[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 5ebd12b6ff 377/427: Add some support for the ESCAP
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 5ebd12b6ff 377/427: Add some support for the ESCAPE operator |
Date: |
Tue, 13 Dec 2022 03:00:13 -0500 (EST) |
branch: elpa/emacsql
commit 5ebd12b6ffaa9fbadefe8518eab07a028bbaf7c1
Author: Ákos Kiss <ak@coram.pub>
Commit: Ákos Kiss <ak@coram.pub>
Add some support for the ESCAPE operator
---
emacsql-compiler.el | 18 ++++++++++++++++++
tests/emacsql-compiler-tests.el | 4 +++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/emacsql-compiler.el b/emacsql-compiler.el
index 305aaaeaf5..5345643b4a 100644
--- a/emacsql-compiler.el
+++ b/emacsql-compiler.el
@@ -60,6 +60,12 @@
(insert "'")
(buffer-string)))
+(defun emacsql-quote-character (c)
+ "Single-quote character C for use in a SQL expression."
+ (if (char-equal c ?')
+ "''''"
+ (format "'%c'" c)))
+
(defun emacsql-quote-identifier (string)
"Double-quote (identifier) STRING for use in a SQL expression."
(format "\"%s\"" (replace-regexp-in-string "\"" "\"\"" string)))
@@ -399,6 +405,18 @@ string returned is wrapped with parentheses."
(recur (if (eq op '>=) 2 0))
(recur (if (eq op '>=) 0 2))))
(otherwise (nops op))))
+ ;; enforce second argument to be a character
+ ((escape)
+ (let ((second-arg (cadr args)))
+ (cond
+ ((not (= 2 (length args))) (nops op))
+ ((not (characterp second-arg))
+ (emacsql-error
+ "Second operand of escape has to be a character, got %s"
+ second-arg))
+ (t (format format-string
+ (recur 0)
+ (emacsql-quote-character second-arg))))))
;; Ordering
((asc desc)
(format "%s %s" (recur 0) (upcase (symbol-name op))))
diff --git a/tests/emacsql-compiler-tests.el b/tests/emacsql-compiler-tests.el
index aad9b53fcd..70228f358c 100644
--- a/tests/emacsql-compiler-tests.el
+++ b/tests/emacsql-compiler-tests.el
@@ -181,7 +181,9 @@
([:where (= name 'foo)] '()
"WHERE name = 'foo';")
([:where (= name '$s1)] '(qux)
- "WHERE name = 'qux';")))
+ "WHERE name = 'qux';")
+ ([:where (like url (escape "%`%%" ?`))] '()
+ "WHERE url LIKE '\"%`%%\"' ESCAPE '`';")))
(ert-deftest emacsql-expr ()
(emacsql-tests-with-queries
- [nongnu] elpa/emacsql 3e16afce8b 281/427: Escape backslashes as well., (continued)
- [nongnu] elpa/emacsql 3e16afce8b 281/427: Escape backslashes as well., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3c57f9a986 308/427: Adjust MySQL isolation level., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c68f11b74e 313/427: Register emacsql-pg for unit testing., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ef4bcec524 321/427: Conform to elisp header conventions, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c1ea25c872 322/427: Drop Windows issue from README (fixed in 24.4)., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2bc599d856 327/427: Add separate package headers for each backend., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e498dd1dea 336/427: Drop emacsql-escape-format's KIND argument., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3042597a72 343/427: Add note about lack of Windows support., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5ad4d2da9a 355/427: fix ldlibs for berkeley-unix systems, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a96b2587c4 365/427: Update README to mention FTS5 (#40), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5ebd12b6ff 377/427: Add some support for the ESCAPE operator,
ELPA Syncer <=
- [nongnu] elpa/emacsql c82a0e6b4d 384/427: Add public domain statement to remaining files, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 97ccd7d9e6 398/427: Update library commentaries of package libraries, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6728a8649a 396/427: No longer try to clear a buffer that isn't live anymore, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a118b6c95a 381/427: Don't use -lm flag on Windows (#55), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e7b932a5c9 378/427: Handle read-only emacsql install diretory, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9e48d12e42 402/427: Fix typos in README.md, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6d8cd93662 382/427: README: Remove a duplicate word, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b6a0336d62 405/427: make: Compile SQLite binary before Elisp, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b9d848fa9c 407/427: make: Don't warn about implicit fallthroughs, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql dbf0598731 087/427: Add "-interactive" argument (fixes #1)., ELPA Syncer, 2022/12/13