Fix some races in sqlite3

This commit is contained in:
Ron Pedde 2006-03-05 05:40:48 +00:00
parent 1e48e88215
commit 4b728b899d
2 changed files with 10 additions and 2 deletions

View File

@ -50,6 +50,7 @@ typedef struct tag_config {
int use_mdns; /**< Should we do rendezvous advertisements? */ int use_mdns; /**< Should we do rendezvous advertisements? */
int stop; /**< Time to exit? */ int stop; /**< Time to exit? */
int reload; /**< Time to reload and/or rescan the database? */ int reload; /**< Time to reload and/or rescan the database? */
int foreground; /**< Whether or not we are running in foreground */
#if 0 #if 0
char *configfile; /**< path to config file */ char *configfile; /**< path to config file */

View File

@ -183,13 +183,14 @@ int db_sqlite3_exec(char **pe, int loglevel, char *fmt, ...) {
int err; int err;
char *perr; char *perr;
db_sqlite3_lock();
va_start(ap,fmt); va_start(ap,fmt);
query=sqlite3_vmprintf(fmt,ap); query=sqlite3_vmprintf(fmt,ap);
va_end(ap); va_end(ap);
DPRINTF(E_DBG,L_DB,"Executing: %s\n",query); DPRINTF(E_DBG,L_DB,"Executing: %s\n",query);
db_sqlite3_lock();
err=sqlite3_exec(db_sqlite3_songs,query,NULL,NULL,&perr); err=sqlite3_exec(db_sqlite3_songs,query,NULL,NULL,&perr);
if(err != SQLITE_OK) { if(err != SQLITE_OK) {
db_get_error(pe,DB_E_SQL_ERROR,perr); db_get_error(pe,DB_E_SQL_ERROR,perr);
@ -424,7 +425,13 @@ int db_sqlite3_event(int event_type) {
*/ */
int db_sqlite3_insert_id(void) { int db_sqlite3_insert_id(void) {
return (int)sqlite3_last_insert_rowid(db_sqlite3_songs); int result;
db_sqlite3_lock();
result = (int)sqlite3_last_insert_rowid(db_sqlite3_songs);
db_sqlite3_unlock();
return result;
} }