My problem is get a "database is locked" error using lastest linux kernel
(above 2.6.28) , while the code can run smoothly on linux 2.6.26.2
kernel(vmware pc686 host) and on 2.6.26.3 kernel(arm9 embed system).
The problem code is:
#if 1
if (sqlite3_exec(gJcDb, "PRAGMA cache_size = 4000", NULL, NULL, &errMsg) !=
SQLITE_OK)
{
fprintf(stderr, "!!!cache_size set error, %s\n", errMsg);
sqlite3_free(errMsg);
}
#endif
Even if I comment the the #if 0/1 #endif code block, still can't open a
table and access the table data. I tried sqlite3.6.7 and sqlite3.6.16, the
problem is same.
Three attached files are compiling&making sqlite3 Makefile, short test
code(code.c) and test database(jc.db).
Compile Sqlite with full functions and NDEBUG option and run, I get following
info:
fcntl unknown 4 1 0
fcntl unknown 4 2 0
fcntl 1073864000 4 SETLK RDLCK 0 1 0 -1
fcntl-failure-reason: RDLCK 0 1 0
fcntl 1073864000 4 SETLK RDLCK 1073741824 1 1 -1
fcntl-failure-reason: RDLCK 1073741824 1 1
PRAGMA page_size value is 1024
PRAGMA temp_store value is 2
PRAGMA read_uncommitted value is 1
PRAGMA journal_mode value is off
fcntl 1073864000 4 SETLK RDLCK 1073741824 1 229840 -1
fcntl-failure-reason: RDLCK 1073741824 1 229840
fcntl 1073864000 4 SETLK RDLCK 1073741824 1 229840 -1
fcntl-failure-reason: RDLCK 1073741824 1 229840
!!!Load Terminal from db failedfcntl 1073864000 4 SETLK RDLCK 1073741824 1
229840 -1
fcntl-failure-reason: RDLCK 1073741824 1 229840
Any advise from you will be appreciated!
inline static int PragmaSetCallback(void * pParam, int pColumnCount, char **
pColumnValue, char ** pColumnName)
{
fprintf(stdout, "%s value is %s\n", (char *)pParam, pColumnValue[0]);
return 0;
}
static bool OpenAndInitDb(char * pDbFileName)
{
char * errMsg = NULL;
sqlite3_enable_shared_cache(1);
if (sqlite3_open(pDbFileName, &gJcDb) != SQLITE_OK)
{
fprintf(stderr, "!!!Open database error: %s\n",
sqlite3_errmsg(gJcDb));
return false;
}
#if 1
if (sqlite3_exec(gJcDb, "PRAGMA cache_size = 4000", NULL, NULL,
&errMsg) != SQLITE_OK)
{
fprintf(stderr, "!!!cache_size set error, %s\n", errMsg);
sqlite3_free(errMsg);
}
#endif
sqlite3_exec(gJcDb, "PRAGMA cache_size", PragmaSetCallback, "PRAGMA
cache_size", &errMsg);
#if 1
if (SQLITE_OK != sqlite3_exec(gJcDb, "PRAGMA synchronous = FULL", NULL,
NULL, &errMsg)) //OFF FULL NORMAL
{
fprintf(stderr, "!!!synchronous set error, %s\n", errMsg);
sqlite3_free(errMsg);
}
#endif
sqlite3_exec(gJcDb, "PRAGMA synchronous", PragmaSetCallback, "PRAGMA
synchronous", &errMsg);
return true;
}
static bool LoadTerminalFromDb(sqlite3 * pDb, Terminal * pTerminal)
{
pTerminal->WorkStateId = 1;
pTerminal->DefaultUpChannelTypeId = ChannelType_UpTnGprsClient;
pTerminal->IsChanged = false;
sqlite3_stmt * stmt = 0;
if (sqlite3_prepare_v2(pDb, "select * from Terminal", -1, &stmt, 0) !=
SQLITE_OK)
{
return false;
}
if (sqlite3_step(stmt) != SQLITE_ROW)
{
sqlite3_finalize(stmt);
return false;
}
return true;
}
sqlite3 *gJcDb = NULL;
int main(int argc, char *argv[])
{
char * db = "./jc.db";
if (access(db, F_OK) || !OpenAndInitDb(db))
{
fprintf(stderr, "!!!Open and init db failed");
return 1;
}
if (!LoadTerminalFromDb(gJcDb, &gTerminal))
{
fprintf(stderr, "!!!Load Terminal from db failed");
CloseDb(gJcDb);
return 2;
}
return 0;
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users