【问题标题】:Sqlite error in Objective CObjective C 中的 Sqlite 错误
【发布时间】:2012-01-11 19:40:55
【问题描述】:

我试图在我的 iPhone 应用程序上删除我的 sqlite 数据库中的一些条目,但出现了一个奇怪的错误。

这是我的代码:

if(sqlite3_open([databasePath UTF8String], &yerocDB)==SQLITE_OK)
{   
    sqlite3_stmt *compiledstatement;

    NSString *deleteSql=[NSString stringWithFormat: @"delete from Favorites_Table where playlist_name = Studying and date = 1/1/2012"];
    const char *sqlstmt = [deleteSql UTF8String];

    if(sqlite3_prepare_v2(yerocDB, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
    {
        int result = sqlite3_step(compiledstatement);

        if(SQLITE_DONE != result)

            NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(yerocDB) );
    }else{
        NSLog(@"didn't delete error: %s", sqlite3_errmsg(yerocDB));
    }
    sqlite3_finalize(compiledstatement);
}

然后我得到错误:

didn't delete error: no such column: Studying

playlist_name 和 date 是我的专栏...为什么说“学习”不是专栏?

【问题讨论】:

    标签: iphone objective-c sqlite


    【解决方案1】:

    您需要将Studying 括在单引号中。还有你的约会对象。

    这个:

    delete from Favorites_Table 
    where playlist_name = Studying and date = 1/1/2012
    

    应该是这样的:

    delete from Favorites_Table 
    where playlist_name = 'Studying' and date = '2012-01-01'
    

    原因是如果你不把它放在单引号里,解析器会认为它是一个列名。在您的第一个查询中,您试图从Favorites_Table 中删除playlist_name 列等于Studying 列。从此你的错误,“没有这样的列。”

    一旦你修正了关于学习的引用,你的约会也会出错。日期使用 ISO 格式 (yyyy-mm-dd) 进行比较。根据经验,不要使用本地化的 mm/dd/yyyy 或 dd/mm/yyyy 格式。

    【讨论】:

      猜你喜欢
      • 2018-12-05
      • 2012-09-24
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 2017-01-28
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多