aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-01-10 18:05:55 +0000
committerdrh <drh@noemail.net>2020-01-10 18:05:55 +0000
commit8875b9e7b5d699fac33171f7bafa32c7adb62dbf (patch)
tree96ef099b8bd66b938f65d7f27fd6c023991bd7fb /src/main.c
parentb2fe5a7c35a114e8d4b869968c61c7b6a9a99cb7 (diff)
downloadsqlite-8875b9e7b5d699fac33171f7bafa32c7adb62dbf.tar.gz
sqlite-8875b9e7b5d699fac33171f7bafa32c7adb62dbf.zip
Rearchitect the way in which filenames are stored in the Pager object so that
the sqlite3_uri_parameter() interface will work from journal and WAL filenames too. This check-in implements the central idea, and compile and runs somewhat, but crashes on an extended test. FossilOrigin-Name: 2ae77bd2335708343bce4541b4d2cf16edfe3fd5bc2dfb93757238c926aa960b
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index c0f53916a..5426c8d71 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4272,13 +4272,17 @@ int sqlite3UriCount(const char *z){
** returns a NULL pointer.
*/
const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
+ const Pager *pPager;
+ const char *z;
if( zFilename==0 || zParam==0 ) return 0;
- zFilename += sqlite3Strlen30(zFilename) + 1;
- while( zFilename[0] ){
- int x = strcmp(zFilename, zParam);
- zFilename += sqlite3Strlen30(zFilename) + 1;
- if( x==0 ) return zFilename;
- zFilename += sqlite3Strlen30(zFilename) + 1;
+ pPager = sqlite3PagerFromFilename(zFilename);
+ assert( pPager!=0 );
+ z = sqlite3PagerQueryParameters(pPager);
+ while( z[0] ){
+ int x = strcmp(z, zParam);
+ z += sqlite3Strlen30(z) + 1;
+ if( x==0 ) return z;
+ z += sqlite3Strlen30(z) + 1;
}
return 0;
}
@@ -4309,6 +4313,32 @@ sqlite3_int64 sqlite3_uri_int64(
}
/*
+** Translate a filename that was handed to a VFS routine into the corresponding
+** database, journal, or WAL file.
+**
+** It is an error to pass this routine a filename string that was not
+** passed into the VFS from the SQLite core. Doing so is similar to
+** passing free() a pointer that was not obtained from malloc() - it is
+** an error that we cannot easily detect but that will likely cause memory
+** corruption.
+*/
+const char *sqlite3_filename_database(const char *zFilename){
+ const Pager *pPager = sqlite3PagerFromFilename(zFilename);
+ assert( pPager!=0 );
+ return sqlite3PagerFilename(pPager, 0);
+}
+const char *sqlite3_filename_journal(const char *zFilename){
+ const Pager *pPager = sqlite3PagerFromFilename(zFilename);
+ assert( pPager!=0 );
+ return sqlite3PagerJournalFilename(pPager);
+}
+const char *sqlite3_filename_wal(const char *zFilename){
+ const Pager *pPager = sqlite3PagerFromFilename(zFilename);
+ assert( pPager!=0 );
+ return sqlite3PagerWalFilename(pPager);
+}
+
+/*
** Return the Btree pointer identified by zDbName. Return NULL if not found.
*/
Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){