我收到错误"数据库被锁定"在SQlite版本3.7.11上,这意味着在同一个数据库上发生了两个或更多不兼容的操作。 我试过Googling for" sqlite数据库被锁定" SQLite版本3和#34;中的"文件锁定和并发,但我无法弄清楚这背后的原因。
Sqlite3 API由以下函数封装(在伪代码中):
int dbClass::ExecSql(char *sql)
{
gisLONG rtn=0;
CHECK_PTRVAL(m_dbHandle)
if(sql==NULL)
{
rtn=SQLITE_OK;
}
else
{
CloseCursor();
rtn=local_sqlite3_prepare_v2((sqlite3 *)m_dbHandle,sql,-1,(sqlite3_stmt **)&m_pStmt,NULL);
}
if (rtn==SQLITE_OK)
{
rtn=sqlite3_step((sqlite3_stmt *)m_pStmt);
if (rtn==SQLITE_ROW)
{
m_bFirst=false;
m_curPos=1;
rtn=1;
}
else if(rtn==SQLITE_DONE)
{
m_curPos=-1;
rtn=1;
}
else
{
rtn=0;
}
return(rtn);
}
int errcode=sqlite3_errcode((sqlite3 *)m_dbHandle);
errcode=sqlite3_extended_errcode((sqlite3 *)m_dbHandle);
return (0);
}
bool TableExist(string tblName)
{
string sql = "select name from sqlite_master where type='table' and name=";
sql += tblName;
ExecSql(sql); // a function executes sql language
return RowCount() > 0; // counts of result by "select" sql
}
long CreateTableInner(string tblName, string fieldList)
{
if (!TableExist())
{
string sql = "create table ";
sql += tblName + fieldList;
return ExecSql(sql);
}
}
long CreateBlobTableInner(string tblName)
{
if (!TableExist())
{
string sql = "create table ";
sql += tblName;
sql += "blob";
sql += " (id INT, classname BLOB)";
return ExecSql(sql);
}
}
void CreateTable(short type)
{
if (type == 1)
{
CreateTableInner("cache", "length INT, start INT");
CreateTableInner("path", "name BLOB");
}
else if (type == 2)
{
CreateTableInner("dot", "id INT, name BLOB");
CreateBlobTableInner("dot);
CreateTableInner("line", "id INT, name BLOB");
CreateBlobTableInner("line");
}
}
OutFunction(short type)
{
OpenA(fileName, type); // it calls sqlite3_open_v2(), then do nothing
CreateTable(type);
}
A.dll调用OutFunction(1); 当所有表都存在时,OutFunction()只打开x.db文件。当B.exe调用A.dll打开时,x.db无法修改。 如果CreateTable()被注释掉,一切正常,可以更改x.db。
任何人都可以找到原因吗?