@@ -1197,7 +1197,25 @@ public synchronized boolean open() {
11971197 // Android version should be one version higher.
11981198 if (dbVersion < 18 ) {
11991199 // Version 12: Because of a bug fix that changes JSON collation, invalidate view indexes
1200- String upgradeSql = "DELETE FROM maps; UPDATE views SET lastsequence=0; " +
1200+
1201+ // instead of delete all rows in maps table, drop table and recreate it.
1202+ String upgradeSql = "DROP TABLE maps" ;
1203+ if (!initialize (upgradeSql )) {
1204+ return false ;
1205+ }
1206+
1207+ upgradeSql = "CREATE TABLE IF NOT EXISTS maps ( " +
1208+ " view_id INTEGER NOT NULL REFERENCES views(view_id) ON DELETE CASCADE, " +
1209+ " sequence INTEGER NOT NULL REFERENCES revs(sequence) ON DELETE CASCADE, " +
1210+ " key TEXT NOT NULL COLLATE JSON, " +
1211+ " value TEXT); " +
1212+ " CREATE INDEX IF NOT EXISTS maps_keys on maps(view_id, key COLLATE JSON); " +
1213+ " CREATE INDEX IF NOT EXISTS maps_sequence ON maps(sequence);" ;
1214+ if (!initialize (upgradeSql )) {
1215+ return false ;
1216+ }
1217+
1218+ upgradeSql = "UPDATE views SET lastsequence=0; " +
12011219 "PRAGMA user_version = 18" ;
12021220 if (!initialize (upgradeSql )) {
12031221 return false ;
@@ -1211,6 +1229,20 @@ public synchronized boolean open() {
12111229 // 1. Creates attachments table if it does not exist.
12121230 // 2. Iterate revs table to populate attachments table.
12131231 if (dbVersion >= 101 ) {
1232+
1233+ // NOTE: CBL iOS v1.1.0 does not have maps table, Needs to create it if it does not exist.
1234+ String upgradeSql = "CREATE TABLE IF NOT EXISTS maps ( " +
1235+ " view_id INTEGER NOT NULL REFERENCES views(view_id) ON DELETE CASCADE, " +
1236+ " sequence INTEGER NOT NULL REFERENCES revs(sequence) ON DELETE CASCADE, " +
1237+ " key TEXT NOT NULL COLLATE JSON, " +
1238+ " value TEXT); " +
1239+ " CREATE INDEX IF NOT EXISTS maps_keys on maps(view_id, key COLLATE JSON); " +
1240+ " CREATE INDEX IF NOT EXISTS maps_sequence ON maps(sequence);" ;
1241+ if (!initialize (upgradeSql )) {
1242+ return false ;
1243+ }
1244+
1245+
12141246 // Check if attachments table exists. If not, create the table, and iterate revs
12151247 // to populate attachment table
12161248 boolean existsAttachments = false ;
@@ -1231,7 +1263,7 @@ public synchronized boolean open() {
12311263
12321264 if (!existsAttachments ) {
12331265 // 1. create attachments table
1234- String upgradeSql = "CREATE TABLE attachments ( " +
1266+ upgradeSql = "CREATE TABLE attachments ( " +
12351267 "sequence INTEGER NOT NULL REFERENCES revs(sequence) ON DELETE CASCADE, " +
12361268 "filename TEXT NOT NULL, " +
12371269 "key BLOB NOT NULL, " +
0 commit comments