In fact, is a compilation process, so easy, just online methods of various, and not the latest, so I figured out.
1. Download sqlite-amalgamation-xxx and sqlite-dll-win32-x86-xxx from SQLite website
2. Download wxsqlite3-xxx from GitHub
3. Use VS to create Win32 DLL Empty project
4. Copy all H, c files and def files under Wxsqlite3-3.3.0\sqlite3\secure\src\
5, add sqlite3secure.c, sqlite3.h to the project
6. Set preprocessing definition: Sqlite_has_codec codec_type=codec_type_aes128 sqlite_core sqlite_secure_delete SQLITE_ENABLE_COLUMN_ METADATA Sqlite_enable_rtree
Compiling a static library requires multiple additions: use_dynamic_sqlite3_load=0
7, compile the dynamic library: In the configuration Properties---linker--and input-to-module definition files to join Sqlite3.def 8, using the introduction of Sqlite3.h and SQLITE3USERAUTH.H sample code to participate in the compilation project
If you need to use the latest sqlite3, replace the project file with the H and C files in Sqlite-amalgamation-xxx.
The new version of Ps:sqlite3 may be incompatible with wxsqlite3, it is recommended to use the Wxsqlite3, and its update is also very fast.
The sample code is as follows
1#include"include\sqlite3.h"2#include"include\sqlite3userauth.h"3 4 /*Sqlite3 Encryption Example*/5 /*The database Sqlite3_open is opened first, and then the database operation is performed before the database is executed Sqlite3_key, otherwise an error is returned. 6 Sqlite3_key is the input key, if the database is encrypted you must first execute this function and enter the correct key to operate.7 If the database is not encrypted, the database operation after executing this function will instead appear "This database is encrypted or not a database file" error. 8 Sqlite3_rekey is a change key or an encryption key or an empty key for a database that is not encrypted.9 The Sqlite3_key must be executed correctly before changing the key or emptying the key. Ten The database can be operated properly before Sqlite3_close shuts down the database after the Sqlite3_rekey is executed correctly, without the need to execute sqlite3_key. */ One A Sqlite3_config (sqlite_config_singlethread); -sqlite3* db =nullptr; - if(Sqlite_ok = = SQLITE3_OPEN_V2 (".. /TEST.DB3", &db, Sqlite_open_exclusive |Sqlite_open_readwrite, nullptr)) the { - /*Encrypt - if (sqlite_ok! = Sqlite3_rekey (Psqlite3, "qazwsx!123", ten)) - { + std::string serr = "SQLite encrypt error:"; - Serr + = sqlite3_errmsg (psqlite3); + }*/ A at /*Decrypt*/ -Sqlite3_key (DB,"qazwsx!123",Ten); - - /*Query*/ -STD::stringSQLSTR ("Select comment from country where codevalue=1"); -sqlite3_stmt*pstmt; in if(Sqlite_ok = = SQLITE3_PREPARE_V2 (db, Sqlstr.c_str (), Sqlstr.length (), &pstmt, nullptr)) - { to if(Sqlite_row = =Sqlite3_step (pstmt)) + { -STD::stringStext = (Char*) Sqlite3_column_text (pstmt,0); the } * Else $ {Panax NotoginsengSTD::stringSerr ="SQLite Step Error:"; -Serr + =sqlite3_errmsg (db); the } + } A Else the { +STD::stringSerr ="SQLite Prepare error:"; -Serr + =sqlite3_errmsg (db); $ } $ sqlite3_finalize (pstmt); - } - Else the { -STD::stringSerr ="SQLite Open Error:";WuyiSerr + =sqlite3_errmsg (db); the } -Sqlite3_close (DB);
Wxsqlite3 encryption module is compiled separately