[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/sqlite e94157e 1/2: Get the insertion logic right
From: |
Lars Ingebrigtsen |
Subject: |
scratch/sqlite e94157e 1/2: Get the insertion logic right |
Date: |
Tue, 7 Dec 2021 01:51:39 -0500 (EST) |
branch: scratch/sqlite
commit e94157ebebdb014893d740d8f0fafb29d8e9d33c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Get the insertion logic right
---
lisp/emacs-lisp/sticky.el | 19 ++++++++++---------
lisp/sqlite.el | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/lisp/emacs-lisp/sticky.el b/lisp/emacs-lisp/sticky.el
index 4c94836..72142ce 100644
--- a/lisp/emacs-lisp/sticky.el
+++ b/lisp/emacs-lisp/sticky.el
@@ -104,9 +104,9 @@ DOC should be a doc string, and ARGS are keywords as
applicable to
"select value, sequence from sticky where package = ? and key
= ?"
id))))
(if stored
- (let ((value (read-from-string (caar stored))))
+ (let ((value (car (read-from-string (car stored)))))
(setf (sticky--cached-value object) value
- (sticky--cached-sequence object) (cadar stored))
+ (sticky--cached-sequence object) (cadr stored))
value)
;; Nothing; return the initial value.
(sticky--initial-value object))))
@@ -136,13 +136,15 @@ DOC should be a doc string, and ARGS are keywords as
applicable to
;; We have no backend, so just store the value.
(setf (sticky--cached-value object) value)
;; We have a backend.
+ (sticky--ensure-db)
(with-sqlite-transaction sticky--db
(let* ((id (list (symbol-name (sticky--package object))
(symbol-name (sticky--key object))))
(old-sequence
- (sqlite-select
- sticky--db
- "select sequence from sticky where package = ? and key = ?"
id)))
+ (caar
+ (sqlite-select
+ sticky--db
+ "select sequence from sticky where package = ? and key = ?"
id))))
(if old-sequence
(progn
(setf (sticky--cached-sequence object) (1+ old-sequence))
@@ -155,10 +157,9 @@ DOC should be a doc string, and ARGS are keywords as
applicable to
(cl-incf (sticky--cached-sequence object))
(sqlite-execute
sticky--db
- "insert into sticky (package, key, value, sequence) values (?, ?,
?, ?)"
- (cons (prin1-to-string value)
- (cons (sticky--cached-sequence object)
- id))))
+ "insert into sticky (package, key, sequence, value) values (?, ?,
?, ?)"
+ (nconc id (list (sticky--cached-sequence object)
+ (prin1-to-string value)))))
(setf (sticky--cached-value object) value)))))
(gv-define-simple-setter sticky-value sticky--set-value)
diff --git a/lisp/sqlite.el b/lisp/sqlite.el
index c95c8ef..a47689c 100644
--- a/lisp/sqlite.el
+++ b/lisp/sqlite.el
@@ -25,7 +25,7 @@
(defmacro with-sqlite-transaction (db &rest body)
"Execute BODY while holding a transaction for DB."
- (declare (indent 1))
+ (declare (indent 1) (debug (form body)))
(let ((db-var (gensym)))
`(let ((,db-var ,db))
(if (sqlite-available-p)