0

我在执行我的应用程序时遇到问题,我收到以下警告:“不兼容的指针类型将'const char *'传递给'sqlite3_stmt *'类型的参数(又名'struct sqlite3_stmt *')”。

它只发生在以下几行:

if (sqlite3_prepare_v2(database, sql, -1, &databasePath, NULL)!=SQLITE_OK)

while (sqlite3_step(sql) == SQLITE_ROW)

szStore = [NSString stringWithUTF8String:(char*)sqlite3_column_text(sql, 0)];

szReg = [NSString stringWithUTF8String:(char*)sqlite3_column_text(sql, 1)];

sqlite3_finalize(sql); 

这是功能:

-(IBAction)setInput:(id)sender
{
NSString *strStoreNumber;
NSString *strRegNumber;

strStoreNumber = StoreNumber.text;
strRegNumber = RegNumber.text;
lblStoreNumber.text = strStoreNumber;
lblRegNumber.text = strRegNumber;

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,         NSUserDomainMask, YES);
NSString* documentsDirectory = [paths lastObject];
//    NSString* databasePath = [documentsDirectory   stringByAppendingPathComponent:@"tblStore.sqlite"];
NSString* databasePath = [[NSBundle mainBundle] pathForResource:@"tblStore" ofType:@"sqlite"];

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
{

NSLog(@"Opened sqlite database at %@", databasePath);

//...stuff
} 
else 
{
NSLog(@"Failed to open database at %@ with error %s", databasePath,     sqlite3_errmsg(database));
sqlite3_close (database);
}

NSString *querystring;

// create your statement
querystring = [NSString stringWithFormat:@"SELECT strStore FROM tblStore WHERE strStore = %@;", strStoreNumber];  

const char *sql = [querystring UTF8String];

NSString *szStore = nil;
NSString *szReg = nil;


if (sqlite3_prepare_v2(database, sql, -1, &databasePath, NULL)!=SQLITE_OK) //queryString =    Statement
{
NSLog(@"sql problem occured with: %s", sql);
NSLog(@"%s", sqlite3_errmsg(database));
}
else
{
// you could handle multiple rows here

while (sqlite3_step(databasePath) == SQLITE_ROW) // queryString = statement
{            
    szStore = [NSString stringWithUTF8String:(char*)sqlite3_column_text(databasePath, 0)];
    szReg = [NSString stringWithUTF8String:(char*)sqlite3_column_text(databasePath, 1)];
} // while        

}

sqlite3_finalize(databasePath);

// Do something with data...  
}

任何帮助或见解将不胜感激。谢谢!

4

1 回答 1

0

数据库路径被传递而不是语句句柄指针。代替

if (sqlite3_prepare_v2(database, sql, -1, &databasePath, NULL)!=SQLITE_OK)

sqlite3_stmt *statement = nil;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL)!=SQLITE_OK)

并将终结行设置为

sqlite3_finalize(statement);

sqlite3_prepare_v2上的文档提供了有关此方法的更多详细信息。

于 2012-05-05T09:13:13.810 回答