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

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

[nongnu] elpa/emacsql 8f59fe6e80 073/427: Add a vector escape.


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 8f59fe6e80 073/427: Add a vector escape.
Date: Tue, 13 Dec 2022 02:59:29 -0500 (EST)

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

    Add a vector escape.
---
 emacsql.el | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/emacsql.el b/emacsql.el
index 49d87b0715..8aa0a67968 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -273,18 +273,11 @@ buffer. This is for debugging purposes."
           ((numberp value) (prin1-to-string value))
           ((emacsql-escape (prin1-to-string value) t)))))
 
-(defun emacsql-insert (conn table &rest rows)
-  "Insert ROWS into TABLE.
-Each row must be a sequence of values to store into TABLE.
-
-  (emacsql-insert db :table '(\"Chris\" 0) [\"Jeff\" 1])"
-  (emacsql-with-errors conn
-    (emacsql--send
-     conn
-     (format "INSERT INTO %s VALUES (%s);" (emacsql-escape table)
-             (mapconcat (lambda (row)
-                          (mapconcat #'emacsql-escape-value row ", "))
-                        rows "), (")))))
+(defun emacsql-escape-vector (vector)
+  "Encode VECTOR into a SQL vector scalar."
+  (cl-etypecase vector
+    (list   (mapconcat #'emacsql-escape-vector vector ", "))
+    (vector (concat "(" (mapconcat #'emacsql-escape-value vector ", ") ")"))))
 
 ;; SQL Expansion:
 
@@ -339,6 +332,7 @@ See also `emacsql-with-errors'."
                       (cl-ecase kind
                         (:identifier (emacsql-escape thing))
                         (:value (emacsql-escape-value thing))
+                        (:vector (emacsql-escape-vector thing))
                         (:auto (if (symbolp thing)
                                    (emacsql-escape thing)
                                  (emacsql-escape-value thing)))))))))
@@ -367,6 +361,7 @@ KIND should be :value or :identifier."
    "%" "%%" (cl-case kind
               (:value (emacsql-escape-value thing))
               (:identifier (emacsql-escape thing))
+              (:vector (emacsql-escape-vector thing))
               (otherwise thing))))
 
 (defvar emacsql--vars ()
@@ -384,7 +379,7 @@ KIND should be :value or :identifier."
   (if (emacsql-var thing)
       (prog1 "%s" (push (cons (emacsql-var thing) kind) emacsql--vars))
     (cl-ecase kind
-      ((:identifier :value) (emacsql-escape-format thing kind))
+      ((:identifier :value :vector) (emacsql-escape-format thing kind))
       (:auto (emacsql-escape-format
               thing (if (symbolp thing) :identifier :value))))))
 



reply via email to

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