1. The requirement program to achieve the product offline data download, it uses the Java side directly splicing SQL files, the client download SQL files, merged into the local database. Performance also line LAN more than 10 seconds more than 7 trillion, but there is a sqlite or SQL file saved in the Chinese path can not be merged with the problem 2. The main reason is that when SQLite opens the database with UTF8 open, QT generally uses Unicode encoding. There are many methods on the Internet, here we adopt another method to solve the problem of avoiding Chinese path by relative path 3. Code Snippet 1. Create a database
"/db"); dir(""); dir.mkpath(strdbpath); "/mysqlite.db"; QSqlDatabase dbset = QSqlDatabase::addDatabase("QSQLITE""file"); dbset.setDatabaseName(strdbpath); if (!dbset.open()) { LOG_ALL_ERROR(QStringLiteral("failed open mysqlite.db")); return bret; }
2. Merging SQL files to the local database
std::string strstdcmd("sqlite3.exe ./db/mysqlite.db \".read ./db/mysqlite.sql\""); process; process.start(strstdcmd.c_str()); process.waitForFinished(); String"/db/mysqlite.sql"); QFile::remove(strsqlpath);
3. Download the SQL file section slightly with Libcurl it is easy and quick to download the file 4. Note 1. Code in Win7+vs2010+qt5.40+libcurl 7.36.0 compiled by 2. Compile or direct download Sqlite3.exe in the generated directory and the source directory is stored in a copy of 3. Common sense Currentpath at compile time refers to the source directory, directly run EXE refers to the directory of EXE
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Sqlite3 implementation of Chinese path SQL file import alternative solution