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

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

[nongnu] elpa/emacsql f030b9952d 224/427: Fix up psql-connection.


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql f030b9952d 224/427: Fix up psql-connection.
Date: Tue, 13 Dec 2022 02:59:46 -0500 (EST)

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

    Fix up psql-connection.
---
 emacsql-psql.el | 33 +++++++++++++++++++++++++++++++++
 emacsql.el      |  2 +-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/emacsql-psql.el b/emacsql-psql.el
index aefaa98f3b..d873ff128b 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -78,6 +78,39 @@
     (when (process-live-p process)
       (process-send-string process "\\q\n"))))
 
+(defmethod emacsql-send-message ((connection emacsql-psql-connection) message)
+  (let ((process (emacsql-process connection)))
+    (process-send-string process message)
+    (process-send-string process "\n")))
+
+(defmethod emacsql-waiting-p ((connection emacsql-psql-connection))
+  (with-current-buffer (emacsql-buffer connection)
+    (cond ((= (buffer-size) 1) (string= "]" (buffer-string)))
+          ((> (buffer-size) 1) (string= "\n]"
+                                        (buffer-substring
+                                         (- (point-max) 2) (point-max)))))))
+
+(defmethod emacsql-check-error ((connection emacsql-psql-connection))
+  (with-current-buffer (emacsql-buffer connection)
+    (let ((case-fold-search t))
+      (setf (point) (point-min))
+      (when (looking-at "error:")
+        (let* ((beg (line-beginning-position))
+               (end (line-end-position)))
+          (signal 'emacsql-error (list (buffer-substring beg end))))))))
+
+(defmethod emacsql-parse ((connection emacsql-psql-connection))
+  (emacsql-check-error connection)
+  (with-current-buffer (emacsql-buffer connection)
+    (let ((standard-input (current-buffer)))
+      (setf (point) (point-min))
+      (cl-loop until (looking-at "]")
+               collect (read) into row
+               when (looking-at "\n")
+               collect row into rows
+               and do (progn (forward-char 1) (setf row ()))
+               finally (cl-return rows)))))
+
 (provide 'emacsql-psql)
 
 ;;; emacsql-psql.el ends here
diff --git a/emacsql.el b/emacsql.el
index c1148e5d6a..39212614ff 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -171,7 +171,7 @@ must display as \"nil\".")
   "Signal a specific condition for CODE from CONNECTION.
 Subclasses should override this method in order to provide more
 specific error conditions."
-  (signal 'emacsql-syntax (list code message)))
+  (signal 'emacsql-error (list code message)))
 
 (defmethod emacsql-parse ((connection emacsql-protocol-mixin))
   "Parse well-formed output into an s-expression."



reply via email to

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