MCPcopy Create free account
hub / github.com/SqliteModernCpp/sqlite_modern_cpp / main

Function main

tests/sqlcipher.cc:21–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19};
20
21int main()
22{
23 try
24 {
25 TmpFile file;
26 sqlcipher_config config;
27 {
28 config.key = "DebugKey";
29 sqlcipher_database db(file.fname, config);
30
31 db << "CREATE TABLE foo (a integer, b string);";
32 db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello";
33 db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world";
34
35 string str;
36 db << "SELECT b from FOO where a=?;" << 2 >> str;
37
38 if(str != "world")
39 {
40 cout << "Bad result on line " << __LINE__ << endl;
41 exit(EXIT_FAILURE);
42 }
43 }
44 try {
45 config.key = "DebugKey2";
46 sqlcipher_database db(file.fname, config);
47 db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
48
49 cout << "Can open with wrong key";
50 exit(EXIT_FAILURE);
51 } catch(errors::notadb) {
52 // Expected, wrong key
53 }
54 {
55 config.key = "DebugKey";
56 sqlcipher_database db(file.fname, config);
57 db.rekey("DebugKey2");
58 }
59 {
60 config.key = "DebugKey2";
61 sqlcipher_database db(file.fname, config);
62 db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
63 }
64 }
65 catch(sqlite_exception e)
66 {
67 cout << "Unexpected error " << e.what() << endl;
68 exit(EXIT_FAILURE);
69 }
70 catch(...)
71 {
72 cout << "Unknown error\n";
73 exit(EXIT_FAILURE);
74 }
75
76 cout << "OK\n";
77 exit(EXIT_SUCCESS);
78}

Callers

nothing calls this directly

Calls 1

rekeyMethod · 0.80

Tested by

no test coverage detected