sqlite数据库加密wxsqlite3 运行时间错误
Sqlite database encryption with wxsqlite3 run time error
我从 here(wxSQLite3 3.5.9) 下载了预构建的二进制文件,我还下载了 sqlite3.h
文件版本 3.21.0,我添加了头文件和 .dll
和.lib
文件到我的项目。
我复制了 32 位版本的 dll 和 lib 文件,并将它们复制到我的解决方案中,并将 .lib
文件添加到项目属性中 Linker->Input
中的 Additional Dependencies
。
我用 C++ 创建了这个示例应用程序:
#define SQLITE_HAS_CODEC
#include "sqlite3.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
sqlite3* db;
sqlite3_open("test1.db", &db);
sqlite3_key(
db, /* Database to be rekeyed */
"test", sizeof("test") /* The key, and the length of the key in bytes */
);
std::string createQuery =
"CREATE TABLE IF NOT EXISTS items (userid INTEGER PRIMARY KEY, ipaddr TEXT, username TEXT, useradd TEXT, userphone INTEGER, age INTEGER, "
"time TEXT NOT NULL DEFAULT (NOW()));";
sqlite3_stmt* createStmt;
std::cout << "Creating Table Statement" << endl;
sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
cout << "Stepping Table Statement" << endl;
if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;
string insertQuery =
"INSERT INTO items (time, ipaddr,username,useradd,userphone,age) VALUES('7:30', '192.187.27.55', 'vivekanand', 'kolkatta', '04456823948', 74);";
// WORKS!
sqlite3_stmt* insertStmt;
cout << "Creating Insert Statement" << endl;
sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
cout << "Stepping Insert Statement" << endl;
if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;
return 0;
}
当我 运行 这个程序时,我在 运行 时得到这个错误:
但是如果我注释掉这段代码
sqlite3_key(
db, /* Database to be rekeyed */
"test", sizeof("test") /* The key, and the length of the key in bytes */
);
它工作得很好,我做错了什么?
C/C++代码似乎没问题。如果可以正确编译测试应用程序,则显然使用了有效的 link 库。但是,运行时错误消息表明未加载正确的 DLL。
这表明 pre-compiled SQLite DLL 未复制到测试应用程序的可执行文件所在的同一目录中,或者它不在应用程序的搜索路径中。但是,在搜索路径中发现了一些 SQLite DLL,但很可能是不包含加密扩展的 "official" SQLite DLL。
确保测试应用程序可以访问包含加密扩展的 SQLite DLL。
wxSQLite3 版本的 pre-compiled 二进制文件肯定包含入口点 sqlite3_key 和 sqlite3_rekey.
我从 here(wxSQLite3 3.5.9) 下载了预构建的二进制文件,我还下载了 sqlite3.h
文件版本 3.21.0,我添加了头文件和 .dll
和.lib
文件到我的项目。
我复制了 32 位版本的 dll 和 lib 文件,并将它们复制到我的解决方案中,并将 .lib
文件添加到项目属性中 Linker->Input
中的 Additional Dependencies
。
我用 C++ 创建了这个示例应用程序:
#define SQLITE_HAS_CODEC
#include "sqlite3.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
sqlite3* db;
sqlite3_open("test1.db", &db);
sqlite3_key(
db, /* Database to be rekeyed */
"test", sizeof("test") /* The key, and the length of the key in bytes */
);
std::string createQuery =
"CREATE TABLE IF NOT EXISTS items (userid INTEGER PRIMARY KEY, ipaddr TEXT, username TEXT, useradd TEXT, userphone INTEGER, age INTEGER, "
"time TEXT NOT NULL DEFAULT (NOW()));";
sqlite3_stmt* createStmt;
std::cout << "Creating Table Statement" << endl;
sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
cout << "Stepping Table Statement" << endl;
if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;
string insertQuery =
"INSERT INTO items (time, ipaddr,username,useradd,userphone,age) VALUES('7:30', '192.187.27.55', 'vivekanand', 'kolkatta', '04456823948', 74);";
// WORKS!
sqlite3_stmt* insertStmt;
cout << "Creating Insert Statement" << endl;
sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
cout << "Stepping Insert Statement" << endl;
if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;
return 0;
}
当我 运行 这个程序时,我在 运行 时得到这个错误:
但是如果我注释掉这段代码
sqlite3_key(
db, /* Database to be rekeyed */
"test", sizeof("test") /* The key, and the length of the key in bytes */
);
它工作得很好,我做错了什么?
C/C++代码似乎没问题。如果可以正确编译测试应用程序,则显然使用了有效的 link 库。但是,运行时错误消息表明未加载正确的 DLL。
这表明 pre-compiled SQLite DLL 未复制到测试应用程序的可执行文件所在的同一目录中,或者它不在应用程序的搜索路径中。但是,在搜索路径中发现了一些 SQLite DLL,但很可能是不包含加密扩展的 "official" SQLite DLL。
确保测试应用程序可以访问包含加密扩展的 SQLite DLL。
wxSQLite3 版本的 pre-compiled 二进制文件肯定包含入口点 sqlite3_key 和 sqlite3_rekey.