我目前正在開發一個與sqlite數據庫交互的項目。問題是每次我想連接到數據庫時,我必須打開並準備數據庫。所以我想讓這些步驟更具通用性,我決定創建一個能爲我完成這些步驟的普通課程。在目標中傳遞引用參數C
+(void)openAndPrepareDatabase:(sqlite3 *)db andStatement:(sqlite3_stmt *)statement andSql:(const char *)sql
{
@try
{
if(!sqlite3_open([[self getDatabasePath] UTF8String], &db) == SQLITE_OK)
{
NSException *myException = [NSException exceptionWithName:@"Can't open database" reason:@"Can't open database" userInfo:Nil];
@throw myException;
}
if(!sqlite3_prepare(db, sql, -1, &statement, NULL) == SQLITE_OK)
{
NSException *myException = [NSException exceptionWithName:@"Can't prepare database" reason:@"Can't prepare database" userInfo:Nil];
@throw myException;
}
}
@catch (NSException *exception)
{
@throw exception;
}
}
+(void)openAndPrepareDatabaseV2:(sqlite3 *)db andStatement:(sqlite3_stmt *)statement andSql:(const char *)sql
{
@try
{
if(!sqlite3_open([[self getDatabasePath] UTF8String], &db) == SQLITE_OK)
{
NSException *myException = [NSException exceptionWithName:@"Can't open database" reason:@"Can't open database" userInfo:Nil];
@throw myException;
}
if(!sqlite3_prepare_v2(db, sql, -1, &statement, NULL) == SQLITE_OK)
{
NSException *myException = [NSException exceptionWithName:@"Can't prepare database" reason:@"Can't prepare database" userInfo:Nil];
@throw myException;
}
}
@catch (NSException *exception)
{
@throw exception;
}
}
但是當我嘗試調用它在我的對象,即:
[Common openAndPrepareDatabase:&db andStatement:&statement andSql:sql];
我得到了一個警告:
"Incompatible pointer types sending 'sqlite3_stmt **' (aka 'struct sqlite3_stmt **') to parameter of type 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *'); remove &"
有誰知道我的問題的解決方案?
你爲什麼不讀的複製粘貼前的錯誤信息順便說一下? – 2013-03-05 06:40:06