branch: elpa/emacsql commit 7a725e1910619c360e358cb24a069f051b1ffebe Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Add new library emacsql-sqlite-common --- Makefile | 9 +++--- emacsql-sqlite-builtin.el | 1 + emacsql-sqlite-common.el | 71 +++++++++++++++++++++++++++++++++++++++++++++++ emacsql-sqlite-module.el | 1 + emacsql-sqlite.el | 1 + emacsql.el | 53 ----------------------------------- 6 files changed, 79 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index b953e45ab3..f3b7c482f6 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,13 @@ PKG = emacsql ELS = $(PKG)-compiler.el ELS += $(PKG).el -ELS += $(PKG)-mysql.el -ELS += $(PKG)-pg.el -ELS += $(PKG)-psql.el -ELS += $(PKG)-sqlite.el +ELS += $(PKG)-sqlite-common.el ELS += $(PKG)-sqlite-builtin.el ELS += $(PKG)-sqlite-module.el +ELS += $(PKG)-sqlite.el +ELS += $(PKG)-mysql.el +ELS += $(PKG)-psql.el +ELS += $(PKG)-pg.el ELCS = $(ELS:.el=.elc) TEST_ELS = tests/emacsql-compiler-tests.el diff --git a/emacsql-sqlite-builtin.el b/emacsql-sqlite-builtin.el index 2c264da913..59447011fc 100644 --- a/emacsql-sqlite-builtin.el +++ b/emacsql-sqlite-builtin.el @@ -17,6 +17,7 @@ ;;; Code: (require 'emacsql) +(require 'emacsql-sqlite-common) (require 'sqlite nil t) (declare-function sqlite-open "sqlite") diff --git a/emacsql-sqlite-common.el b/emacsql-sqlite-common.el new file mode 100644 index 0000000000..cf08344d7d --- /dev/null +++ b/emacsql-sqlite-common.el @@ -0,0 +1,71 @@ +;;; emacsql-sqlite-common.el --- Code used by multiple SQLite back-ends -*- lexical-binding:t -*- + +;; This is free and unencumbered software released into the public domain. + +;; Author: Jonas Bernoulli <jo...@bernoul.li> +;; Homepage: https://github.com/magit/emacsql + +;; SPDX-License-Identifier: Unlicense + +;;; Commentary: + +;; This library contains code that is used by multiple SQLite back-ends. + +;;; Code: + +;;; Constants + +(defconst emacsql-sqlite-reserved + '( ABORT ACTION ADD AFTER ALL ALTER ANALYZE AND AS ASC ATTACH + AUTOINCREMENT BEFORE BEGIN BETWEEN BY CASCADE CASE CAST CHECK + COLLATE COLUMN COMMIT CONFLICT CONSTRAINT CREATE CROSS + CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP DATABASE DEFAULT + DEFERRABLE DEFERRED DELETE DESC DETACH DISTINCT DROP EACH ELSE END + ESCAPE EXCEPT EXCLUSIVE EXISTS EXPLAIN FAIL FOR FOREIGN FROM FULL + GLOB GROUP HAVING IF IGNORE IMMEDIATE IN INDEX INDEXED INITIALLY + INNER INSERT INSTEAD INTERSECT INTO IS ISNULL JOIN KEY LEFT LIKE + LIMIT MATCH NATURAL NO NOT NOTNULL NULL OF OFFSET ON OR ORDER + OUTER PLAN PRAGMA PRIMARY QUERY RAISE RECURSIVE REFERENCES REGEXP + REINDEX RELEASE RENAME REPLACE RESTRICT RIGHT ROLLBACK ROW + SAVEPOINT SELECT SET TABLE TEMP TEMPORARY THEN TO TRANSACTION + TRIGGER UNION UNIQUE UPDATE USING VACUUM VALUES VIEW VIRTUAL WHEN + WHERE WITH WITHOUT) + "List of all of SQLite's reserved words. +Also see http://www.sqlite.org/lang_keywords.html.") + +(defconst emacsql-sqlite-error-codes + '((1 SQLITE_ERROR emacsql-error "SQL logic error") + (2 SQLITE_INTERNAL emacsql-internal nil) + (3 SQLITE_PERM emacsql-access "access permission denied") + (4 SQLITE_ABORT emacsql-error "query aborted") + (5 SQLITE_BUSY emacsql-locked "database is locked") + (6 SQLITE_LOCKED emacsql-locked "database table is locked") + (7 SQLITE_NOMEM emacsql-memory "out of memory") + (8 SQLITE_READONLY emacsql-access "attempt to write a readonly database") + (9 SQLITE_INTERRUPT emacsql-error "interrupted") + (10 SQLITE_IOERR emacsql-access "disk I/O error") + (11 SQLITE_CORRUPT emacsql-corruption "database disk image is malformed") + (12 SQLITE_NOTFOUND emacsql-error "unknown operation") + (13 SQLITE_FULL emacsql-access "database or disk is full") + (14 SQLITE_CANTOPEN emacsql-access "unable to open database file") + (15 SQLITE_PROTOCOL emacsql-access "locking protocol") + (16 SQLITE_EMPTY emacsql-corruption nil) + (17 SQLITE_SCHEMA emacsql-error "database schema has changed") + (18 SQLITE_TOOBIG emacsql-error "string or blob too big") + (19 SQLITE_CONSTRAINT emacsql-constraint "constraint failed") + (20 SQLITE_MISMATCH emacsql-error "datatype mismatch") + (21 SQLITE_MISUSE emacsql-error "bad parameter or other API misuse") + (22 SQLITE_NOLFS emacsql-error "large file support is disabled") + (23 SQLITE_AUTH emacsql-access "authorization denied") + (24 SQLITE_FORMAT emacsql-corruption nil) + (25 SQLITE_RANGE emacsql-error "column index out of range") + (26 SQLITE_NOTADB emacsql-corruption "file is not a database") + (27 SQLITE_NOTICE emacsql-warning "notification message") + (28 SQLITE_WARNING emacsql-warning "warning message")) + "Alist mapping SQLite error codes to EmacSQL conditions. +Elements have the form (ERRCODE SYMBOLIC-NAME EMACSQL-ERROR +ERRSTR). Also see https://www.sqlite.org/rescode.html.") + +(provide 'emacsql-sqlite-common) + +;;; emacsql-sqlite-common.el ends here diff --git a/emacsql-sqlite-module.el b/emacsql-sqlite-module.el index c2f5f0c2ab..000b837897 100644 --- a/emacsql-sqlite-module.el +++ b/emacsql-sqlite-module.el @@ -17,6 +17,7 @@ ;;; Code: (require 'emacsql) +(require 'emacsql-sqlite-common) (require 'sqlite3 nil t) (declare-function sqlite3-open "sqlite3-api") diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el index e2cb39338d..3d0045a1b0 100644 --- a/emacsql-sqlite.el +++ b/emacsql-sqlite.el @@ -20,6 +20,7 @@ ;;; Code: (require 'emacsql) +(require 'emacsql-sqlite-common) (emacsql-register-reserved emacsql-sqlite-reserved) diff --git a/emacsql.el b/emacsql.el index e755b8cc55..7539216743 100644 --- a/emacsql.el +++ b/emacsql.el @@ -398,59 +398,6 @@ A prefix argument causes the SQL to be printed into the current buffer." (emacsql-show-sql sql))) (user-error "Invalid SQL: %S" sexp)))) -;;; Common SQLite values - -(defconst emacsql-sqlite-reserved - '( ABORT ACTION ADD AFTER ALL ALTER ANALYZE AND AS ASC ATTACH - AUTOINCREMENT BEFORE BEGIN BETWEEN BY CASCADE CASE CAST CHECK - COLLATE COLUMN COMMIT CONFLICT CONSTRAINT CREATE CROSS - CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP DATABASE DEFAULT - DEFERRABLE DEFERRED DELETE DESC DETACH DISTINCT DROP EACH ELSE END - ESCAPE EXCEPT EXCLUSIVE EXISTS EXPLAIN FAIL FOR FOREIGN FROM FULL - GLOB GROUP HAVING IF IGNORE IMMEDIATE IN INDEX INDEXED INITIALLY - INNER INSERT INSTEAD INTERSECT INTO IS ISNULL JOIN KEY LEFT LIKE - LIMIT MATCH NATURAL NO NOT NOTNULL NULL OF OFFSET ON OR ORDER - OUTER PLAN PRAGMA PRIMARY QUERY RAISE RECURSIVE REFERENCES REGEXP - REINDEX RELEASE RENAME REPLACE RESTRICT RIGHT ROLLBACK ROW - SAVEPOINT SELECT SET TABLE TEMP TEMPORARY THEN TO TRANSACTION - TRIGGER UNION UNIQUE UPDATE USING VACUUM VALUES VIEW VIRTUAL WHEN - WHERE WITH WITHOUT) - "List of all of SQLite's reserved words. -Also see http://www.sqlite.org/lang_keywords.html.") - -(defconst emacsql-sqlite-error-codes - '((1 SQLITE_ERROR emacsql-error "SQL logic error") - (2 SQLITE_INTERNAL emacsql-internal nil) - (3 SQLITE_PERM emacsql-access "access permission denied") - (4 SQLITE_ABORT emacsql-error "query aborted") - (5 SQLITE_BUSY emacsql-locked "database is locked") - (6 SQLITE_LOCKED emacsql-locked "database table is locked") - (7 SQLITE_NOMEM emacsql-memory "out of memory") - (8 SQLITE_READONLY emacsql-access "attempt to write a readonly database") - (9 SQLITE_INTERRUPT emacsql-error "interrupted") - (10 SQLITE_IOERR emacsql-access "disk I/O error") - (11 SQLITE_CORRUPT emacsql-corruption "database disk image is malformed") - (12 SQLITE_NOTFOUND emacsql-error "unknown operation") - (13 SQLITE_FULL emacsql-access "database or disk is full") - (14 SQLITE_CANTOPEN emacsql-access "unable to open database file") - (15 SQLITE_PROTOCOL emacsql-access "locking protocol") - (16 SQLITE_EMPTY emacsql-corruption nil) - (17 SQLITE_SCHEMA emacsql-error "database schema has changed") - (18 SQLITE_TOOBIG emacsql-error "string or blob too big") - (19 SQLITE_CONSTRAINT emacsql-constraint "constraint failed") - (20 SQLITE_MISMATCH emacsql-error "datatype mismatch") - (21 SQLITE_MISUSE emacsql-error "bad parameter or other API misuse") - (22 SQLITE_NOLFS emacsql-error "large file support is disabled") - (23 SQLITE_AUTH emacsql-access "authorization denied") - (24 SQLITE_FORMAT emacsql-corruption nil) - (25 SQLITE_RANGE emacsql-error "column index out of range") - (26 SQLITE_NOTADB emacsql-corruption "file is not a database") - (27 SQLITE_NOTICE emacsql-warning "notification message") - (28 SQLITE_WARNING emacsql-warning "warning message")) - "Alist mapping SQLite error codes to EmacSQL conditions. -Elements have the form (ERRCODE SYMBOLIC-NAME EMACSQL-ERROR -ERRSTR). Also see https://www.sqlite.org/rescode.html.") - ;;; Fix Emacs' broken vector indentation (defun emacsql--inside-vector-p ()