Changes
[emacs.git] / .emacs.d / elisp / org / ob-sql.el
index 08d4419..493b3dc 100644 (file)
   (org-babel-sql-expand-vars
    body (mapcar #'cdr (org-babel-get-header params :var))))
 
-(defun dbstring-mysql (host user password database)
+(defun org-babel-sql-dbstring-mysql (host user password database)
   "Make MySQL cmd line args for database connection.  Pass nil to omit that arg."
   (combine-and-quote-strings
-   (remq nil
+   (delq nil
         (list (when host     (concat "-h" host))
               (when user     (concat "-u" user))
               (when password (concat "-p" password))
               (when database (concat "-D" database))))))
 
+(defun org-babel-sql-dbstring-postgresql (host user database)
+  "Make PostgreSQL command line args for database connection.
+Pass nil to omit that arg."
+  (combine-and-quote-strings
+   (delq nil
+        (list (when host (concat "-h" host))
+              (when user (concat "-U" user))
+              (when database (concat "-d" database))))))
+
 (defun org-babel-execute:sql (body params)
   "Execute a block of Sql code with Babel.
 This function is called by `org-babel-execute-src-block'."
@@ -117,13 +126,15 @@ This function is called by `org-babel-execute-src-block'."
                                      (org-babel-process-file-name in-file)
                                      (org-babel-process-file-name out-file)))
                     ('mysql (format "mysql %s %s %s < %s > %s"
-                                   (dbstring-mysql dbhost dbuser dbpassword database)
+                                   (org-babel-sql-dbstring-mysql dbhost dbuser dbpassword database)
                                    (if colnames-p "" "-N")
                                     (or cmdline "")
                                    (org-babel-process-file-name in-file)
                                    (org-babel-process-file-name out-file)))
                    ('postgresql (format
-                                 "psql -A -P footer=off -F \"\t\"  -f %s -o %s %s"
+                                 "psql --set=\"ON_ERROR_STOP=1\" %s -A -P footer=off -F \"\t\"  %s -f %s -o %s %s"
+                                 (if colnames-p "" "-t")
+                                 (org-babel-sql-dbstring-postgresql dbhost dbuser database)
                                  (org-babel-process-file-name in-file)
                                  (org-babel-process-file-name out-file)
                                  (or cmdline "")))