From f35dc7058b22a6c7bca23c6696b815f137427fb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Fri, 25 Nov 2022 10:42:38 +0100 Subject: [PATCH] Add sqlite library version string retrieval function (bug#58766) * src/sqlite.c (sqlite3_libversion, load_dll_functions): Make sqlite3_libversion available. (Fsqlite_version): New. (syms_of_sqlite): Define sqlite-version. * doc/lispref/text.texi (Database): Document. * test/src/sqlite-tests.el (sqlite-returning): `RETURNING` was added in sqlite 3.35; skip the test for older versions. --- doc/lispref/text.texi | 4 ++++ src/sqlite.c | 14 ++++++++++++++ test/src/sqlite-tests.el | 1 + 3 files changed, 19 insertions(+) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 793c22949c8..ef938e88ecf 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -5460,6 +5460,10 @@ Extensions are usually shared-library files; on GNU and Unix systems, they have the @file{.so} file-name extension. @end defun +@defun sqlite-version +Return a string denoting the version of the SQLite library in use. +@end defun + @findex sqlite-mode-open-file If you wish to list the contents of an SQLite file, you can use the @code{sqlite-mode-open-file} command. This will pop to a buffer using diff --git a/src/sqlite.c b/src/sqlite.c index ac860f55bcd..c2f90d6a871 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -55,6 +55,7 @@ DEF_DLL_FN (SQLITE_API const char*, sqlite3_errmsg, (sqlite3*)); #if SQLITE_VERSION_NUMBER >= 3007015 DEF_DLL_FN (SQLITE_API const char*, sqlite3_errstr, (int)); #endif +DEF_DLL_FN (SQLITE_API const char*, sqlite3_libversion, (void)); DEF_DLL_FN (SQLITE_API int, sqlite3_step, (sqlite3_stmt*)); DEF_DLL_FN (SQLITE_API int, sqlite3_changes, (sqlite3*)); DEF_DLL_FN (SQLITE_API int, sqlite3_column_count, (sqlite3_stmt*)); @@ -96,6 +97,7 @@ DEF_DLL_FN (SQLITE_API int, sqlite3_load_extension, # if SQLITE_VERSION_NUMBER >= 3007015 # undef sqlite3_errstr # endif +# undef sqlite3_libversion # undef sqlite3_step # undef sqlite3_changes # undef sqlite3_column_count @@ -124,6 +126,7 @@ DEF_DLL_FN (SQLITE_API int, sqlite3_load_extension, # if SQLITE_VERSION_NUMBER >= 3007015 # define sqlite3_errstr fn_sqlite3_errstr # endif +# define sqlite3_libversion fn_sqlite3_libversion # define sqlite3_step fn_sqlite3_step # define sqlite3_changes fn_sqlite3_changes # define sqlite3_column_count fn_sqlite3_column_count @@ -155,6 +158,7 @@ load_dll_functions (HMODULE library) #if SQLITE_VERSION_NUMBER >= 3007015 LOAD_DLL_FN (library, sqlite3_errstr); #endif + LOAD_DLL_FN (library, sqlite3_libversion); LOAD_DLL_FN (library, sqlite3_step); LOAD_DLL_FN (library, sqlite3_changes); LOAD_DLL_FN (library, sqlite3_column_count); @@ -763,6 +767,15 @@ This will free the resources held by SET. */) return Qt; } +DEFUN ("sqlite-version", Fsqlite_version, Ssqlite_version, 0, 0, 0, + doc: /* SQLite library version string. */) + (void) +{ + if (!init_sqlite_functions ()) + error ("sqlite support is not available"); + return build_string (sqlite3_libversion ()); +} + #endif /* HAVE_SQLITE3 */ DEFUN ("sqlitep", Fsqlitep, Ssqlitep, 1, 1, 0, @@ -814,6 +827,7 @@ syms_of_sqlite (void) defsubr (&Ssqlite_columns); defsubr (&Ssqlite_more_p); defsubr (&Ssqlite_finalize); + defsubr (&Ssqlite_version); DEFSYM (Qset, "set"); DEFSYM (Qfull, "full"); #endif diff --git a/test/src/sqlite-tests.el b/test/src/sqlite-tests.el index be4f60ab57f..e9ddf9c0bef 100644 --- a/test/src/sqlite-tests.el +++ b/test/src/sqlite-tests.el @@ -243,6 +243,7 @@ (ert-deftest sqlite-returning () (skip-unless (sqlite-available-p)) + (skip-unless (version<= "3.35" (sqlite-version))) (let (db) (progn (setq db (sqlite-open)) -- 2.39.2