@@ -20,12 +20,14 @@ import com.zoffcc.applications.sorm.Log;
2020public class OrmaDatabase
2121{
2222 private static final String TAG = "sorm.OrmaDatabase";
23- public static final String OrmaDatabaseVersion = "1.0.2 ";
23+ public static final String OrmaDatabaseVersion = "1.0.3 ";
2424
2525 final static boolean ORMA_TRACE = false; // set "false" for release builds
2626 final static boolean ORMA_LONG_RUNNING_TRACE = false; // set "false" for release builds
2727 final static long ORMA_LONG_RUNNING_MS = 180;
2828
29+ private static final String SQLCIPHER_NOT_USED = "sqlcipher not in use";
30+
2931 public static Connection sqldb = null;
3032 static int THIS_DB_SCHEMA_VERSION = 1; // HINT: this is the version the database schema should be upgraded to
3133 static int current_db_schema_version = 0; // HINT: this is current database schema version,
@@ -53,6 +55,19 @@ public class OrmaDatabase
5355 private static String secrect_key = null;
5456 private static boolean wal_mode = false; // default mode is WAL off!
5557
58+ public static enum SQLITE_TYPE {
59+ UNLOADED(0),
60+ SQLITE(1),
61+ SQLCIPHER(2);
62+
63+ public final int type;
64+
65+ private SQLITE_TYPE(int type) {
66+ this.type = type;
67+ }
68+ }
69+ private static boolean is_shutdown = true;
70+
5671 public static String getVersion()
5772 {
5873 return OrmaDatabase.OrmaDatabaseVersion;
@@ -274,6 +289,24 @@ public class OrmaDatabase
274289 return results;
275290 }
276291
292+ public static SQLITE_TYPE get_sqlite_type()
293+ {
294+ if (is_shutdown)
295+ {
296+ return SQLITE_TYPE.UNLOADED;
297+ }
298+
299+ final String sqlcipher_version_used = get_current_sqlcipher_version();
300+ if (sqlcipher_version_used.equals(SQLCIPHER_NOT_USED))
301+ {
302+ return SQLITE_TYPE.SQLITE;
303+ }
304+ else
305+ {
306+ return SQLITE_TYPE.SQLCIPHER;
307+ }
308+ }
309+
277310 public static String get_current_sqlite_version()
278311 {
279312 String ret = "unknown";
@@ -320,6 +353,53 @@ public class OrmaDatabase
320353 return ret;
321354 }
322355
356+ public static String get_current_sqlcipher_version()
357+ {
358+ String ret = SQLCIPHER_NOT_USED;
359+
360+ orma_global_sqlfreehand_lock.lock();
361+ Statement statement = null;
362+ try
363+ {
364+ statement = sqldb.createStatement();
365+ final ResultSet rs = statement.executeQuery("PRAGMA cipher_version");
366+ if (rs.next())
367+ {
368+ ret = rs.getString(1);
369+ }
370+ try
371+ {
372+ rs.close();
373+ }
374+ catch (Exception e)
375+ {
376+ Log.i(TAG, "ERR:CSQCV:001:" + e.getMessage());
377+ e.printStackTrace();
378+ }
379+ return ret;
380+ }
381+ catch (Exception e)
382+ {
383+ // HINT: if sqlcipher is not used we would get this error. so do not show it
384+ // Log.i(TAG, "ERR:CSQCV:002:" + e.getMessage());
385+ // e.printStackTrace();
386+ }
387+ finally
388+ {
389+ try
390+ {
391+ statement.close();
392+ }
393+ catch (Exception e)
394+ {
395+ e.printStackTrace();
396+ }
397+ orma_global_sqlfreehand_lock.unlock();
398+ }
399+
400+ return ret;
401+ }
402+
323403 public static int get_current_db_version()
324404 {
325405 int ret = 0;
@@ -543,6 +623,7 @@ public class OrmaDatabase
543623 Log.i(TAG, "ERR:SHUTDOWN:001:" + e2.getMessage());
544624 e2.printStackTrace();
545625 }
626+ is_shutdown = true;
546627 Log.i(TAG, "SHUTDOWN:finished");
547628 }
548629
@@ -570,9 +651,13 @@ public class OrmaDatabase
570651 throw new RuntimeException(e);
571652 }
572653
654+ Log.i(TAG, "loaded:sqlite_type:1:" + get_sqlite_type());
655+
573656 // HINT: check if the database can be opened (e.g. the password for an sqlcipher db is correct), if not throw RuntimeException
574657 check_db_open();
575658
659+ is_shutdown = false;
660+
576661 if (OrmaDatabase.wal_mode)
577662 {
578663 Log.i(TAG, "INIT:journal_mode=" + run_query_for_single_result("PRAGMA journal_mode;"));
@@ -608,7 +693,9 @@ public class OrmaDatabase
608693 Log.i(TAG, "INIT:turning OFF WAL mode");
609694 }
610695
696+ Log.i(TAG, "loaded:sqlite_type:2:" + get_sqlite_type());
611697 Log.i(TAG, "loaded:sqlite:" + get_current_sqlite_version());
698+ Log.i(TAG, "loaded:sqlcipher:" + get_current_sqlcipher_version());
612699
613700 // --------------- CREATE THE DATABASE ---------------
614701 // --------------- CREATE THE DATABASE ---------------
0 commit comments