mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Add support for the sqlite3_get_clientdata() and sqlite3_set_clientdata()
interfaces, to better support JNI. FossilOrigin-Name: 9806c0dd2802d68b67c25c4f3347ed532f9a98b051e775d34e9182dd2f099891
This commit is contained in:
71
src/main.c
71
src/main.c
@@ -1253,6 +1253,14 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){
|
||||
}
|
||||
#endif
|
||||
|
||||
while( db->pDbData ){
|
||||
DbClientData *p = db->pDbData;
|
||||
db->pDbData = p->pNext;
|
||||
assert( p->pData!=0 );
|
||||
if( p->xDestructor ) p->xDestructor(p->pData);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
|
||||
/* Convert the connection into a zombie and then close it.
|
||||
*/
|
||||
db->eOpenState = SQLITE_STATE_ZOMBIE;
|
||||
@@ -3710,6 +3718,69 @@ int sqlite3_collation_needed16(
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
/*
|
||||
** Find existing client data.
|
||||
*/
|
||||
void *sqlite3_get_clientdata(sqlite3 *db, const char *zName){
|
||||
DbClientData *p;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
for(p=db->pDbData; p; p=p->pNext){
|
||||
if( strcmp(p->zName, zName)==0 ){
|
||||
void *pResult = p->pData;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return pResult;
|
||||
}
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add new client data to a database connection.
|
||||
*/
|
||||
int sqlite3_set_clientdata(
|
||||
sqlite3 *db, /* Attach client data to this connection */
|
||||
const char *zName, /* Name of the client data */
|
||||
void *pData, /* The client data itself */
|
||||
void (*xDestructor)(void*) /* Destructor */
|
||||
){
|
||||
DbClientData *p, **pp;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
pp = &db->pDbData;
|
||||
for(p=db->pDbData; p && strcmp(p->zName,zName); p=p->pNext){
|
||||
pp = &p->pNext;
|
||||
}
|
||||
if( p ){
|
||||
assert( p->pData!=0 );
|
||||
if( p->xDestructor ) p->xDestructor(p->pData);
|
||||
if( pData==0 ){
|
||||
*pp = p->pNext;
|
||||
sqlite3_free(p);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}else if( pData==0 ){
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
size_t n = strlen(zName);
|
||||
p = sqlite3_malloc64( sizeof(DbClientData)+n+1 );
|
||||
if( p==0 ){
|
||||
if( xDestructor ) xDestructor(pData);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
memcpy(p->zName, zName, n+1);
|
||||
p->pNext = db->pDbData;
|
||||
db->pDbData = p;
|
||||
}
|
||||
p->pData = pData;
|
||||
p->xDestructor = xDestructor;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/*
|
||||
** This function is now an anachronism. It used to be used to recover from a
|
||||
|
Reference in New Issue
Block a user