Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite3:非ascii unicode字符';更新不起作用?_C_Sqlite - Fatal编程技术网

SQLite3:非ascii unicode字符';更新不起作用?

SQLite3:非ascii unicode字符';更新不起作用?,c,sqlite,C,Sqlite,我在win32下使用SQLite3,在我的C程序上使用SQLite3更新WVARCHAR列时,我总是将非ascii字符转换为悬空字符,下面是一个我的代码示例,不幸的是没有正确更新非ascii字符,如“é”: #include <stdio.h> #include <sqlite3.h> int main(){ sqlite3_stmt *stmt; sqlite3 *sqdb; sqlite3_initial

我在win32下使用SQLite3,在我的C程序上使用SQLite3更新WVARCHAR列时,我总是将非ascii字符转换为悬空字符,下面是一个我的代码示例,不幸的是没有正确更新非ascii字符,如“é”:

    #include <stdio.h>
    #include <sqlite3.h>

    int main(){
      sqlite3_stmt *stmt;
      sqlite3 *sqdb;

      sqlite3_initialize();
      sqlite3_open("sqlite_unicode_test", &sqdb);
       const char* table_check = {
      "CREATE TABLE IF NOT EXISTS mytable("
       "id INTEGER PRIMARY KEY AUTOINCREMENT,"
       "mycolumn1 WVARCHAR,"
       "mycolumn2 WVARCHAR"
       ");"
       };
      sqlite3_prepare_v2(sqdb, table_check, -1, &stmt, 0);
      sqlite3_step(stmt);
      sqlite3_finalize(stmt);
      sqlite3_prepare16(sqdb, L"UPDATE mytable SET mycolumn1=? mycolumn2=? WHERE(id=0)", -1, &stmt, 0);
      sqlite3_bind_text16(stmt, 1, L"e", -1, SQLITE_STATIC); //e is stored correctly on the database
      sqlite3_bind_text16(stmt, 2, L"é", -1, SQLITE_STATIC); //however é not stored correctly: modified by a dangled character
      sqlite3_step(stmt);
      sqlite3_finalize(stmt);
      sqlite3_close(sqdb);
    }
#包括
#包括
int main(){
sqlite3_stmt*stmt;
sqlite3*sqdb;
sqlite3_初始化();
sqlite3_open(“sqlite_unicode_测试”&sqdb);
常量字符*表检查={
“如果不存在,则创建表mytable(”
id整数主键自动递增
“mycolumn1 WVARCHAR,”
“mycolumn2 WVARCHAR”
");"
};
sqlite3_prepare_v2(sqdb,表检查,-1,&stmt,0);
sqlite3_步骤(stmt);
sqlite3_最终确定(stmt);
sqlite3_prepare16(sqdb,L“更新mytable集mycolumn1=?mycolumn2=?其中(id=0)”,-1,&stmt,0);
sqlite3_bind_text16(stmt,1,L“e”,-1,SQLITE_STATIC);//e正确存储在数据库中
sqlite3_bind_text16(stmt,2,L“é”,-1,SQLITE_STATIC);//但是未正确存储:由悬挂字符修改
sqlite3_步骤(stmt);
sqlite3_最终确定(stmt);
sqlite3_关闭(sqdb);
}
我不知道为什么会发生这种情况,我在之前发布了一个问题 ()但我认为这与sqlite3 win32二进制文件无关,因为我测试了 我自己使用gcc构建SQLite,总是会遇到同样的问题。
那么SQLite unicode有什么问题?我怎样才能准确地解决这个问题呢?我需要帮助。

我想你必须做两件事:

创建数据库时,必须指定utf-16(我认为utf-8是默认值)

此外,在绑定字符之前,必须将重音字符转换为UTF-16,并且不能传递UNICODE字符串


有关更多信息,请参阅和。

+1将此简化为一个简单的案例,您是否可以显示您的连接声明…@ojblass您所说的“您是否可以显示您的连接声明”是什么意思?你是说shell的截图吗?显然,在你准备一个声明之前,你必须用一些选项打开一个db连接…@ojblass我更新了上面的代码。非常感谢,这确实帮助我解决了这个问题!再次感谢。