emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql c5e1ccef73 257/427: Flesh out the rest of mysql-co


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql c5e1ccef73 257/427: Flesh out the rest of mysql-connection's constructor.
Date: Tue, 13 Dec 2022 02:59:49 -0500 (EST)

branch: elpa/emacsql
commit c5e1ccef7369025b25c5d85932ac898726bc9947
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Flesh out the rest of mysql-connection's constructor.
---
 emacsql-mysql.el  | 36 ++++++++++++++++++++----------------
 emacsql-psql.el   |  4 +---
 emacsql-sqlite.el |  4 +---
 emacsql.el        |  7 +++++++
 4 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/emacsql-mysql.el b/emacsql-mysql.el
index 17f11be99c..4930497b07 100644
--- a/emacsql-mysql.el
+++ b/emacsql-mysql.el
@@ -21,23 +21,27 @@
                       (object "LONGTEXT")
                       (nil "LONGTEXT")))))
 
-(defun emacsql-mysql (dbname)
+(cl-defun emacsql-mysql (database &key user password host port debug)
   "Connect to a MySQL server using the mysql command line program."
-  (let* ((process-connection-type t)
-         (buffer (generate-new-buffer " *emacsql-mysql*"))
-         (mysql emacsql-mysql-executable)
-         (command (mapconcat #'shell-quote-argument
-                             (list mysql "-rfBNL" "--skip-pager" dbname)
-                             " "))
-         (process (start-process-shell-command
-                   "emacsql-mysql" buffer (concat "stty raw &&" command)))
-         (connection (make-instance 'emacsql-mysql-connection
-                                    :process process
-                                    :dbname dbname)))
-    (setf (process-sentinel process)
-          (lambda (proc _) (kill-buffer (process-buffer proc))))
-    (emacsql connection [:set-session (= sql-mode 'NO_BACKSLASH_ESCAPES)])
-    (emacsql-register connection)))
+  (let* ((mysql (executable-find emacsql-mysql-executable))
+         (command (list database "--skip-pager" "-rfBNL" mysql)))
+    (when user     (push (format "--user=%s" user) command))
+    (when password (push (format "--password=%s" password) command))
+    (when host     (push (format "--host=%s" host) command))
+    (when port     (push (format "--port=%s" port) command))
+    (let* ((process-connection-type t)
+           (buffer (generate-new-buffer " *emacsql-mysql*"))
+           (command (mapconcat #'shell-quote-argument (nreverse command) " "))
+           (process (start-process-shell-command
+                     "emacsql-mysql" buffer (concat "stty raw &&" command)))
+           (connection (make-instance 'emacsql-mysql-connection
+                                      :process process
+                                      :dbname database)))
+      (setf (process-sentinel process)
+            (lambda (proc _) (kill-buffer (process-buffer proc))))
+      (when debug (emacsql-enable-debugging connection))
+      (emacsql connection [:set-session (= sql-mode 'NO_BACKSLASH_ESCAPES)])
+      (emacsql-register connection))))
 
 (defmethod emacsql-close ((connection emacsql-mysql-connection))
   (let ((process (emacsql-process connection)))
diff --git a/emacsql-psql.el b/emacsql-psql.el
index a6cd725b86..d96a78ad1a 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -59,9 +59,7 @@
                                       :dbname dbname)))
       (setf (process-sentinel process)
             (lambda (proc _) (kill-buffer (process-buffer proc))))
-      (when debug
-        (setf (emacsql-log-buffer connection)
-              (generate-new-buffer " *emacsql-log*")))
+      (when debug (emacsql-enable-debugging connection))
       (mapc (apply-partially #'emacsql-send-message connection)
             '("\\pset pager off"
               "\\pset null nil"
diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 55ec04e5cf..a8afc23cdd 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -43,9 +43,7 @@ buffer. This is for debugging purposes."
     (emacsql-wait connection)
     (emacsql connection [:pragma (= busy-timeout $s1)]
              (/ (* emacsql-global-timeout 1000) 2))
-    (when debug
-      (setf (emacsql-log-buffer connection)
-            (generate-new-buffer " *emacsql-log*")))
+    (when debug (emacsql-enable-debugging connection))
     (emacsql-register connection)))
 
 (defmethod emacsql-close ((connection emacsql-sqlite-connection))
diff --git a/emacsql.el b/emacsql.el
index fe13cd908f..f79150aaa3 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -73,6 +73,7 @@ If nil, wait forever.")
             :accessor emacsql-process)
    (log-buffer :type (or null buffer)
                :initarg :log-buffer
+               :initform nil
                :accessor emacsql-log-buffer
                :documentation "Output log (debug).")
    (types :allocation :class
@@ -103,6 +104,12 @@ SQL expression.")
   "Get proccess buffer for CONNECTION."
   (process-buffer (emacsql-process connection)))
 
+(defmethod emacsql-enable-debugging ((connection emacsql-connection))
+  "Enable debugging on this"
+  (unless (buffer-live-p (emacsql-log-buffer connection))
+    (setf (emacsql-log-buffer connection)
+          (generate-new-buffer " *emacsql-log*"))))
+
 (defmethod emacsql-log ((connection emacsql-connection) message)
   "Log MESSAGE into CONNECTION's log.
 MESSAGE should not have a newline on the end."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]