我在我的C / C ++项目中使用ubunt 12.04中的eclipse,并且在尝试执行查询时遇到以下错误。 我已经发布了堆栈以及查询执行和语法:
这个人总是成功
查询1:CREATE TABLE IF NOT EXISTS HS_TABLE(用户TEXT NOT NULL,passwd TEXT NOT NULL,PRIMARY KEY(user));
此查询第一次成功但第二次失败
查询2:INSERT OR REPLACE INTO HS_TABLE(user,passwd)SELECT'user 0','passwd 0'UNION SELECT'user 1','passwd 1'UNION SELECT'user 2','passwd 2'; < / p>
线程[1] 5556 [核心:3](暂停:信号: SIGSEGV :分段错误)
sqlite3Init() at sqlite3.c:93,817 0x466540
sqlite3ReadSchema() at sqlite3.c:93,855 0x466667
sqlite3LocateTable() at sqlite3.c:81,026 0x4506f9
sqlite3LocateTableItem() at sqlite3.c:81,065 0x45081f
sqlite3SrcListLookup() at sqlite3.c:85,104 0x457c79
sqlite3Insert() at sqlite3.c:89,190 0x45e612
yy_reduce() at sqlite3.c:1,10,576 0x4822d2
sqlite3Parser() at sqlite3.c:1,11,347 0x484a5d
sqlite3RunParser() at sqlite3.c:1,12,172 0x4856fc
sqlite3Prepare() at sqlite3.c:94,032 0x466a48
sqlite3LockAndPrepare() at sqlite3.c:94,124 0x466d77
sqlite3_prepare_v2 at sqlite3.c:94,200 0x466f2e
另外我的sqlite3_close(sqlite3 * db)函数失败,程序每次终止
线程[1] 5845 [core:0](暂停:信号:SIGSEGV:分段错误)
sqlite3MemSize() at sqlite3.c:15,594 0x406d41
sqlite3MallocSize() at sqlite3.c:19,021 0x407a73
sqlite3_free() at sqlite3.c:19,044 0x407afd
sqlite3DbFree() at sqlite3.c:19,080 0x407c16
sqliteDeleteColumnNames() at sqlite3.c:81,237 0x450da7
sqlite3DeleteTable() at sqlite3.c:81,296 0x450f0e
sqlite3SchemaClear() at sqlite3.c:85,035 0x457b23
sqlite3LeaveMutexAndCloseZombie() at sqlite3.c:1,13,533 0x487682
sqlite3Close() at sqlite3.c:1,13,473 0x487558
sqlite3_close() at sqlite3.c:1,13,486 0x48757c
CODE:
sql_ret = sqlite3_prepare_v2(m_database, CurrQuery, -1, &stmt, NULL);
我的查询中是否有任何错误,如果是这样,为什么会崩溃,这种情况发生在我尝试在EClipse中调试时。
以下是代码:
ErrorCode DBResponder::openDB(const char* DBPath)
{
UINT64 sql_ret;
sql_ret = sqlite3_open(DBPath,&m_database);
cout<<__func__<<": sql_ret = "<<sql_ret<<endl;
if( sql_ret != SQLITE_OK )
return DB_ERROR;
return NO_ERROR;
}
ErrorCode DBResponder::closeDB()
{
UINT64 sql_ret;
sql_ret = sqlite3_close(m_database);
cout<<__func__<<": sql_ret = "<<sql_ret<<endl;
if( sql_ret != SQLITE_OK )
return DB_ERROR;
return NO_ERROR;
}
ErrorCode DBResponder::executeQuery()
{
sqlite3_stmt *stmt;
UINT64 sql_ret;
const char *CurrQuery = "INSERT OR REPLACE INTO HS_TABLE (user, passwd) SELECT 'user 0','passwd 0' UNION SELECT 'user 1','passwd 1' UNION SELECT 'user 2','passwd 2';";
ErrorCode err = NO_ERROR;
cout<<endl<<__func__<<": "<<CurrQuery<<endl;
sql_ret = sqlite3_prepare_v2(m_database, CurrQuery, -1, &stmt, NULL);
cout<<__func__<<": sql_ret (sqlite3_prepare_v2) = "<<sql_ret<<endl;
if(sql_ret != SQLITE_OK)
return DB_ERROR;
HInfo* h;
while(1)
{
sql_ret = sqlite3_step(stmt);
cout<<__func__<<": sql_ret (sqlite3_step) = "<<sql_ret<<endl;
if(sql_ret == SQLITE_ROW)
{
hs = (HInfo*)malloc(1*sizeof(HInfo));
strncpy(hs->user, (const char*)sqlite3_column_text(stmt,0), MAX_STR_LEN );
strncpy(hs->passwd, (const char*)sqlite3_column_text(stmt,1), MAX_STR_LEN);
llist.add( (void*) hs);
}
else if(sql_ret == SQLITE_DONE)
{
//query finished
//return hs;
writeResponse(hs);
break;
}
else
{
//error
err = DB_ERROR;
writeResponse(NULL);
break;
}
}//end of while loop
sql_ret = sqlite3_finalize(stmt);
cout<<__func__<<": sql_ret (sqlite3_finalize) = "<<sql_ret<<endl;
if(sql_ret != SQLITE_OK)
err = DB_ERROR;
return err;
}
我也得到错误: 无效的参数' 候选人是: int sqlite3_open(const char *,* *) “的
对于每个sqlite3函数都是这样的。注意* ,而不是sqlite3 *,但项目正在构建中。我在链接器中包含了dl和pthread。请查看此错误: http://stackoverflow.com/questions/13859956/how-to-use-sqlite3-c-and-sqlite3-h-in-eclipse-c-c-project
请帮忙! 感谢