我有一个sqlite语法错误。什么是不正确的?

时间:2012-05-20 11:01:44

标签: sql ios sqlite

我有一个sqlite语法错误。什么是不正确的?

我的代码:

+ (void)insertUpdateCatalogTime:(NSString *)time
{
 NSLog(@"%@", time);
 sqlite3 *database; 
 if(sqlite3_open([DatabaseManager databasePath], &database) == SQLITE_OK) 
 {
    const char *sqlStatement = [[NSString stringWithFormat:@"UPDATE t_catalog SET updateTime=%@", time] cStringUsingEncoding:NSASCIIStringEncoding];
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) 
    {
        while(sqlite3_step(compiledStatement) == SQLITE_ROW);
    } 
    else 
    {
        NSLog(@"sqlite3_prepare_v2 error %s", sqlite3_errmsg(database));
    }       
    sqlite3_finalize(compiledStatement);
 } 
 else 
 { 
    NSLog(@"sqlite3_open error");
 }  
 sqlite3_close(database);
}

并记录:

 2012-05-10 14:23:04
 sqlite3_prepare_v2 error near "14": syntax error

1 个答案:

答案 0 :(得分:5)

您是否尝试使用单引号包装updateTime?

const char *sqlStatement = [[NSString stringWithFormat:@"UPDATE t_catalog SET updateTime='%@'", time] cStringUsingEncoding:NSASCIIStringEncoding];