ios - ios 无法将镜像更新到 SQLite

标签 ios image sqlite

我按如下方式创建表,并将数据插入该表,我检索了表值以及它创建、插入和检索成功的图像,但没有更新下面的 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”:语法错误

最佳答案

UPDATE places SET place = ?, ... ,snoozeTime = ? reminderImage = ? where...

snoozeTimereminderImage 之间的逗号丢失了。

关于ios - ios 无法将镜像更新到 SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29295644/

相关文章:

ios - 如果 iPad mini 分辨率为 1024x768,现有的 iPad 应用程序是否可以在其上运行?

ios - Creative SDK 图像组件 - IOS

ios - undefined symbol “_OBJC_CLASS_$_CkoFtp2”与chilikat的链接错误

python-3.x - 无法使用 Anaconda Python 导入 sqlite3

ios - 使用 "jiulongw/swift-unity "将 Unity 与 Push Extension 集成到 Swift 项目

java - 这段代码对图片类做了什么

Python-尝试找到具有最大绿色圆圈的图像

java - 如何垂直移动 JApplet 中的图像?

android - 无法使用 sqlite 查询获取过去两个月的数据

python - 将 python 字典插入 SQLite 数据库