[sqlite] "database is locked" error using lastest linux kernel

2009-07-13 Thread hua zhou
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, ) != 
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 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, ) != 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, 
) != 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", );



#if 1
if (SQLITE_OK != sqlite3_exec(gJcDb, "PRAGMA synchronous = FULL", NULL, 
 NULL, )) //OFF FULL NORMAL
{
fprintf(stderr, "!!!synchronous set error, %s\n", errMsg);
sqlite3_free(errMsg);
}
#endif
sqlite3_exec(gJcDb, "PRAGMA synchronous", PragmaSetCallback, "PRAGMA 
synchronous", );

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, , 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, ))
{
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


[sqlite] "database is locked" error using lastest linux kernel

2009-07-12 Thread hua zhou
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, ) != 
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 sqlite3 Makefile, short test 
code(code.c) and test database(jc.db).


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, ) != 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, 
) != 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", );



#if 1
if (SQLITE_OK != sqlite3_exec(gJcDb, "PRAGMA synchronous = FULL", NULL, 
 NULL, )) //OFF FULL NORMAL
{
fprintf(stderr, "!!!synchronous set error, %s\n", errMsg);
sqlite3_free(errMsg);
}
#endif
sqlite3_exec(gJcDb, "PRAGMA synchronous", PragmaSetCallback, "PRAGMA 
synchronous", );

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, , 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, ))
{
fprintf(stderr, "!!!Load Terminal from db failed");
CloseDb(gJcDb);
return 2;
}

return 0;
}#!/usr/make
#
# Makefile for SQLITE
#
# This makefile is suppose to be configured automatically using the
# autoconf.  But if that does not work for you, you can configure
# the makefile manually.  Just set the parameters below to values that
# work well for your system.
#
# If the configure script does not work out-of-the-box, you might
# be able to get it to work by giving it some hints.  See the comment
# at the beginning of configure.in for additional information.
#

# The toplevel directory of the source tree.  This is the directory
# that contains this "Makefile.in" and the "configure.in" script.
#
TOP = .

# C Compiler and options for use in building executables that
# will run on the platform that is doing the build.
#
BCC = gcc  -g

# C Compile and options for use in building executables that 
# will run on the target platform.  (BCC and TCC are usually the
# same unless your are cross-compiling.)
#
TCC = arm-9tdmi-linux-gnueabi-gcc   -g -O2 -DSQLITE_OS_UNIX=1 -I. -I${TOP}/src

# Define this for the autoconf-based build, so that the code knows it can
# include the generated config.h
# 
TCC += -D_HAVE_SQLITE_CONFIG_H

# Define -DNDEBUG to compile without debugging (i.e., for production usage)
# Omitting the define will cause extra debugging code to be inserted and
# includes extra comments when "EXPLAIN stmt" is used.
#
TCC += -DNDEBUG -DSQLITE_ALLOW_XTHREAD_CONNECT=1

# Compiler options needed for programs that use the TCL library.
#
TCC += 

# The library that programs using TCL must link against.
#
LIBTCL =  

# Compiler options needed for programs that use the readline() library.
#
READLINE_FLAGS = -DHAVE_READLINE=0 

# The library that programs using readline() must link against.
#
LIBREADLINE = 

# Should the database engine be compiled threadsafe
#
TCC += -DSQLITE_THREADSAFE=1

# Do threads override each others locks by default (1), or do we test (-1)
#
TCC += -DSQLITE_THREAD_OVERRIDE_LOCK=-1

# Any target libraries which libsqlite must be linked against
# 
TLIBS = -lpthread 

# Flags controlling use of the in memory btree implementation
#
# SQLITE_TEMP_STORE is 0 to force 

[sqlite] "database is locked" error using lastest linux kernel

2009-07-12 Thread hua zhou

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, ) != 
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 sqlite3 Makefile, short test 
code(code.c) and test database(jc.db).


Any advise from you will be appreciated!



  
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users