0

我有一个 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
4

1 回答 1

5

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

const char *sqlStatement = [[NSString stringWithFormat:@"UPDATE t_catalog SET updateTime='%@'", time] cStringUsingEncoding:NSASCIIStringEncoding];
于 2012-05-20T11:29:00.643 回答