From 268209383a86fc3120db26089b7e9c2dfc8b6992 Mon Sep 17 00:00:00 2001 From: Peng Sun Date: Wed, 16 May 2018 19:08:46 +0800 Subject: [PATCH 1/2] Make the lib behave like the document said In doc db tables is create and migrate by execute the sql scripts in assets directory. In fact the db table is create by the utilize the info of annotated model class. SQLiteOpenHelper will set db version after execute the onCreate, this will case the onCreate got the wrong db version, and some migration sql script will never be executed. Signed-off-by: Peng Sun --- src/com/activeandroid/DatabaseHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/activeandroid/DatabaseHelper.java b/src/com/activeandroid/DatabaseHelper.java index 7158c5bb6..9d28000a7 100644 --- a/src/com/activeandroid/DatabaseHelper.java +++ b/src/com/activeandroid/DatabaseHelper.java @@ -49,6 +49,7 @@ public final class DatabaseHelper extends SQLiteOpenHelper { // PRIVATE FIELDS ////////////////////////////////////////////////////////////////////////////////////// + private Configuration mConfiguration; private final String mSqlParser; ////////////////////////////////////////////////////////////////////////////////////// @@ -59,6 +60,7 @@ public DatabaseHelper(Configuration configuration) { super(configuration.getContext(), configuration.getDatabaseName(), null, configuration.getDatabaseVersion()); copyAttachedDatabase(configuration.getContext(), configuration.getDatabaseName()); mSqlParser = configuration.getSqlParser(); + mConfiguration = configuration; } ////////////////////////////////////////////////////////////////////////////////////// @@ -73,15 +75,13 @@ public void onOpen(SQLiteDatabase db) { @Override public void onCreate(SQLiteDatabase db) { executePragmas(db); - executeCreate(db); - executeMigrations(db, -1, db.getVersion()); + executeMigrations(db, -1, mConfiguration.getDatabaseVersion()); executeCreateIndex(db); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { executePragmas(db); - executeCreate(db); executeMigrations(db, oldVersion, newVersion); } From 30fd73ad1945dd4cda1387d23f62e44ce1c51174 Mon Sep 17 00:00:00 2001 From: Peng Sun Date: Wed, 16 May 2018 19:16:24 +0800 Subject: [PATCH 2/2] change the default sql parser to "delimited" this parser will support multi-line sql. Signed-off-by: Peng Sun --- src/com/activeandroid/Configuration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/activeandroid/Configuration.java b/src/com/activeandroid/Configuration.java index b197d2234..4c06d9150 100644 --- a/src/com/activeandroid/Configuration.java +++ b/src/com/activeandroid/Configuration.java @@ -104,7 +104,7 @@ public static class Builder { private static final int DEFAULT_CACHE_SIZE = 1024; private static final String DEFAULT_DB_NAME = "Application.db"; - private static final String DEFAULT_SQL_PARSER = SQL_PARSER_LEGACY; + private static final String DEFAULT_SQL_PARSER = SQL_PARSER_DELIMITED; ////////////////////////////////////////////////////////////////////////////////////// // PRIVATE MEMBERS