当i = 1执行时,我的应用程序在语句(sqlite3_step(insertAlert) == SQLITE_DONE)
上崩溃。任何人都可以告诉我它崩溃的原因吗?
sqlite3_stmt *insertAlert;
textmeAppDelegate *textme = (textmeAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *insert = @"INSERT INTO alerts (alert_id, email_address, messege_text, when_to_send, how_often_send, recipient_phone_number) VALUES(?, ?, ?, ?, ?, ?)";
if(sqlite3_prepare_v2(textme.dbConn, [insert UTF8String], -1, &insertAlert, NULL) == SQLITE_OK)
{
NSDictionary *tmpDictionary;
NSString *alertId;
for(int i=0; i<[keys count]; i++)
{
alertId = [NSString stringWithFormat:@"%@", [keys objectAtIndex:i]];
tmpDictionary = [NSDictionary dictionaryWithDictionary:[dictionary2 objectForKey:alertId]];
sqlite3_bind_text(insertAlert, 1, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"alert_id"]], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertAlert, 2, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"email_address"]], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertAlert, 3, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"messege_text"]], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertAlert, 4, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"when_to_send"]], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertAlert, 5, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"how_often_send"]], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertAlert, 6, [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"recipient_phone_number"]], -1, SQLITE_TRANSIENT);
if (sqlite3_step(insertAlert) == SQLITE_DONE) {
sqlite3_reset(insertAlert);
sqlite3_clear_bindings(insertAlert);
}
else {
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(textme.dbConn));
//[textme showError:@"Device Error" errMsg:sqlite3_errmsg(textme.dbConn)];
return FALSE;
}
}
sqlite3_finalize(insertAlert);
}
答案 0 :(得分:2)
你认为sqlite3_bind_text()能理解如何处理NSString吗?我没有。
我很惊讶
要解决此问题,您需要更换
[NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"alert_id"]]
与
[[NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"alert_id"]] UTF8String]
和所有其他sqlite3_bind_text()行类似。