有没有一种方法可以使用C++?
我正在尝试将Wstrings存储在Sqlite中。 SQLite是否支持Wstrings的存储? 以下是代码片段
Person Table created using
CREATE TABLE Persons ( PersonID int, LastName varchar(255),FirstName varchar(255));
int callback(void* NotUsed, int argc, char** argv, char** azColName) {
int i;
for (i = 0; i < argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main()
{
std::wstring firstName = L"Hello3ф";
std::wstring lastName = L"World45£";
sqlite3_stmt* stmt;
int val = sqlite3_prepare16_v2(db, u"INSERT INTO Persons (PersonID,LastName,FirstName)
VALUES (4, ?, ?)", -1, &stmt, nullptr);
if (val != SQLITE_OK) {
fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
return 133;
}
sqlite3_bind_text16(stmt, 1, lastName.c_str(), -1, SQLITE_STATIC);
sqlite3_bind_text16(stmt, 2, firstName.c_str(), -1, SQLITE_STATIC);
val = sqlite3_step(stmt);
if (val != SQLITE_DONE) {
fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
return 134;
}
sqlite3_finalize(stmt);
//To read the records
std::string query = "select * from Persons";
sqlite3_exec(db, query.c_str(), callback, NULL, &zErrMsg);
}
输出。回调仅接受char **而不是wchar_t **。有人可以建议我如何安全地存储这些价值吗?
PersonID = 4
LastName = World45£
FirstName = Hello3ф
I am trying to store wstrings in sqlite. Does sqlite support the storage of wstrings?
Below is code snippet
Person Table created using
CREATE TABLE Persons ( PersonID int, LastName varchar(255),FirstName varchar(255));
int callback(void* NotUsed, int argc, char** argv, char** azColName) {
int i;
for (i = 0; i < argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main()
{
std::wstring firstName = L"Hello3ф";
std::wstring lastName = L"World45£";
sqlite3_stmt* stmt;
int val = sqlite3_prepare16_v2(db, u"INSERT INTO Persons (PersonID,LastName,FirstName)
VALUES (4, ?, ?)", -1, &stmt, nullptr);
if (val != SQLITE_OK) {
fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
return 133;
}
sqlite3_bind_text16(stmt, 1, lastName.c_str(), -1, SQLITE_STATIC);
sqlite3_bind_text16(stmt, 2, firstName.c_str(), -1, SQLITE_STATIC);
val = sqlite3_step(stmt);
if (val != SQLITE_DONE) {
fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
return 134;
}
sqlite3_finalize(stmt);
//To read the records
std::string query = "select * from Persons";
sqlite3_exec(db, query.c_str(), callback, NULL, &zErrMsg);
}
Output as below. callback is accepting only char** instead of wchar_t**. Can someone please suggest how I can safely store these values ?
PersonID = 4
LastName = World45£
FirstName = Hello3ф
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论