-2

我目前正在开发一个与 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 &"

有谁知道我的问题的解决方案?

4

1 回答 1

1

有谁知道我的问题的解决方案?

编译器刚刚向您展示了一个。

“不兼容的指针……等等等等;删除&

(强调我的)

于 2013-03-05T06:39:00.640 回答