vendredi 27 mars 2015

i getting the fail to update the image to SQLite in ios

i'm creating the tables as followed and i insert the data to that table and i retrieved the table values as well the image also it created,inserted and retrieved successfully,but not updating the image in the sqlite table below is my entire code help me thanks in advance

here is the create code



-(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;
}


the table is successfully created by the above fields.And my insert code is below..



-(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;
}


And my update code is below:



-(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);
}
}
}


When i update it getting the following error. update all fails error: near "reminderImage": syntax error


Aucun commentaire:

Enregistrer un commentaire