現在、sqlite データベースと対話するプロジェクトを開発しています。問題は、データベースに接続するたびに、データベースを開いて準備する必要があることです。そこで、これらのステップをより一般的なものにしたいと思い、これらのステップを実行する共通クラスを作成することにしました。
+(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;
}
}
しかし、オブジェクトでそれを呼び出そうとすると、IE:
[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 &"
誰かが私の問題の解決策を知っていますか?