gpt4 book ai didi

iphone - iPhone中的Select语句崩溃问题

转载 作者:行者123 更新时间:2023-12-03 21:16:42 29 4
gpt4 key购买 nike

-(void)insertDataToFavourites:(int)pageid :(NSString *)description
{
sqlite3_stmt *insertStatement = nil;
NSString *sql;
int returnvalue;

sql = [NSString stringWithFormat:@"insert into AddFavorite (Id,Description) VALUES (?,?)"];

returnvalue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &insertStatement, NULL);

if (returnvalue == 1){
NSAssert1 (0,@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_text(insertStatement, 2,[[tempDict objectForKey:@"pageid"] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertStatement, 3,[[tempDict objectForKey:@"desc"] UTF8String], -1, SQLITE_TRANSIENT);
if (SQLITE_DONE != sqlite3_step(insertStatement)){
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}
else{
sqlite3_reset(insertStatement);
}

sqlite3_finalize(insertStatement);

if(sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL) != SQLITE_DONE ){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Data saved Successfully." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}

else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Data insertion error." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}

}

上面的代码我正在将数据插入到 Sqlite 数据库表中。这向我显示警报数据已成功保存。 将数据插入收藏夹列表时。

-(void)getFavoriteList
{

if([ArrFav count] > 0)
[ArrFav removeAllObjects];

ArrFav = [[NSMutableArray alloc] init];

sqlite3_stmt *selectStatement=nil;
NSString *sql;
int returnvalue;

sql=[NSString stringWithFormat:@"SELECT Description FROM AddFavorite"];

returnvalue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectStatement, NULL);

if(returnvalue==1)
{
NSAssert1(0, @"Error: failed to select the database with message '%s'.", sqlite3_errmsg(database));
}

NSMutableDictionary *dict;
NSString *str;
if(returnvalue == SQLITE_OK)
{
while(sqlite3_step(selectStatement) == SQLITE_ROW)
{
dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement,1)] forKey:@"Description"];

[ArrFav addObject:[dict objectForKey:@"Description"]];
NSLog(@"Favorite data is:--> %@",ArrFav);
}
}
}

这是从sqlite数据库表中选择数据的代码。在行 [dict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement,1)] forKey:@"Description"]; 应用程序崩溃了。

任何人都可以建议我解决这个问题,为什么会出现这个问题以及解决方案是什么?

最佳答案

我认为您正在尝试为字典中的键设置零值。这意味着您没有从 SELECT 语句中获得任何结果。请使用 Mozilla sqlite 编辑器检查数据库的内容,并查看您尝试检索的值是否存在于数据库中。

关于iphone - iPhone中的Select语句崩溃问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823437/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com