mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Redesign for better legacy compatibility. Add the sqlite3_uri_key() interface.
FossilOrigin-Name: bcb43d11c4d0be36888c9e968ccdf85e7d7fccd72a29866f85c014e0562d4b93
This commit is contained in:
79
src/main.c
79
src/main.c
@@ -4241,25 +4241,6 @@ int sqlite3_test_control(int op, ...){
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/*
|
||||
** This routine appears inside assert() statements only.
|
||||
**
|
||||
** Return the number of URI parameters that follow the filename.
|
||||
*/
|
||||
int sqlite3UriCount(const char *z){
|
||||
int n = 0;
|
||||
if( z==0 ) return 0;
|
||||
z += strlen(z)+1;
|
||||
while( z[0] ){
|
||||
z += strlen(z)+1;
|
||||
z += strlen(z)+1;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
/*
|
||||
** This is a utility routine, useful to VFS implementations, that checks
|
||||
** to see if a database file was a URI that contained a specific query
|
||||
@@ -4272,21 +4253,30 @@ 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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a pointer to the name of Nth query parameter of the filename.
|
||||
*/
|
||||
const char *sqlite3_uri_key(const char *zFilename, int N){
|
||||
if( zFilename==0 || N<0 ) return 0;
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
while( zFilename[0] && (N--)>0 ){
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
zFilename += sqlite3Strlen30(zFilename) + 1;
|
||||
}
|
||||
return zFilename[0] ? zFilename : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a boolean value for a query parameter.
|
||||
*/
|
||||
@@ -4312,6 +4302,25 @@ sqlite3_int64 sqlite3_uri_int64(
|
||||
return bDflt;
|
||||
}
|
||||
|
||||
/*
|
||||
** The Pager stores the Journal filename, WAL filename, and Database filename
|
||||
** consecutively in memory, in that order, with prefixes \000\001\000,
|
||||
** \002\000, and \003\000, in that order. Thus the three names look like query
|
||||
** parameters if you start at the first prefix.
|
||||
**
|
||||
** This routine backs up a filename to the start of the first prefix.
|
||||
**
|
||||
** This only works if the filenamed passed in was obtained from the Pager.
|
||||
*/
|
||||
static const char *startOfNameList(const char *zName){
|
||||
while( zName[0]!='\001' || zName[1]!=0 ){
|
||||
zName -= 3;
|
||||
while( zName[0]!='\000' ){ zName--; }
|
||||
zName++;
|
||||
}
|
||||
return zName-1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Translate a filename that was handed to a VFS routine into the corresponding
|
||||
** database, journal, or WAL file.
|
||||
@@ -4323,19 +4332,13 @@ sqlite3_int64 sqlite3_uri_int64(
|
||||
** corruption.
|
||||
*/
|
||||
const char *sqlite3_filename_database(const char *zFilename){
|
||||
const Pager *pPager = sqlite3PagerFromFilename(zFilename);
|
||||
assert( pPager!=0 );
|
||||
return sqlite3PagerFilename(pPager, 0);
|
||||
return sqlite3_uri_parameter(zFilename - 3, "\003");
|
||||
}
|
||||
const char *sqlite3_filename_journal(const char *zFilename){
|
||||
const Pager *pPager = sqlite3PagerFromFilename(zFilename);
|
||||
assert( pPager!=0 );
|
||||
return sqlite3PagerJournalFilename(pPager);
|
||||
return sqlite3_uri_parameter(startOfNameList(zFilename), "\001");
|
||||
}
|
||||
const char *sqlite3_filename_wal(const char *zFilename){
|
||||
const Pager *pPager = sqlite3PagerFromFilename(zFilename);
|
||||
assert( pPager!=0 );
|
||||
return sqlite3PagerWalFilename(pPager);
|
||||
return sqlite3_uri_parameter(startOfNameList(zFilename), "\002");
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user