diff options
author | drh <> | 2022-05-17 14:59:05 +0000 |
---|---|---|
committer | drh <> | 2022-05-17 14:59:05 +0000 |
commit | ff16267d7da5ddbf1edb683d4524e5f8d7d7ae11 (patch) | |
tree | c68c01513cf1a5ef79915a7ea6418c9808f09df1 /src | |
parent | c7d7ebd75587bec2227befda16c298bf175b5fa9 (diff) | |
download | sqlite-ff16267d7da5ddbf1edb683d4524e5f8d7d7ae11.tar.gz sqlite-ff16267d7da5ddbf1edb683d4524e5f8d7d7ae11.zip |
Add the sqlite3_db_name() interface.
FossilOrigin-Name: 2ad152236c408cbb1f942b221de4bf3cbaa9c35313d7eb07a63f46b6040fc981
Diffstat (limited to 'src')
-rw-r--r-- | src/loadext.c | 5 | ||||
-rw-r--r-- | src/main.c | 18 | ||||
-rw-r--r-- | src/sqlite.h.in | 20 | ||||
-rw-r--r-- | src/sqlite3ext.h | 3 |
4 files changed, 44 insertions, 2 deletions
diff --git a/src/loadext.c b/src/loadext.c index bba431096..dd15d9a4d 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 c40b3162a..3ae1f4fe3 100644 --- a/src/main.c +++ b/src/main.c @@ -4627,6 +4627,24 @@ Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ } /* +** 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 9c4df2292..7c3664253 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6277,6 +6277,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 a75dd496e..2cdd0e429 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) |