From d786a2a89871ce75846bd4e272cea6ef90397226 Mon Sep 17 00:00:00 2001 From: Tebbe Ubben Date: Wed, 10 Apr 2019 16:15:18 +0200 Subject: [PATCH 1/2] Insight: Set SQLite Sequence to current time millis on table creation --- .../java/info/nightscout/androidaps/db/DatabaseHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index c23d797c8c..b024f64711 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -131,6 +131,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_BOLUS_IDS); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_PUMP_IDS); } catch (SQLException e) { log.error("Can't create database", e); throw new RuntimeException(e); @@ -151,6 +153,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_BOLUS_IDS); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_PUMP_IDS); } else { log.info(DatabaseHelper.class.getName(), "onUpgrade"); TableUtils.dropTable(connectionSource, TempTarget.class, true); From 39412ae032acdd8a13b9364fca648ad584a946f6 Mon Sep 17 00:00:00 2001 From: Tebbe Ubben Date: Wed, 17 Apr 2019 17:31:10 +0200 Subject: [PATCH 2/2] Fix initial sqlite_sequence for Insight driver --- .../nightscout/androidaps/db/DatabaseHelper.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index b024f64711..ad16cb90f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -131,8 +131,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_BOLUS_IDS); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_PUMP_IDS); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\")"); } catch (SQLException e) { log.error("Can't create database", e); throw new RuntimeException(e); @@ -153,8 +155,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_BOLUS_IDS); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = " + System.currentTimeMillis() + " WHERE name = " + DATABASE_INSIGHT_PUMP_IDS); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\")"); } else { log.info(DatabaseHelper.class.getName(), "onUpgrade"); TableUtils.dropTable(connectionSource, TempTarget.class, true);