2 public import static "ecere"
3 public import static "EDA"
13 static class SQLiteCipherDataSource : SQLiteDataSource
15 class_property(name) = "SQLiteCipher";
16 class_property(databaseFileExtension) = "sqlcipher";
18 Database OpenDatabase(const String name, CreateOptions createOptions, DataSource ds)
20 Database result = null;
23 String path = MakeDatabasePath(name);
26 // sqlite3_open(path, &db);
27 // sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY /*SQLITE_OPEN_READWRITE*/ /*SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE*/, null );
29 if(sqlite3_open_v2(path, &db, (createOptions == readOnly) ? SQLITE_OPEN_READONLY :
30 (SQLITE_OPEN_READWRITE | ((createOptions == create) ? SQLITE_OPEN_CREATE : 0)), null))
31 // fprintf(stderr, "%s\n", s); // interesting
32 printf($"Can't open database (%s): %s\n", path, sqlite3_errmsg(db));
35 int rc = SQLITE_ERROR;
37 if(ds.pass && ds.pass[0])
39 sprintf(command, "PRAGMA key = '%s';", ds.pass);
40 sqlite3_exec(db, command, null, null, null);
41 rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", null, null, null);
42 if(rc == SQLITE_NOTADB)
44 printf($"EDASQLiteCipher: database (%s) format not recognized, disabling cipher_use_hmac to support version 1.1.x databases\n", path);
45 strcpy(command, "PRAGMA cipher_use_hmac = OFF;");
46 sqlite3_exec(db, command, null, null, null);
47 rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", null, null, null);
51 sprintf(command, "CREATE TABLE eda_table_fields(Table_Name TEXT, Name TEXT, Type TEXT, Length INT);");
52 sqlite3_exec(db, command, null, null, null);
53 result = SQLiteDatabase { db = db };
56 printf($"Can't open database (%s): %s -- password may be incorrect\n", path, sqlite3_errstr(rc));