2 public import static "ecere"
3 public import static "EDA"
13 static class SQLiteCipherDataSource : SQLiteDataSource
15 class_property(name) = "SQLiteCipher";
17 String MakeDatabasePath(const String name)
21 char build[MAX_LOCATION];
22 strcpy(build, path ? path : "");
24 ChangeExtension(build, "sqlcipher", build);
25 return CopyString(build);
30 Database OpenDatabase(const String name, CreateOptions createOptions, DataSource ds)
32 Database result = null;
35 String path = MakeDatabasePath(name);
38 // sqlite3_open(path, &db);
39 // sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY /*SQLITE_OPEN_READWRITE*/ /*SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE*/, null );
41 if(sqlite3_open_v2(path, &db, (createOptions == readOnly) ? SQLITE_OPEN_READONLY :
42 (SQLITE_OPEN_READWRITE | ((createOptions == create) ? SQLITE_OPEN_CREATE : 0)), null))
43 // fprintf(stderr, "%s\n", s); // interesting
44 printf($"Can't open database (%s): %s\n", path, sqlite3_errmsg(db));
47 int rc = SQLITE_ERROR;
49 if(ds.pass && ds.pass[0])
51 sprintf(command, "PRAGMA key = '%s';", ds.pass);
52 sqlite3_exec(db, command, null, null, null);
53 rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", null, null, null);
54 if(rc == SQLITE_NOTADB)
56 printf($"EDASQLiteCipher: database (%s) format not recognized, disabling cipher_use_hmac to support version 1.1.x databases\n", path);
57 strcpy(command, "PRAGMA cipher_use_hmac = OFF;");
58 sqlite3_exec(db, command, null, null, null);
59 rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", null, null, null);
63 sprintf(command, "CREATE TABLE eda_table_fields(Table_Name TEXT, Name TEXT, Type TEXT, Length INT);");
64 sqlite3_exec(db, command, null, null, null);
65 result = SQLiteDatabase { db = db };
68 printf($"Can't open database (%s): %s -- password may be incorrect\n", path, sqlite3_errstr(rc));