mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Add the new sqlite3_create_filename() and sqlite3_free_filename() interfaces
for use by Shims. Use these interfaces inside the multiplexor. FossilOrigin-Name: 9469f36ac89e4b75d0ab25fefbeff25201992c53141da915dcaa017083cab6db
This commit is contained in:
62
src/main.c
62
src/main.c
@@ -4242,6 +4242,68 @@ static const char *databaseName(const char *zName){
|
||||
return zName;
|
||||
}
|
||||
|
||||
/*
|
||||
** Append text z[] to the end of p[]. Return a pointer to the first
|
||||
** character after then zero terminator on the new text in p[].
|
||||
*/
|
||||
static char *appendText(char *p, const char *z){
|
||||
size_t n = strlen(z);
|
||||
memcpy(p, z, n+1);
|
||||
return p+n+1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate memory to hold names for a database, journal file, WAL file,
|
||||
** and query parameters. The pointer returned is valid for use by
|
||||
** sqlite3_filename_database() and sqlite3_uri_parameter() and related
|
||||
** functions.
|
||||
**
|
||||
** Memory layout must be compatible with that generated by the pager
|
||||
** and expected by sqlite3_uri_parameter() and databaseName().
|
||||
*/
|
||||
char *sqlite3_create_filename(
|
||||
const char *zDatabase,
|
||||
const char *zJournal,
|
||||
const char *zWal,
|
||||
int nParam,
|
||||
const char **azParam
|
||||
){
|
||||
sqlite3_int64 nByte;
|
||||
int i;
|
||||
char *pResult, *p;
|
||||
nByte = strlen(zDatabase) + strlen(zJournal) + strlen(zWal) + 10;
|
||||
for(i=0; i<nParam*2; i++){
|
||||
nByte += strlen(azParam[i])+1;
|
||||
}
|
||||
pResult = p = sqlite3_malloc64( nByte );
|
||||
if( p==0 ) return 0;
|
||||
memset(p, 0, 4);
|
||||
p += 4;
|
||||
p = appendText(p, zDatabase);
|
||||
for(i=0; i<nParam*2; i++){
|
||||
p = appendText(p, azParam[i]);
|
||||
}
|
||||
*(p++) = 0;
|
||||
p = appendText(p, zJournal);
|
||||
p = appendText(p, zWal);
|
||||
*(p++) = 0;
|
||||
*(p++) = 0;
|
||||
assert( (sqlite3_int64)(p - pResult)==nByte );
|
||||
return pResult + 4;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free memory obtained from sqlite3_create_filename(). It is a severe
|
||||
** error to call this routine with any parameter other than a pointer
|
||||
** previously obtained from sqlite3_create_filename() or a NULL pointer.
|
||||
*/
|
||||
void sqlite3_free_filename(char *p){
|
||||
if( p==0 ) return;
|
||||
p = (char*)databaseName(p);
|
||||
sqlite3_free(p - 4);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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
|
||||
|
Reference in New Issue
Block a user