[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 3b70e8f5dd 366/427: Add support for NUL characters
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 3b70e8f5dd 366/427: Add support for NUL characters in strings (fixes #42) |
Date: |
Tue, 13 Dec 2022 03:00:11 -0500 (EST) |
branch: elpa/emacsql
commit 3b70e8f5dd6cc127b68d039772e2818eee49a5d2
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Add support for NUL characters in strings (fixes #42)
---
emacsql-compiler.el | 14 +++++++++++++-
tests/emacsql-external-tests.el | 10 ++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/emacsql-compiler.el b/emacsql-compiler.el
index e8f3365759..bfa03f228c 100644
--- a/emacsql-compiler.el
+++ b/emacsql-compiler.el
@@ -49,7 +49,19 @@
(defun emacsql-quote-scalar (string)
"Single-quote (scalar) STRING for use in a SQL expression."
- (format "'%s'" (replace-regexp-in-string "'" "''" string)))
+ (with-temp-buffer
+ (insert string)
+ (setf (point) (point-min))
+ (while (re-search-forward "'" nil t)
+ (replace-match "''"))
+ (setf (point) (point-min))
+ (while (re-search-forward "\0" nil t)
+ (replace-match "\\\\0"))
+ (setf (point) (point-min))
+ (insert "'")
+ (setf (point) (point-max))
+ (insert "'")
+ (buffer-string)))
(defun emacsql-quote-identifier (string)
"Double-quote (identifier) STRING for use in a SQL expression."
diff --git a/tests/emacsql-external-tests.el b/tests/emacsql-external-tests.el
index 99150dc0d7..b00b6c8de9 100644
--- a/tests/emacsql-external-tests.el
+++ b/tests/emacsql-external-tests.el
@@ -39,6 +39,16 @@
(should (equal (emacsql db [:select * :from foo])
'((1) (2) (3))))))))
+(ert-deftest emacsql-nul-character ()
+ "Try inserting and retrieving strings with a NUL byte."
+ (let ((emacsql-global-timeout emacsql-tests-timeout))
+ (dolist (factory emacsql-tests-connection-factories)
+ (emacsql-with-connection (db (funcall (cdr factory)))
+ (emacsql db [:create-temporary-table foo ([x])])
+ (emacsql db [:insert :into foo :values (["a\0bc"])])
+ (should (equal (emacsql db [:select * :from foo])
+ '(("a\0bc"))))))))
+
(ert-deftest emacsql-foreign-key ()
"Tests that foreign keys work properly through EmacSQL."
(let ((emacsql-global-timeout emacsql-tests-timeout))
- [nongnu] elpa/emacsql c93f52159f 347/427: Bump to version 2.0.2., (continued)
- [nongnu] elpa/emacsql c93f52159f 347/427: Bump to version 2.0.2., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e91bac3a20 350/427: Add cl-generic require to emacsql.el (#32)., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b65c5b03d5 351/427: Fix up Cask file., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e3bc9b105f 354/427: Finish removing Cask, including updating the README, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 83a278aa6b 356/427: Remove trailing &key in method definition, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 67ca8124bc 425/427: make: Suppress warning about obsolete autoload package, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e318a6c8f6 426/427: Add new SQLite back-ends, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9f0a19280c 296/427: Enhance emacsql-with-transaction to retry., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 616dde3752 361/427: An identifier named * means select all columns (#19), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5da614bc9b 359/427: Drop finalizer use and explicitely depend on Emacs 25, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3b70e8f5dd 366/427: Add support for NUL characters in strings (fixes #42),
ELPA Syncer <=
- [nongnu] elpa/emacsql 75ac0448a5 364/427: Add support for DISTINCT in aggregate functions (#41), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8c46fb2c1e 286/427: Drop argument count check since it's wrong., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 641338533c 331/427: Just build SQLite on first connection., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 56a2882936 333/427: Update README for Melpa changes., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1b37570bf5 352/427: Fix up the Makefile., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2e9e2d6ba1 390/427: Fix SQL truncated when print-level or print-length are changed, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 50b139443b 414/427: make: Fix compiling and cleaning tests, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4fe4413994 420/427: Re-indent some data so that machine and human can agree, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 62d3915737 363/427: Update to SQLite 3.22.0 and remove download system (#40), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a164ecd9d3 374/427: Implement operator precedence handling, ELPA Syncer, 2022/12/13