Iphone 第二条insert语句的sqlite3崩溃

Iphone 第二条insert语句的sqlite3崩溃,iphone,objective-c,iphone-sdk-3.0,sqlite,Iphone,Objective C,Iphone Sdk 3.0,Sqlite,当为i=1执行语句时,我的应用程序在语句(sqlite3\u步骤(insertAlert)==SQLITE\u完成)上崩溃。有人能告诉我为什么它会坠毁吗 sqlite3_stmt *insertAlert; textmeAppDelegate *textme = (textmeAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString *insert = @"INSERT INTO alerts (alert_id

当为i=1执行语句时,我的应用程序在语句
(sqlite3\u步骤(insertAlert)==SQLITE\u完成)上崩溃。有人能告诉我为什么它会坠毁吗

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);
}
sqlite3\u stmt*insertAlert;
textmeAppDelegate*textmeAppDelegate=(textmeAppDelegate*)[[UIApplication sharedApplication]委托];
NSString*insert=@“插入警报(警报id、电子邮件地址、消息文本、发送时间、发送频率、收件人电话号码)值(?,,,,,,)”;
if(sqlite3\u prepare\u v2(textme.dbConn,[insert UTF8String],-1,&insertAlert,NULL)==SQLITE\u确定)
{
NSDictionary*tmpDictionary;
NSString*警报ID;

对于(int i=0;i您认为sqlite3\u bind\u text()了解如何处理NSString吗?我不知道

我很惊讶

  • 即使i==0,它也可以工作
  • 您没有在所有这些绑定上看到编译器警告
  • 要修复,您需要替换

    [NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"alert_id"]]
    


    类似地,对于所有其他sqlite3_bind_text()行。

    你应该考虑使用核心数据。你应该考虑使用包装器而不是直接与C API交互。你能提供核心数据或一些示例用法的好教程吗?谢谢,我想出来了,你是正确的,编译器在SqLITE3BIN文本(每一行)上发出警告。即使i==0,也没有存储任何数据,但它在执行时没有任何崩溃(也令人惊讶)。
    [[NSString stringWithFormat:@"%@", [tmpDictionary objectForKey:@"alert_id"]] UTF8String]