我正在创建表格,如下所示,我将数据插入到该表中,我检索了表格值以及它创建,插入和检索成功的图像,但是没有更新下面的sqlite表格中的图像是我的整个代码帮我提前谢谢 这是创建代码
-(int) createTable:(NSString*) filePath
{
sqlite3* db = NULL;
int rc=0;
NSLog(@"create");
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"Failed to open db connection");
}
else
{
char * query ="CREATE TABLE IF NOT EXISTS places ( id INTEGER PRIMARY KEY AUTOINCREMENT,place TEXT ,locationname TEXT,time TEXT,description TEXT,notifyTime TEXT,radius TEXT,lat DOUBLE,lon DOUBLE ,notify TEXT,selection INTEGER,status INTEGER,radiusMeter DOUBLE,frequency INTEGER,notifiedStatus INTEGER,snoozeNooftimes INTEGER,snoozeStatus INTEGER,snoozeTime TEXT,reminderImage BLOB)";
char * errMsg;
rc = sqlite3_exec(db, query,NULL,NULL,&errMsg);
if(SQLITE_OK != rc)
{
NSLog(@"Failed to create table rc:%d, msg=%s",rc,errMsg);
}
else{
NSLog(@"Sucessfully Created ");
}
sqlite3_close(db);
}
return rc;
}
表格由上述字段成功创建。我的插入代码在下面..
-(int) insert:(NSString *)filePath withName:(NSString *)place location:(NSString *)locationString description:(NSString*)description time:(NSString*)time notify:(NSString *)notifyTime radius:(NSString *)radius lat:(double)lat lon:(double)lon notify:(NSString *)notify selec:(int)selection stat:(int)status radius:(double)radiusMeter freq:(int)frequency notifyStatus:(int)notifiedStatus snoozeNooftime:(int)snoozeNoOfTimes snoozeStatus:(int)snoozeStat snoozeTime:(NSString *)snoozeTime img:(NSData *)imageData
{
sqlite3* db = NULL;
int rc=0;
sqlite3_stmt *stmt =NULL;
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"insert Failed to open db connection");
}
else
{
const char *insertSQL="INSERT INTO places (place,locationname,time,description,notifyTime,radius,lat,lon,notify,selection,status,radiusMeter,frequency,notifiedStatus,snoozeNooftimes,snoozeStatus,snoozeTime,reminderImage) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
if (sqlite3_prepare_v2(db, insertSQL, -1, & stmt, NULL) != SQLITE_OK)
{
NSLog(@"INSERT fails error: %s", sqlite3_errmsg(db));
}
else
{
sqlite3_bind_text(stmt, 1, [place UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, [locationString UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, [time UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 4, [description UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 5, [notifyTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 6, [radius UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(stmt, 7, lat);
sqlite3_bind_double(stmt, 8, lon);
sqlite3_bind_text(stmt, 9, [notify UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 10, selection );
sqlite3_bind_int(stmt, 11, status);
sqlite3_bind_double(stmt, 12, radiusMeter);
sqlite3_bind_int(stmt, 13, frequency);
sqlite3_bind_int(stmt, 14, notifiedStatus);
sqlite3_bind_int(stmt, 15, snoozeNoOfTimes);
sqlite3_bind_int(stmt, 16, snoozeStat);
sqlite3_bind_text(stmt, 17, [snoozeTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, 18, [imageData bytes], [imageData length], SQLITE_TRANSIENT);
int success = sqlite3_step(stmt);
sqlite3_reset(stmt);
if (success == SQLITE_ERROR)
{
}
else
{
// NSLog(@"insert query %@",query);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}
}
return rc;
}
我的更新代码如下:
-(void) update:(NSString *)filePath withName:(NSString *)place location:(NSString *)locationString description:(NSString*)description time:(NSString*)time notify:(NSString *)notifyTime radius:(NSString *)radius lat:(double)lat lon:(double)lon notify:(NSString *)notify selec:(int)selection where:(int)idd stat:(int)status radius:(double)radiusMeter freq:(int)frequency notifyStatus:(int)notifiedStatus snoozeNooftime:(int)snoozeNoOfTimes snoozeStatus:(int)snoozeStat snoozeTime:(NSString *)snoozeTime img:(NSData *)imageData
{
sqlite3* db = NULL;
int rc=0;
sqlite3_stmt* stmt =NULL;
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"update all Failed to open db connection");
}
else
{
const char *sql = "UPDATE places SET place = ?, locationname = ?, time = ?, description = ?, notifyTime = ?, radius = ?, lat = ?, lon = ?, notify = ?, selection = ?, status = ?, radiusMeter = ?, frequency = ?, notifiedStatus = ?,snoozeNooftimes = ?,snoozeStatus = ?,snoozeTime = ? reminderImage = ? where id = ?";
if (sqlite3_prepare_v2(db, sql, -1, & stmt, NULL) != SQLITE_OK)
{
NSLog(@"update all fails error: %s", sqlite3_errmsg(db));
}
else
{
sqlite3_bind_text(stmt, 1, [place UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, [locationString UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, [time UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 4, [description UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 5, [notifyTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 6, [radius UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(stmt, 7, lat);
sqlite3_bind_double(stmt, 8, lon);
sqlite3_bind_text(stmt, 9, [notify UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 10, selection );
sqlite3_bind_int(stmt, 11, status);
sqlite3_bind_double(stmt, 12, radiusMeter);
sqlite3_bind_int(stmt, 13, frequency);
sqlite3_bind_int(stmt, 14, notifiedStatus);
sqlite3_bind_int(stmt, 15, snoozeNoOfTimes);
sqlite3_bind_int(stmt, 16, snoozeStat);
sqlite3_bind_text(stmt, 17, [snoozeTime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, 18, [imageData bytes], [imageData length], SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 0, idd);
int success = sqlite3_step(stmt);
sqlite3_reset(stmt);
if (success == SQLITE_ERROR)
{
}
else
{
NSLog(@"update all success");
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}
}
}
当我更新它时收到以下错误。 更新全部失败错误:“reminderImage”附近:语法错误
答案 0 :(得分:1)
UPDATE places SET place = ?, ... ,snoozeTime = ? reminderImage = ? where...
snoozeTime
和reminderImage
之间的逗号丢失。