Zhu Jinchan
Source: http://blog.csdn.net/clever101
The Sqlite3_open function is required to open a SQLite database, but the first parameter of the Sqlite3_open function is the absolute path to the database file.
It is fastidious and must be a UTF8 string. That is, if the file path is a non-UTF8 character, it is converted to UTF characters. So take the information on the Internet. Wrote one of the most frequently used functions from multibyte to UTF8, code such as the following:
Compilation environment: VS 2008+sp1,win7, Project is set to multibyte character set std::string MbcsToUtf8 (const char* PSZMBCS) {std::string str; WCHAR *pwchar=0; CHAR *pchar=0;int Len=0;int codepage = Arefileapisansi ()?Cp_acp:cp_oemcp;len=multibytetowidechar (codepage, 0, Pszmbcs,-1, null,0);p wchar=new wchar[len];if (pwchar!=0) {len = MultiByteToWideChar (codepage, 0, Pszmbcs,-1, Pwchar, Len); if (len!=0) {len = WideCharToMultiByte (Cp_utf8, 0, Pwchar,-1, 0, 0, 0, 0);p char=new char[len];if (pchar!=0) {len = WideCharToMultiByte (Cp_utf8, 0, Pwchar,-1, Pchar, len,0, 0); if (len!=0) {str = pchar; } Delete Pchar;} Delete Pwchar;}} return str;}
Test code such as the following:
Build environment: VS 2008+sp1,win7, Project set to multibyte character Set # include <sqlite3.h> #include <string>int main (void) {sqlite3* db = 0;char* pszerrmsg = null;//Connection Database std::string strimgindexfilename = "C:\\test.db" std::string strUtf8File = MbcsToUt F8 (Strimgindexfilename.c_str ()); int ret = Sqlite3_open (Strutf8file.c_str (), &db); if (ret! = SQLITE_OK) {fprintf ( stderr, "Unable to open database:%s", sqlite3_errmsg (db)); return 1;} return 0;}
References:
1. Sqlite3 Problem 2: Chinese path support
The use of the Sqlite3_open function of SQLite learning notes