summaryrefslogtreecommitdiffstats
path: root/src/org/madore/android/unicodeMap/UnicodeDatabase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/madore/android/unicodeMap/UnicodeDatabase.java')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeDatabase.java39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeDatabase.java b/src/org/madore/android/unicodeMap/UnicodeDatabase.java
index c40cf67..b81c99a 100644
--- a/src/org/madore/android/unicodeMap/UnicodeDatabase.java
+++ b/src/org/madore/android/unicodeMap/UnicodeDatabase.java
@@ -25,7 +25,9 @@ public class UnicodeDatabase {
protected static final int DATABASE_VERSION = 1;
protected static final String UNICODE_TABLE_NAME = "unicode";
- protected static class DatabaseInit extends SQLiteOpenHelper {
+ protected boolean needPopulate;
+
+ protected class DatabaseInit extends SQLiteOpenHelper {
final Context context;
@@ -40,6 +42,7 @@ public class UnicodeDatabase {
+"id INTEGER PRIMARY KEY , "
+"name TEXT , "
+"category TEXT )");
+ UnicodeDatabase.this.needPopulate = true;
}
@Override
@@ -59,10 +62,22 @@ public class UnicodeDatabase {
this.activity = activity;
this.dbinit = new DatabaseInit(activity);
db = dbinit.getReadableDatabase();
+ if ( ! this.needPopulate ) {
+ Cursor c = db.rawQuery("SELECT count(*) FROM "+UNICODE_TABLE_NAME, null);
+ c.moveToFirst();
+ int lineCnt = c.getInt(0);
+ c.close();
+ if ( lineCnt == 0 )
+ this.needPopulate = true;
+ }
}
- protected void reportProgress(Handler progressHandler,
- int done, int total) {
+ public boolean needPopulate() {
+ return this.needPopulate;
+ }
+
+ protected static void reportProgress(Handler progressHandler,
+ int done, int total) {
Message msg = progressHandler.obtainMessage();
Bundle b = new Bundle();
b.putInt("done", done);
@@ -113,6 +128,8 @@ public class UnicodeDatabase {
}
rd.close();
}
+ db.setTransactionSuccessful();
+ this.needPopulate = false;
} catch (UnsupportedEncodingException e) {
throw new AssertionError("US-ASCII encoding unsupported");
} catch (IOException e) {
@@ -144,15 +161,12 @@ public class UnicodeDatabase {
return ch;
}
- protected final static String[] countColumns = { "count(*)" };
-
public int countRange(int from, int to) {
final Cursor c
- = db.query(UNICODE_TABLE_NAME, countColumns,
- "id >= ? AND id < ?",
- new String[] { Integer.toString(from),
- Integer.toString(to) },
- null, null, null, null);
+ = db.rawQuery("SELECT count(*) FROM "+UNICODE_TABLE_NAME
+ +" WHERE id >= ? AND id < ?",
+ new String[] { Integer.toString(from),
+ Integer.toString(to) });
if ( c.getCount() != 1 )
throw new AssertionError("\"SELECT count(*)\" returned no result");
c.moveToFirst();
@@ -207,4 +221,9 @@ public class UnicodeDatabase {
return new CursorIterable(c);
}
+ public void close() {
+ db.close();
+ db = null;
+ }
+
}