branch: externals/triples commit 45dc57703ae870aa864a195041b76d622535c351 Author: Andrew Hyatt <ahy...@gmail.com> Commit: Andrew Hyatt <ahy...@gmail.com>
Fix emacsql/buit-in sqlite incompatibility Emacsql correctly was storing integers as integers, whereas the builtin sqlite was both reading and writing integers as strings. This corrects the built-in sqlite to use integers instead of strings. Fixes the cause of https://github.com/ahyatt/triples/issues/2, although we will need a further upgrading mechanism for data written in the built-in sqlite. --- CHANGELOG.org | 10 ---------- NEWS.org | 2 ++ triples-backups.el | 2 +- triples-test.el | 41 +++++++++++++++++++++++++++++++++++++++-- triples.el | 12 +++++++----- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org deleted file mode 100644 index f6e451d1d1..0000000000 --- a/CHANGELOG.org +++ /dev/null @@ -1,10 +0,0 @@ -TITLE: Changelog for the triples module for GNU Emacs. - -* 0.2 -- Create a default database to encourage a shared triple database. Add information on why this is an interesting idea in the README. -- Add support for backups of databases via =triples-backup=, and a simple way to have a sane and shared backups created with the new =triples-backups= module. -- Add =triples-move-subject= which will move both a subject as well as reference to it. -* 0.1.1 - - Bugfix release to fix =triples-subject-with-predicate-object=. -* 0.1 -- This is the initial version that contained basic triple functionality, and was integrated into GNU ELPA. diff --git a/NEWS.org b/NEWS.org index a08c9a4f92..b64b006f27 100644 --- a/NEWS.org +++ b/NEWS.org @@ -1,5 +1,7 @@ TITLE: Changelog for the triples module for GNU Emacs. +* 0.3 +- All integers are stored as integers, and not strings * 0.2.7 - Add new function =triples-db-select-pred-op=, which allows querying among predicates for objects with a certain relationship to values, replaces =triples-db-select-predicate-object-fragment=. - Add ability to store cons types (basically lists) as values. diff --git a/triples-backups.el b/triples-backups.el index df5ee8d48e..2e8036b4ab 100644 --- a/triples-backups.el +++ b/triples-backups.el @@ -90,4 +90,4 @@ LAST-UPDATE is the time of the last update." 7)) (provide 'triples-backups) -;;; Code: +;;; triples-backups.el ends here diff --git a/triples-test.el b/triples-test.el index b96c1b3385..aaade3a559 100644 --- a/triples-test.el +++ b/triples-test.el @@ -190,6 +190,43 @@ easily debug into it.") ;; this will fail. (should (= 0 (length (triples-db-select-pred-op db :person/age '> 1000)))))) +(ert-deftest triples-test-builtin-emacsql-compat () + (let ((triples-sqlite-interface 'builtin)) + (triples-test-with-temp-db + (triples-add-schema db 'person + '(name :base/unique t :base/type string) + '(age :base/unique t :base/type integer)) + (triples-set-type db 123 'person :name "Alice Aardvark" :age 41) + (should (equal (triples-get-type db 123 'person) + '(:age 41 :name "Alice Aardvark"))) + (triples-close db) + (let* ((triples-sqlite-interface 'emacsql) + (db (triples-connect db-file))) + (should (equal (triples-get-type db 123 'person) + '(:age 41 :name "Alice Aardvark"))) + (triples-close db)) + ;; Just so the last close will work. + (setq db (triples-connect db-file))))) + +(ert-deftest triples-test-emacsql-builtin-compat () + (let ((triples-sqlite-interface 'emacsql)) + (triples-test-with-temp-db + (triples-add-schema db 'person + '(name :base/unique t :base/type string) + '(age :base/unique t :base/type integer)) + (triples-set-type db 123 'person :name "Alice Aardvark" :age 41) + (should (equal (triples-get-type db 123 'person) + '(:age 41 :name "Alice Aardvark"))) + (triples-close db) + (let* ((triples-sqlite-interface 'builtin) + (db (triples-connect db-file))) + (should (equal (triples-get-type db 123 'person) + '(:age 41 :name "Alice Aardvark"))) + (triples-close db)) + ;; Just so the last close will work. + (setq db (triples-connect db-file))))) + + ;; After this we don't bother testing both with emacsql and the builtin sqlite, ;; since if the functions tested above work, it should also work for both. @@ -426,10 +463,10 @@ easily debug into it.") (should (= 1 (length (triples-subjects-with-predicate-object db 'named/name "Foo")))))) (ert-deftest triples-readme () - (triples-test-with-temp-db - (triples-add-schema db 'person + ((triples-add-schema db 'person '(name :base/unique t :base/type string) '(age :base/unique t :base/type integer)) + triples-test-with-temp-db (triples-add-schema db 'employee '(id :base/unique t :base/type integer) '(manager :base/unique t) diff --git a/triples.el b/triples.el index fd34fa5c0c..a9a42f7f90 100644 --- a/triples.el +++ b/triples.el @@ -6,7 +6,7 @@ ;; Homepage: https://github.com/ahyatt/triples ;; Package-Requires: ((seq "2.0") (emacs "28.1")) ;; Keywords: triples, kg, data, sqlite -;; Version: 0.2.7 +;; Version: 0.3 ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of the @@ -137,15 +137,17 @@ exist at any time. Older backups are the ones that are deleted." "If VAL is a string, return it as enclosed in quotes This is done to have compatibility with the way emacsql stores values. Turn a symbol into a string as well, but not a quoted -one, because sqlite cannot handle symbols." +one, because sqlite cannot handle symbols. Integers do not need +to be stringified." ;; Do not print control characters escaped - we want to get things out exactly ;; as we put them in. (let ((print-escape-control-characters nil)) - (if val - (format "%S" val) + (pcase val ;; Just to save a bit of space, let's use "()" instead of "null", which is ;; what it would be turned into by the pcase above. - "()"))) + ((pred null) "()") + ((pred integerp) val) + (_ (format "%S" val))))) (defun triples-standardize-result (result) "Return RESULT in standardized form.