Skip to content

Commit

Permalink
correct feature options & eval enviro
Browse files Browse the repository at this point in the history
  • Loading branch information
flintforge committed Nov 15, 2024
1 parent fccff88 commit 2d2d54d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 46 deletions.
3 changes: 1 addition & 2 deletions ob-sql-session-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ sqlite|3.4
(pg-test "DROP TABLE if exists publications;
CREATE TABLE publications (id int2, database text);
INSERT INTO publications VALUES (10, 'HGNC'), (13, 'FlyBase');
SELECT database FROM publications where id=10 or id=13;"
"DROP TABLE
SELECT database FROM publications where id=10 or id=13;" "DROP TABLE
CREATE TABLE
INSERT 0 2
database\nHGNC\nFlyBase\n"))
Expand Down
83 changes: 39 additions & 44 deletions ob-sql.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@
(sql-set-product-feature 'postgres :batch-terminate
(format "\\echo %s\n" ob-sql-session--batch-end-indicator))
(sql-set-product-feature 'postgres :terminal-command "\\\\")

(setq sql-postgres-options
(list "--set=ON_ERROR_STOP=1"
(format "--set=PROMPT1=%s" (sql-get-product-feature 'postgres :prompt-regexp ))
(format "--set=PROMPT2=%s" (sql-get-product-feature 'postgres :prompt-cont-regexp ))
"-P" "pager=off"
"-P" "footer=off"
"-A" ))
(sql-set-product-feature 'postgres :environment '(("PGPASSWORD" sql-password)))
(sql-set-product-feature
'postgres :sqli-options
(list "--set=ON_ERROR_STOP=1"
(format "--set=PROMPT1=%s" (sql-get-product-feature 'postgres :prompt-regexp ))
(format "--set=PROMPT2=%s" (sql-get-product-feature 'postgres :prompt-cont-regexp ))
"-P" "pager=off"
"-P" "footer=off"
"-A" ))

(declare-function org-table-import "org-table" (file arg))
(declare-function orgtbl-to-csv "org-table" (table params))
Expand Down Expand Up @@ -571,28 +572,25 @@ no longer needed while the session stays open."
(sql-password (cdr (assoc :dbpassword params)))
(buffer-name (format "%s" (if (string= session "none") ""
(format "[%s]" session))))
;; (buffer-name (format "%s%s://%s%s/%s"
;; (if (string= session "none") ""
;; (format "[%s] " session))
;; engine
;; (if sql-user (concat sql-user "@") "")
;; (if sql-server (concat sql-server ":") "")
;; sql-database))
;; (buffer-name
;; (format "%s%s://%s%s/%s"
;; (if (string= session "none") "" (format "[%s] " session))
;; engine
;; (if sql-user (concat sql-user "@") "")
;; (if sql-server (concat sql-server ":") "")
;; sql-database))
(ob-sql-buffer (format "*SQL: %s*" buffer-name)))

;; I get a nil on sql-for-each-login on the first call
;; to sql-interactive at
;; (if (sql-buffer-live-p ob-sql-buffer)
;; so put sql-buffer-live-p aside
(if (ob-sql-session-buffer-live-p ob-sql-buffer)
(progn
;; set again the filter
(progn ; set again the filter
(set-process-filter (get-buffer-process ob-sql-buffer)
#'ob-sql-session-comint-output-filter)
;; and return the buffer
ob-sql-buffer)

;; otherwise initiate a connection
ob-sql-buffer) ; and return the buffer
;; otherwise initiate a new connection
(save-window-excursion
(setq ob-sql-buffer ; start the client
(ob-sql-connect in-engine buffer-name)))
Expand Down Expand Up @@ -657,25 +655,25 @@ should also be prompted."
;; depending on client, password is forcefully prompted

;; Connect to database.
(let ((sql-user (default-value 'sql-user))
(sql-password (default-value 'sql-password))
(sql-server (default-value 'sql-server))
(sql-database (default-value 'sql-database))
(sql-port (default-value 'sql-port))
(default-directory (or sql-default-directory default-directory)))

;; The password wallet returns a function
;; which supplies the password. (untested)
(when (functionp sql-password)
(setq sql-password (funcall sql-password)))

;; Erase previous sql-buffer as we'll be looking for it's prompt
;; to indicate session readyness
(let ((previous-session
(get-buffer (format "*SQL: %s*" sql-cnx))))
(when previous-session
(with-current-buffer
previous-session (erase-buffer))))
;; (let ((sql-user (default-value 'sql-user))
;; (sql-password (default-value 'sql-password))
;; (sql-server (default-value 'sql-server))
;; (sql-database (default-value 'sql-database))
;; (sql-port (default-value 'sql-port))
;; (default-directory (or sql-default-directory default-directory)))

;; The password wallet returns a function
;; which supplies the password. (untested)
(when (functionp sql-password)
(setq sql-password (funcall sql-password)))

;; Erase previous sql-buffer as we'll be looking for it's prompt
;; to indicate session readyness
(let ((previous-session
(get-buffer (format "*SQL: %s*" sql-cnx))))
(when previous-session
(with-current-buffer
previous-session (erase-buffer)))

(setq sqli-buffer
(let ((process-environment (copy-sequence process-environment))
Expand All @@ -687,7 +685,6 @@ should also be prompted."
engine
(sql-get-product-feature engine :sqli-options)
(format "SQL: %s" sql-cnx))))

(setq sql-buffer (buffer-name sqli-buffer))

(setq rpt (sql-make-progress-reporter nil "Login"))
Expand All @@ -702,7 +699,6 @@ should also be prompted."
(progn (goto-char (point-max))
(not (re-search-backward
prompt-regexp 0 t))))
(message ">> %s" secs)
(sql-progress-reporter-update rpt)))

;; no prompt, connexion failed (and process is terminated)
Expand All @@ -721,8 +717,7 @@ Carefully separate client commands from SQL commands
Concatenate SQL commands as one line is one way to stop on error.
Otherwise the entire batch will be emitted no matter what.
Finnally add the termination command."
(message str)
;;(setq sql-product engine)

(concat
(let ((commands (split-string str "\n"))
(terminal-command
Expand Down

0 comments on commit 2d2d54d

Please sign in to comment.