[C ++] [SQLite]如何使用给定条件更新SQLite Blob列(其中ID = X) [英] [C++][SQLite] How to update a SQLite Blob column with a given condition (where ID=X)

查看:123
本文介绍了[C ++] [SQLite]如何使用给定条件更新SQLite Blob列(其中ID = X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQLite中有一个包含的表(在其他)BLOB列和ID列。在我的程序中,我需要首先设置ID(主键),我以这种方式执行



< pre class ="prettyprint"> std :: string sql_s =" INSERT INTO SIGNANTE(ID)" \
" VALUES(" + id_s +");英寸;
const char * sql = sql_s.c_str();

rc = sqlite3_exec(db,sql,0,0,& zErrMsg);

之后我想用BLOB更新条目,我这样做:

 sqlite3_stmt * stmtInsert = nullptr; 
std :: string photo_sql =" UPDATE SIGNANTE set(FOTO)VALUES(?)其中ID =" + id_s +" ;英寸;
const char * photo_char = photo_sql.c_str();

sqlite3_prepare_v2(db,photo_char,-1,& stmtInsert,nullptr);
sqlite3_bind_blob(stmtInsert,1,blobData->数据,blobData->长度,SQLITE_STATIC);

如果我尝试INSERT而不是UPDATE(没有"where ID =" +" id_s +" ;;")一切正常但如果我更新它,我会在下一行收到错误
消息:

 if(sqlite3_step(stmtInsert)== SQLITE_DONE){
TextOut-> Text =" it working" ;;
}



我收到"访问冲突"在里面"wstring" class。



我的问题是,如何使用给定ID(或任何其他主键)的BLOB条目更新SQLite。





解决方案

嗨Carlos Her,


好吧,首先请确保SQL命令正确。您是否尝试在UWP应用程序外运行SQL命令以查看是否可以成功更新数据库?


最好的问候,


Roy


I have a table in SQLite which contains (among others) a BLOB column and a ID column. In my program I need to set the ID (primary key) first, which I do in this fashion:

std::string sql_s = "INSERT INTO SIGNANTE (ID)" \
            "VALUES (" + id_s +"); ";
        const char * sql = sql_s.c_str();

        rc = sqlite3_exec(db, sql, 0, 0, &zErrMsg);

Afterwards I want to UPDATE the entry with a BLOB and I do it this way:

       sqlite3_stmt* stmtInsert = nullptr;
        std::string photo_sql = "UPDATE SIGNANTE set (FOTO) VALUES (?) where ID=" + id_s + " ;";
        const char * photo_char = photo_sql.c_str();

        sqlite3_prepare_v2(db, photo_char, -1, &stmtInsert, nullptr);
        sqlite3_bind_blob(stmtInsert, 1, blobData->Data, blobData->Length, SQLITE_STATIC);

If I try to INSERT instead of UPDATE (without the "where ID="+id_s+";") everything works fine but if I update it, I get an error message on the next line:

if(sqlite3_step(stmtInsert)==SQLITE_DONE){
  TextOut->Text = "it worked";
  }

I get a "access violation" inside "wstring" class.

My question is, how can I UPDATE a SQLite with a BLOB entry for a given ID (or any other primary key).


解决方案

Hi Carlos Her,

Well, please first make sure the SQL command is correctly. Have you tried to run the SQL command outside the UWP app to see if you could updated the database successfully?

Best regards,

Roy


这篇关于[C ++] [SQLite]如何使用给定条件更新SQLite Blob列(其中ID = X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆