Skip to content

Commit 53e62ad

Browse files
committed
将底层sqlite3替换为sqlite3mc加密数据库并提供setPassworld接口,windows 测试无误
1 parent ed76abe commit 53e62ad

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ Debug
2929
Release
3030
TestResults
3131

32+
build/
33+
out/
34+
.vs/

sqlitelib.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef _CPPSQLITELIB_HTTPSLIB_H_
99
#define _CPPSQLITELIB_HTTPSLIB_H_
1010

11-
#include <sqlite3.h>
11+
#include <sqlite3mc.h>
1212

1313
#include <cstring>
1414
#include <memory>
@@ -284,6 +284,18 @@ class Sqlite {
284284
}
285285
}
286286

287+
void setPassworld(const std::string& passworld) const {
288+
int rc = sqlite3_key(db_, passworld.c_str(), static_cast<int>(passworld.size()));
289+
if (rc != SQLITE_OK) {
290+
throw std::runtime_error("设置密码错误");
291+
}
292+
293+
rc = sqlite3_exec(db_, "SELECT count(*) FROM sqlite_master;", nullptr, nullptr, nullptr);
294+
if (rc != SQLITE_OK) {
295+
throw std::runtime_error("密码验证错误");
296+
}
297+
}
298+
287299
Sqlite(Sqlite&& rhs) : db_(rhs.db_) {}
288300

289301
~Sqlite() {

test/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(test)
33

4-
add_executable(test-main test.cc sqlite3.c)
4+
set(SQLite3MC_DIR "D:/App/sqlite3mc-2.1.1-sqlite-3.49.2-icu-win64")
55

6+
add_executable(test-main test.cc)
7+
include_directories(${SQLite3MC_DIR}/include)
8+
9+
target_link_libraries(test-main PRIVATE
10+
${SQLite3MC_DIR}/dll/sqlite3mc_icu_x64.lib
11+
)
612
target_include_directories(test-main PRIVATE .. .)
713

814
enable_testing()

test/test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using namespace sqlitelib;
99
TEST_CASE("Sqlite Test", "[general]") {
1010
Sqlite db("./test.db");
1111
REQUIRE(db.is_open());
12+
db.setPassworld("123555");
1213

1314
db.prepare(R"(
1415
CREATE TABLE IF NOT EXISTS people (

0 commit comments

Comments
 (0)