mirror of
https://github.com/sqlite/sqlite.git
synced 2026-10-23 21:49:02 +03:00
Have API functions sqlite3_serialize, sqlite3_limit, sqlite3_busy_timeout, sqlite3_error_offset, sqlite3_db_name, sqlite3_get_autocommit, sqlite3_errcode, sqlite3_total_changes64, sqlite3_changes64, sqlite3_last_insert_rowid and sqlite3_expired take and hold the database mutex while running.
FossilOrigin-Name: 0d57a60060ee822137f3c1cf7ba1cf40ded024d038981bd51b9cab3bf7f42b2f
This commit is contained in:
20
manifest
20
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\sboth\sa\sbuffer\soverread\sand\soverwrite\sin\sthe\ssessions\srebase\smodule.
|
||||
D 2026-06-26T15:17:08.287
|
||||
C Have\sAPI\sfunctions\ssqlite3_serialize,\ssqlite3_limit,\ssqlite3_busy_timeout,\ssqlite3_error_offset,\ssqlite3_db_name,\ssqlite3_get_autocommit,\ssqlite3_errcode,\ssqlite3_total_changes64,\ssqlite3_changes64,\ssqlite3_last_insert_rowid\sand\ssqlite3_expired\stake\sand\shold\sthe\sdatabase\smutex\swhile\srunning.
|
||||
D 2026-06-26T17:36:58.237
|
||||
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
@@ -700,14 +700,14 @@ F src/insert.c dfd311b0ac2d4f6359e62013db67799757f4d2cc56cca5c10f4888acfbbfa3fd
|
||||
F src/json.c 82b685636c9ff9d677734682e170f637fbfef3a14febf8cb274c4b7e7a272dcc
|
||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||
F src/loadext.c 56a542244fbefc739a2ef57fac007c16b2aefdb4377f584e9547db2ce3e071f9
|
||||
F src/main.c 1f9590257e6f0863b3225ea53df5f0f64dd1a5e70f7da3be57690818d05d2d2c
|
||||
F src/main.c 348784a162acc19d62373560c2fa93886520e0dd94f19bfe8bd2491280e95607
|
||||
F src/malloc.c 422f7e0498e1c9ef967f06283b6f2c0b16db6b905d8e06f6dbc8baaa3e4e6c5a
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2
|
||||
F src/mem2.c c8bfc9446fd0798bddd495eb5d9dbafa7d4b7287d8c22d50a83ac9daa26d8a75
|
||||
F src/mem3.c 30301196cace2a085cbedee1326a49f4b26deff0af68774ca82c1f7c06fda4f6
|
||||
F src/mem5.c b7da5c10a726aacacc9ad7cdcb0667deec643e117591cc69cf9b4b9e7f3e96ff
|
||||
F src/memdb.c 0a0e827311cec57fdea2ed3142d6684704a1b90e7995b286f74fd7d1a6c5a62c
|
||||
F src/memdb.c 290a67488b83fccb0ca9c637342043466e0b16c945ef7d68e0f91679661ff315
|
||||
F src/memjournal.c c283c6c95d940eb9dc70f1863eef3ee40382dbd35e5a1108026e7817c206e8a0
|
||||
F src/msvc.h 80b35f95d93bf996ccb3e498535255f2ef1118c78764719a7cd15ab4106ccac9
|
||||
F src/mutex.c 00b8cee206a67fd764d001f3a148494331d8d0b3b9c3974ecd69ff29bb444462
|
||||
@@ -806,7 +806,7 @@ F src/vacuum.c d3d35d8ae893d419ade5fa196d761a83bddcbb62137a1a157ae751ef38b26e82
|
||||
F src/vdbe.c 6c57525d7db0232d52687d30da1093db0c152f14206c2ef1adf0c19a09d863e3
|
||||
F src/vdbe.h 70e862ac8a11b590f8c1eaac17a0078429d42bc4ea3f757a9af0f451dd966a71
|
||||
F src/vdbeInt.h c31ba4dc8d280c2b1dc89c6fcee68f2555e3813ab34279552c20b964c0e338b1
|
||||
F src/vdbeapi.c 6cdcbe5c7afa754c998e73d2d5d2805556268362914b952811bdfb9c78a37cf1
|
||||
F src/vdbeapi.c e0908d04bbeedbbb4ad6529063fc25a11950f42be4936a48cd9e0fc1f837c3f1
|
||||
F src/vdbeaux.c 81687c55682b9f4d942186695f4f7fa4743c564a985e0889def52eded9076d61
|
||||
F src/vdbeblob.c b3f0640db9642fbdc88bd6ebcc83d6009514cafc98f062f675f2c8d505d82692
|
||||
F src/vdbemem.c efacb8f229422d2a4db0ed38e49b7f3897862a98d82b261aa3b43d7a2d98c6da
|
||||
@@ -2201,9 +2201,9 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
|
||||
F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
|
||||
P 6a55dc85b73ef98f0ef31d7b0740bfe46ebb25653f2dff4eb34074d1b455925a
|
||||
Q +cc36f1741308ea354d540d27c89b92d69a0481885ca3463bdaf0b9ab27464d78
|
||||
R 3924a9995f73c73b45f171f23ff4b87a
|
||||
U drh
|
||||
Z 8629b86aace1297c182a849c90e527db
|
||||
P 12d0d2363a3082f68153393ed1aa91264ee987bc9187e7afd131d503f66e4faa
|
||||
Q +7bfd5c810c6f04ddfd275457a2a03b4da0c3e7d4ee5acb61a54d805e2e67f819
|
||||
R 8e1ed0dd5add9274b65390abdc7e90c0
|
||||
U dan
|
||||
Z fb281d3c1be2eb1fc433a639f6a89650
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
||||
@@ -1 +1 @@
|
||||
12d0d2363a3082f68153393ed1aa91264ee987bc9187e7afd131d503f66e4faa
|
||||
0d57a60060ee822137f3c1cf7ba1cf40ded024d038981bd51b9cab3bf7f42b2f
|
||||
|
||||
80
src/main.c
80
src/main.c
@@ -1111,13 +1111,17 @@ static int nocaseCollatingFunc(
|
||||
** Return the ROWID of the most recent insert
|
||||
*/
|
||||
sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
|
||||
i64 iRet;
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return db->lastRowid;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iRet = db->lastRowid;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1139,13 +1143,17 @@ void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){
|
||||
** Return the number of changes in the most recent call to sqlite3_exec().
|
||||
*/
|
||||
sqlite3_int64 sqlite3_changes64(sqlite3 *db){
|
||||
i64 iRet;
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return db->nChange;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iRet = db->nChange;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
int sqlite3_changes(sqlite3 *db){
|
||||
return (int)sqlite3_changes64(db);
|
||||
@@ -1155,13 +1163,17 @@ int sqlite3_changes(sqlite3 *db){
|
||||
** Return the number of changes since the database handle was opened.
|
||||
*/
|
||||
sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){
|
||||
i64 iRet;
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return db->nTotalChange;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iRet = db->nTotalChange;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
int sqlite3_total_changes(sqlite3 *db){
|
||||
return (int)sqlite3_total_changes64(db);
|
||||
@@ -1844,6 +1856,7 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
||||
#endif
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( ms>0 ){
|
||||
sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
|
||||
(void*)db);
|
||||
@@ -1854,6 +1867,7 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
|
||||
}else{
|
||||
sqlite3_busy_handler(db, 0, 0);
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -2759,9 +2773,11 @@ int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zMsg){
|
||||
*/
|
||||
int sqlite3_error_offset(sqlite3 *db){
|
||||
int iOffset = -1;
|
||||
if( db && sqlite3SafetyCheckSickOrOk(db) && db->errCode ){
|
||||
if( db && sqlite3SafetyCheckSickOrOk(db) ){
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iOffset = db->errByteOffset;
|
||||
if( db->errCode ){
|
||||
iOffset = db->errByteOffset;
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
}
|
||||
return iOffset;
|
||||
@@ -2815,25 +2831,43 @@ const void *sqlite3_errmsg16(sqlite3 *db){
|
||||
** passed to this function, we assume a malloc() failed during sqlite3_open().
|
||||
*/
|
||||
int sqlite3_errcode(sqlite3 *db){
|
||||
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
||||
int iRet;
|
||||
if( !db ) return SQLITE_NOMEM_BKPT;
|
||||
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
||||
return SQLITE_MISUSE_BKPT;
|
||||
}
|
||||
if( !db || db->mallocFailed ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( db->mallocFailed ){
|
||||
iRet = SQLITE_NOMEM_BKPT;
|
||||
}else{
|
||||
iRet = db->errCode & db->errMask;
|
||||
}
|
||||
return db->errCode & db->errMask;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
int sqlite3_extended_errcode(sqlite3 *db){
|
||||
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
||||
int iRet;
|
||||
if( !db ) return SQLITE_NOMEM_BKPT;
|
||||
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
||||
return SQLITE_MISUSE_BKPT;
|
||||
}
|
||||
if( !db || db->mallocFailed ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( db->mallocFailed ){
|
||||
iRet = SQLITE_NOMEM_BKPT;
|
||||
}else{
|
||||
iRet = db->errCode;
|
||||
}
|
||||
return db->errCode;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
int sqlite3_system_errno(sqlite3 *db){
|
||||
return db ? db->iSysErrno : 0;
|
||||
int iRet = 0;
|
||||
if( db ){
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iRet = db->iSysErrno;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3028,6 +3062,7 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
||||
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
|
||||
return -1;
|
||||
}
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
oldLimit = db->aLimit[limitId];
|
||||
if( newLimit>=0 ){ /* IMP: R-52476-28732 */
|
||||
if( newLimit>aHardLimit[limitId] ){
|
||||
@@ -3037,6 +3072,7 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
||||
}
|
||||
db->aLimit[limitId] = newLimit;
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return oldLimit; /* IMP: R-53341-35419 */
|
||||
}
|
||||
|
||||
@@ -3934,13 +3970,17 @@ int sqlite3_global_recover(void){
|
||||
** by the next COMMIT or ROLLBACK.
|
||||
*/
|
||||
int sqlite3_get_autocommit(sqlite3 *db){
|
||||
int iRet;
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return db->autoCommit;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
iRet = db->autoCommit;
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4965,17 +5005,19 @@ Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
|
||||
** of range.
|
||||
*/
|
||||
const char *sqlite3_db_name(sqlite3 *db, int N){
|
||||
const char *zRet = 0;
|
||||
#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;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( N>=0 && N<db->nDb ){
|
||||
zRet = db->aDb[N].zDbSName;
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return zRet;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
18
src/memdb.c
18
src/memdb.c
@@ -759,7 +759,7 @@ unsigned char *sqlite3_serialize(
|
||||
sqlite3_int64 sz;
|
||||
int szPage = 0;
|
||||
sqlite3_stmt *pStmt = 0;
|
||||
unsigned char *pOut;
|
||||
unsigned char *pOut = 0;
|
||||
char *zSql;
|
||||
int rc;
|
||||
|
||||
@@ -769,12 +769,13 @@ unsigned char *sqlite3_serialize(
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
|
||||
if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
|
||||
p = memdbFromDbSchema(db, zSchema);
|
||||
iDb = sqlite3FindDbName(db, zSchema);
|
||||
if( piSize ) *piSize = -1;
|
||||
if( iDb<0 ) return 0;
|
||||
if( iDb<0 ) goto serialize_out;
|
||||
if( p ){
|
||||
MemStore *pStore = p->pStore;
|
||||
assert( pStore->pMutex==0 );
|
||||
@@ -785,19 +786,17 @@ unsigned char *sqlite3_serialize(
|
||||
pOut = sqlite3_malloc64( pStore->sz );
|
||||
if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
|
||||
}
|
||||
return pOut;
|
||||
goto serialize_out;
|
||||
}
|
||||
pBt = db->aDb[iDb].pBt;
|
||||
if( pBt==0 ) return 0;
|
||||
if( pBt==0 ) goto serialize_out;
|
||||
szPage = sqlite3BtreeGetPageSize(pBt);
|
||||
zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema);
|
||||
rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
|
||||
sqlite3_free(zSql);
|
||||
if( rc ) return 0;
|
||||
if( rc ) goto serialize_out;
|
||||
rc = sqlite3_step(pStmt);
|
||||
if( rc!=SQLITE_ROW ){
|
||||
pOut = 0;
|
||||
}else{
|
||||
if( rc==SQLITE_ROW ){
|
||||
sz = sqlite3_column_int64(pStmt, 0)*szPage;
|
||||
if( sz==0 ){
|
||||
sqlite3_reset(pStmt);
|
||||
@@ -831,6 +830,9 @@ unsigned char *sqlite3_serialize(
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(pStmt);
|
||||
|
||||
serialize_out:
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return pOut;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,14 @@
|
||||
** added or changed.
|
||||
*/
|
||||
int sqlite3_expired(sqlite3_stmt *pStmt){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
return p==0 || p->expired;
|
||||
int iRet = 1;
|
||||
if( pStmt ){
|
||||
Vdbe *p = (Vdbe*)pStmt;
|
||||
sqlite3_mutex_enter(p->db->mutex);
|
||||
iRet = p->expired;
|
||||
sqlite3_mutex_leave(p->db->mutex);
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user