问题描述
我使用CppSQLite3作为sqlite3的包装器,因为它允许传递UNICODE字符串,因为它通常支持UNICODE。
是否有一个CppSQLite3函数类似于允许传递回调函数的sqlite3_exec()?
sqlite3_exe声明如下:
I am using CppSQLite3 as a wrapper of sqlite3 because it allows passing UNICODE strings and because it supports UNICODE in general.
Is there an CppSQLite3 function which is similar to sqlite3_exec() in the sense of allowing passing a callback function?
sqlite3_exe is declared as follow:
SQLITE_API int sqlite3_exec(
sqlite3*, /* An open database */
const char *sql, /* SQL to be evaluated */
int(*callback)(void*, int, char**, char**), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
CppSQLite3的execQuery()声明如下:
CppSQLite3's execQuery() is declared as follow:
CppSQLite3Query execQuery(LPCTSTR szSQL);
我尝试过:
我试过寻找这样的包装函数来接受
What I have tried:
I have tried looking for such wrapper function that will accept
wchar_t *
而不是
instead of
char *
但找不到任何...
推荐答案
SQLITE_API int sqlite3_execW(
sqlite3*, /* An open database */
const wchar_t *sql, /* SQL to be evaluated */
int(*callback)(void*, int, wchar_t**, wchar_t**), /* Callback function */
void *, /* 1st argument to callback */
wchar_t **errmsg /* Error msg written here */
);
此代码将(a)将任何参数从Unicode转换为(例如)UTF-8,并调用 char 版本。如果提供了Unicode回调函数,它可以以类似的方式包装 - 提供一个回调函数,该函数接受 char 参数,将它们转换为Unicode,并调用Unicode回调函数。
如果您的代码在Windows下运行,MultibyteToWideChar()和WideCharToMultiByte()API将为您进行转换。
This code would (a) convert any parameters from Unicode to (for example) UTF-8, and call the char version. If a Unicode callback function is provided, it can be wrapped in a similar manner - provide a callback function that accepts char parameters which converts them to Unicode, and calls the Unicode callback function.
If your code runs under Windows, the MultibyteToWideChar() and WideCharToMultiByte() APIs will do the conversion for you.
这篇关于什么是cppsqlite3中的sqlite3的sqlite3_exec(如果有的话)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!