sqlite3 crashes for second insert statement
Posted
by Ayaz Alavi
on Stack Overflow
See other posts from Stack Overflow
or by Ayaz Alavi
Published on 2010-05-26T14:51:24Z
Indexed on
2010/05/26
15:01 UTC
Read the original article
Hit count: 279
My App is crashing on statement (sqlite3_step(insertAlert) == SQLITE_DONE)
when executed for i = 1. Can anybody tell me why it is crashing?
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_finalize(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);
}
© Stack Overflow or respective owner