From: drh <> Date: Tue, 17 May 2022 14:59:05 +0000 (+0000) Subject: Add the sqlite3_db_name() interface. X-Git-Tag: version-3.39.0~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ff16267d7da5ddbf1edb683d4524e5f8d7d7ae11;p=thirdparty%2Fsqlite.git Add the sqlite3_db_name() interface. FossilOrigin-Name: 2ad152236c408cbb1f942b221de4bf3cbaa9c35313d7eb07a63f46b6040fc981 --- diff --git a/manifest b/manifest index f301d1271b..0d33f28d54 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\smemory\sbarriers\sto\smulti-threaded\scode\sin\stest4.c. -D 2022-05-16T16:55:22.768 +C Add\sthe\ssqlite3_db_name()\sinterface. +D 2022-05-17T14:59:05.338 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -516,8 +516,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 173845e5a6bac96ae937409e4f876b631f26b31dabb9df8fd0eb3b130b2bb3a7 F src/json.c 7749b98c62f691697c7ee536b570c744c0583cab4a89200fdd0fc2aa8cc8cbd6 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa -F src/loadext.c 0705c2747212934183398f09891415d2f7f3113d0f543ccb205640210b20e617 -F src/main.c 135858d2ede0b83d779e71b07ede9c1d6b6eaab7b77bc2a85729584152769faf +F src/loadext.c 853385cc7a604157e137585097949252d5d0c731768e16b044608e5c95c3614b +F src/main.c e946f1d9e30bf49cf399ddf860cfd2319e3a97bbaabfb8e87d6ab985a20d54ad F src/malloc.c a9127efdcef92d6934c6339ea9813075b90edc0ce2e5c723556381a3828fb720 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de @@ -555,9 +555,9 @@ F src/resolve.c a4eb3c617027fd049b07432f3b942ea7151fa793a332a11a7d0f58c9539e104f F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 74060a09f66c0c056f3c61627e22cb484af0bbfa29d7d14dcf17c684742c15de F src/shell.c.in 176cad562152cbbafe7ecc9c83c82850e2c3d0cf33ec0a52d67341d35c842f22 -F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17 +F src/sqlite.h.in d15c307939039086adca159dd340a94b79b69827e74c6d661f343eeeaefba896 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 -F src/sqlite3ext.h f49e28c25bd941e79794db5415fdf7b202deb3bc072ed6f1ed273d578703684e +F src/sqlite3ext.h a988810c9b21c0dc36dc7a62735012339dc76fc7ab448fb0792721d30eacb69d F src/sqliteInt.h fbe2d12cc13e80ac88c69ecde5ef9f052025fba78aa10f3eed0c71a5302e9a76 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4a3da6d77eeb3531cb0dbdf7047772a2a1b99f98c69e90ce009c75fe6328b2c0 @@ -1954,8 +1954,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f935c155ef205802c16b4ebea4a3fb01bf5689662b7b4f2af56f0f9021d6d4b1 -R c061fe23c974300044233fa5c2c2a108 -U dan -Z f437a9eddd805a091e05b9805ba19805 +P 9260f4e0fdc8066b4772999bacb5f4130ef714d4ac1967029ceacff618bc48ff +R d21e2300c9b9f847363079df1fcdef69 +U drh +Z 456d2006914746a322619f144cfb48fc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 270e063e23..e411b5aaea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9260f4e0fdc8066b4772999bacb5f4130ef714d4ac1967029ceacff618bc48ff \ No newline at end of file +2ad152236c408cbb1f942b221de4bf3cbaa9c35313d7eb07a63f46b6040fc981 \ No newline at end of file diff --git a/src/loadext.c b/src/loadext.c index bba431096d..dd15d9a4da 100644 --- a/src/loadext.c +++ b/src/loadext.c @@ -503,11 +503,12 @@ static const sqlite3_api_routines sqlite3Apis = { /* Version 3.39.0 and later */ #ifndef SQLITE_OMIT_DESERIALIZE sqlite3_deserialize, - sqlite3_serialize + sqlite3_serialize, #else 0, - 0 + 0, #endif + sqlite3_db_name }; /* True if x is the directory separator character diff --git a/src/main.c b/src/main.c index c40b3162ab..3ae1f4fe30 100644 --- a/src/main.c +++ b/src/main.c @@ -4626,6 +4626,24 @@ Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ return iDb<0 ? 0 : db->aDb[iDb].pBt; } +/* +** Return the name of the N-th database schema. Return NULL if N is out +** of range. +*/ +const char *sqlite3_db_name(sqlite3 *db, int N){ +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + (void)SQLITE_MISUSE_BKPT; + return 0; + } +#endif + if( N<0 || N>=db->nDb ){ + return 0; + }else{ + return db->aDb[N].zDbSName; + } +} + /* ** Return the filename of the database associated with a database ** connection. diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9c4df2292d..7c3664253d 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6276,6 +6276,26 @@ int sqlite3_get_autocommit(sqlite3*); */ sqlite3 *sqlite3_db_handle(sqlite3_stmt*); +/* +** CAPI3REF: Return The Schema Name For A Database Connection +** METHOD: sqlite3 +** +** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name +** for the N-th database on database connection D, or a NULL pointer of N is +** out of range. +** +** Space to hold the string that is returned by sqlite3_db_name() is managed +** by SQLite itself. The string might be deallocated by any operation that +** changes the schema, including [ATTACH] or [DETACH] or calls to +** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that +** occur on a different thread. Applications that need to +** remember the string long-term should make their own copy. Applications that +** are accessing the same database connection simultaneously on multiple +** threads should mutex-protect calls to this API and should make their own +** private copy of the result prior to releasing the mutex. +*/ +const char *sqlite3_db_name(sqlite3 *db, int N); + /* ** CAPI3REF: Return The Filename For A Database Connection ** METHOD: sqlite3 diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index a75dd496e7..2cdd0e429b 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -356,6 +356,7 @@ struct sqlite3_api_routines { sqlite3_int64,sqlite3_int64,unsigned); unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*, unsigned int); + const char *(*db_name)(sqlite3*,int); }; /* @@ -674,10 +675,12 @@ typedef int (*sqlite3_loadext_entry)( #define sqlite3_vtab_in sqlite3_api->vtab_in #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next +/* Version 3.39.0 and later */ #ifndef SQLITE_OMIT_DESERIALIZE #define sqlite3_deserialize sqlite3_api->deserialize #define sqlite3_serialize sqlite3_api->serialize #endif +#define sqlite3_db_name sqlite3_api->db_name #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)