capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
487 stars 116 forks source link

ImportFromJson db is Locked #101

Closed rukshankr closed 3 years ago

rukshankr commented 3 years ago

Hi, I'm a complete beginner testing a database using Angular on Nexus 6 simulator API 29 on Android Studio. When I'm trying to do a full import the 1st time it works and says that my database is created with all the rows entered. But when I try a full import of the same json object again it says one table (name:"role") does not exist to delete, but when I tested with the database the first time the table was there.

CreateDatabaseSchema: DropAll failed: java.lang.Exception: DropAllTables failed: net.sqlcipher.database.SQLiteException: no such table: main.access: DROP TABLE IF EXISTS role

So I tried deleting the database using the deletedatabase function and it says _*database is locked, while compiling: select count() from sqlitemaster; **

To replicate: I deleted the db from data/data/com.***.app/databases and tried again. It still gives the same "no such table" error.

I tried a partial import by removing the schema, but it still says: _*database is locked, while compiling: select count() from sqlitemaster; **

Both the full and partial import Json objs were validated using validateJson() and shows no error there.

I'm using this plugin for a college assignment which is due soon so any help would be highly appreciated.

my getDB code: ` async runDB(imported: Object): Promise { try { let dbExists = await this._sqlite.sqlite.isDatabase("testdb"); if (dbExists.result) { this.log+= "((db exists))"; let partialJson = await this._mainService.partialImportAll();

    let result = await this._sqlite.isJsonValid(
      JSON.stringify(partialJson)
    );
    if (!result.result) {
      return Promise.reject(new Error("IsJsonValid failed"));
    }
    this.log += "\n$$$ Json Object is valid $$$\n";
    // partial import
    let ret = await this._sqlite.importFromJson(
      JSON.stringify(partialJson)
    );
    this.log += `\n||| full import result ${ret.changes.changes}`;
    if (ret.changes.changes === -1)
      return Promise.reject(
        new Error("ImportFromJson 'full' dataToImport failed")
      );
  } else {
    //import fully from mysql

    // test Json object validity
    let result = await this._sqlite.isJsonValid(JSON.stringify(imported));
    if (!result.result) {
      return Promise.reject(new Error("IsJsonValid failed"));
    }
    this.log += "\n$$$ dataToImport Json Object is valid $$$\n";
    // full import
    let ret = await this._sqlite.importFromJson(JSON.stringify(imported));
    this.log += `\n||| full import result ${ret.changes.changes}`;
    if (ret.changes.changes === -1)
      return Promise.reject(
        new Error("ImportFromJson 'full' dataToImport failed")
      );
  }

  // check if the databases exist
  // and delete it for multiple successive tests
  //await deleteDatabase(db);

  // initialize the connection
  const db = await this._sqlite.createConnection(
    "testdb",
    false,
    "no-encryption",
    1
  );
  this.log += "\ndb connected " + db;

  // open db testNew
  await db.open();
  this.log += "\ndb opened";

  //table exists
  let isTable = await db.isTable("repair");
  this.log += "\n???is table repair?: " + isTable.result + "|\n";

  let res = await db.query("SELECT * FROM role;");
  this.log += "\nrole;;: " + res.values.length + " \n";

  // Close Connection MyDB
  await this._sqlite.closeConnection("martis");
  this.log += "\n> closeConnection 'myDb' successful\n";

  return Promise.resolve();
} catch (err) {
  this.log += "\nrejected";
  this.showError(err.message);
  return Promise.reject(err);
}

}`

my full import Json, which is called from a REST API. { "database": "testdb", "version": 1, "encrypted": false, "mode": "full", "tables": [ { "name": "access", "schema": [ { "column": "AccessID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "Access", "value": "TEXT NOT NULL" } ], "values": [ [ "A101", "Update, delete" ], [ "A102", "View" ] ] }, { "name": "asset", "schema": [ { "column": "AssetID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "AssetType", "value": "TEXT DEFAULT NULL" }, { "column": "Status", "value": "TEXT DEFAULT NULL" }, { "column": "GPSLatitude", "value": "TEXT DEFAULT NULL" }, { "column": "GPSLongitude", "value": "TEXT DEFAULT NULL" }, { "column": "Region", "value": "TEXT DEFAULT NULL" }, { "column": "Division", "value": "TEXT DEFAULT NULL" }, { "column": "SubDivision", "value": "TEXT DEFAULT NULL" }, { "column": "NearestMilePost", "value": "TEXT DEFAULT NULL" }, { "column": "LastTestedDate", "value": "TEXT DEFAULT NULL" } ], "values": [ [ "A101", null, "Functions", "40.741895", "-73.989308", "NY", "Manhatten", "Bronx", "MP251", "2019-08-14T00:00:00.000Z" ], [ "A102", null, "Functions", "40.96418572610003", "-76.5923811201172", "PA", "Mechanicsville", "Brook Avenue", "MP211", "2018-09-12T03:16:39.000Z" ], [ "A103", null, "Not fucntioning", "39.283157046013734", "-80.50712966683095", "WV", "Lake Floyd", "Country route", "MP511", "2018-01-24T07:36:06.000Z" ], [ "A104", null, "Functions", "50.651895", "-29.889308", "NC", "Carolina", "Suburbs", "MP564", "2018-01-24T07:36:06.000Z" ], [ "A105", null, "Working", "40.742066", "-73.989204", "a", "c", "v", "b", "2020-11-26T00:00:00.000Z" ], [ "A106", null, "as", "40.742023", "-73.989252", "d", "d", "a", "s", "2020-11-25T00:00:00.000Z" ] ] }, { "name": "role", "schema": [ { "column": "RoleID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "Title", "value": "TEXT NOT NULL" }, { "column": "CreatedDate", "value": "TEXT NOT NULL" }, { "column": "UpdatedDate", "value": "TEXT DEFAULT NULL" }, { "column": "DeletedDate", "value": "TEXT DEFAULT NULL" } ], "values": [ [ "R101", "Supervisor", "2018-09-12T06:24:04.000Z", null, null ], [ "R102", "Inspector", "2019-05-16T16:16:23.000Z", "2019-10-25T03:52:31.000Z", null ], [ "R103", "Engineer", "2018-08-15T07:29:21.000Z", null, null ] ] }, { "name": "user", "schema": [ { "column": "UserID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "Name", "value": "TEXT NOT NULL" }, { "column": "Email", "value": "TEXT NOT NULL" }, { "column": "Password", "value": "TEXT NOT NULL" }, { "column": "Region", "value": "TEXT NOT NULL" }, { "column": "RoleID", "value": "TEXT NOT NULL" }, { "constraint": "user_ibfk_1", "value": "FOREIGN KEY (RoleID) REFERENCES role (RoleID) ON DELETE CASCADE" } ], "values": [ [ "EMP101", "Edith Franco", "Edith.F@gmail.com", "$2b$10$XiczolHXWQIYIvfHR4XCk.WRMMNkBKejohH3NwWeGdheQToZrJ3KC", "CAL", "R102" ], [ "EMP102", "Sofie Andrew", "Sofie.A@gmail.com", "$2b$10$skJne7h0YrStWOGPHutEhuCrQQbFWmuh.55GYSYWsjYK2XfWuajJG", "CAL", "R101" ], [ "EMP103", "Eren Johns", "Eren.J@gmail.com", "$2b$10$XGAJtiLV5/TrVEYBNC6axO2vYsjbiYXAsoAShOP3UvH7YCQYO69C2", "NY", "R101" ], [ "EMP104", "Nyle Franklin", "Nyle.F@gmail.com", "$2b$10$hG9goEpz.q4bwICgMn0JH.XeWiUNN4059SqOwXEiFsbjqyz4z1JYy", "TX", "R103" ], [ "EMP105", "Robson Eaton", "Robson.E@gmail.com", "$2b$10$YCQ92k1H6FfgJZMuJou2Quo1e5kcafyX0taibfxqztk.Scxfo4AKW", "NC", "R103" ] ] }, { "name": "device", "schema": [ { "column": "DeviceID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "UserID", "value": "TEXT NOT NULL" }, { "column": "PIN", "value": "TEXT NOT NULL" }, { "constraint": "device_ibfk_1", "value": "FOREIGN KEY (UserID) REFERENCES user(UserID) ON DELETE CASCADE" } ], "values": [ [ "D101", "EMP101", "8426" ], [ "D102", "EMP102", "6248" ], [ "D103", "EMP103", "7946" ], [ "D104", "EMP104", "4613" ], [ "D105", "EMP105", "1234" ] ] }, { "name": "repair", "schema": [ { "column": "AssetID", "value": "TEXT NOT NULL" }, { "column": "CreatedDate", "value": "TEXT NOT NULL" }, { "column": "EngineerID", "value": "TEXT DEFAULT NULL" }, { "column": "CompletedDate", "value": "TEXT DEFAULT NULL" }, { "column": "comments", "value": "TEXT DEFAULT NULL" }, { "constraint": "PK_repair", "value": "PRIMARY KEY (AssetID, CreatedDate)" }, { "constraint": "repair_ibfk_2", "value": "FOREIGN KEY (EngineerID) REFERENCES user(UserID) ON DELETE CASCADE" }, { "constraint": "repair_ibfk_1", "value": "FOREIGN KEY (AssetID) REFERENCES asset(AssetID) ON DELETE CASCADE" } ], "values": [ [ "A101", "2020-04-17T00:00:00.000Z", "EMP105", "2021-03-19T00:00:00.000Z", "Complete" ], [ "A101", "2020-04-17T23:16:38.000Z", "EMP105", "2020-11-18T00:48:00.000Z", "Complete" ], [ "A101", "2020-11-11T00:00:00.000Z", "EMP103", "2020-12-10T00:00:00.000Z", "THis is a comment" ], [ "A101", "2020-11-15T16:38:55.000Z", null, null, "COmment" ], [ "A102", "2020-05-16T09:45:09.000Z", null, null, null ], [ "A102", "2020-05-26T09:45:09.000Z", null, null, null ], [ "A104", "2021-03-16T00:00:00.000Z", "EMP102", "2021-03-19T00:00:00.000Z", "Fixed" ], [ "A104", "2021-03-17T00:00:00.000Z", "EMP102", null, "Fixed" ], [ "A106", "2020-11-13T19:26:00.000Z", null, "2021-03-27T00:00:00.000Z", null ] ] }, { "name": "roleaccess", "schema": [ { "column": "RoleID", "value": "TEXT NOT NULL" }, { "column": "AccessID", "value": "TEXT NOT NULL" }, { "column": "CreatedDate", "value": "TEXT NOT NULL" }, { "column": "UpdatedDate", "value": "TEXT DEFAULT NULL" }, { "column": "DeletedDate", "value": "TEXT DEFAULT NULL" }, { "constraint": "PK_roleaccesss", "value": "PRIMARY KEY (RoleID, AccessID)" }, { "constraint": "roleaccess_ibfk_1", "value": "FOREIGN KEY (RoleID) REFERENCES role(RoleID) ON DELETE CASCADE" }, { "constraint": "roleaccess_ibfk_2", "value": "FOREIGN KEY (AccessID) REFERENCES access(AccessID) ON DELETE CASCADE" } ], "values": [ [ "R101", "A101", "2019-11-22T07:20:15.000Z", null, null ], [ "R102", "A101", "2019-12-27T12:13:30.000Z", null, null ], [ "R103", "A101", "2019-09-13T00:00:00.000Z", null, "2020-06-24T06:24:33.000Z" ], [ "R103", "A102", "2020-01-24T05:19:29.000Z", "2020-04-17T07:22:09.000Z", null ] ] }, { "name": "testmodule", "schema": [ { "column": "TestModID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "SupervisorID", "value": "TEXT NOT NULL" }, { "column": "Description", "value": "TEXT NOT NULL" }, { "constraint": "testmodule_ibfk_1", "value": "FOREIGN KEY (SupervisorID) REFERENCES user (UserID) ON DELETE CASCADE" } ], "values": [ [ "TM101", "EMP102", "Check Lights" ], [ "TM102", "EMP105", "Check Energy source" ] ] }, { "name": "test", "schema": [ { "column": "TestID", "value": "TEXT PRIMARY KEY NOT NULL" }, { "column": "DateIssued", "value": "TEXT NOT NULL" }, { "column": "AssetID", "value": "TEXT NOT NULL" }, { "column": "InspectorID", "value": "TEXT NOT NULL" }, { "column": "Result", "value": "TEXT DEFAULT NULL" }, { "column": "SupervisorID", "value": "TEXT NOT NULL" }, { "column": "DateCompleted", "value": "TEXT DEFAULT NULL" }, { "column": "Frequency", "value": "INTEGER NOT NULL" }, { "column": "Priority", "value": "INTEGER DEFAULT NULL" }, { "column": "TestModID", "value": "TEXT NOT NULL" }, { "column": "comments", "value": "TEXT DEFAULT NULL" }, { "constraint": "test_ibfk_1", "value": "FOREIGN KEY (AssetID) REFERENCES asset(AssetID) ON DELETE CASCADE" }, { "constraint": "test_ibfk_2", "value": "FOREIGN KEY (InspectorID) REFERENCES user(UserID) ON DELETE CASCADE" }, { "constraint": "test_ibfk_3", "value": "FOREIGN KEY (SupervisorID) REFERENCES user (UserID) ON DELETE CASCADE" }, { "constraint": "test_ibfk_4", "value": "FOREIGN KEY (TestModID) REFERENCES testmodule (TestModID) ON DELETE CASCADE" } ], "values": [ [ "T101", "2019-09-20T08:25:04.000Z", "A102", "EMP104", "Completed", "EMP105", "2020-07-16T19:13:09.000Z", 2, 0, "TM102", "This is a comment" ], [ "T102", "2020-04-23T01:17:28.000Z", "A101", "EMP101", "Pending", "EMP103", null, 1, 1, "TM101", "" ], [ "T103", "2020-03-19T00:00:00.000Z", "A102", "EMP104", "Pending", "EMP102", null, 3, 0, "TM102", "" ], [ "T104", "2020-07-16T19:13:09.000Z", "A102", "EMP101", "Fail", "EMP102", "2020-05-16T09:45:09.000Z", 1, 1, "TM102", "Just to check if a change happened again" ], [ "T105", "2020-11-20T08:40:18.000Z", "A106", "EMP104", "Fail", "EMP103", "2020-11-27T00:21:00.000Z", 1, 1, "TM102", "Checked" ], [ "T106", "2020-07-16T19:13:09.000Z", "A102", "EMP101", null, "EMP102", null, 1, 1, "TM102", null ], [ "T110", "2021-03-27T10:23:15.000Z", "A102", "EMP101", null, "EMP102", null, 1, 3, "TM101", null ] ] } ] }

jepiqueau commented 3 years ago

@rukshankr Thanks for using the plugin, which release of the plugin are you using 2.9.14 or 3.0.0-beta.7 ?

jepiqueau commented 3 years ago

@rukshankr this is certainly due to the constraints

rukshankr commented 3 years ago

@rukshankr Thanks for using the plugin, which release of the plugin are you using 2.9.14 or 3.0.0-beta.7 ?

the 3.0.0-beta 7

rukshankr commented 3 years ago

@rukshankr this is certainly due to the constraints

Oh. Do you know of any way that I can circumvent this issue?

jepiqueau commented 3 years ago

@rukshankr i am working on it i did fix it for android but not yet for iOS and Electron hope i will have a fix to day

jepiqueau commented 3 years ago

@rukshankr waiting for the fix you could do this in the sqlite/SQLITE/UtilsDrop.java file change in the getTablesNames

        query += "AND name NOT LIKE 'android_%';";

by

        query += "AND name NOT LIKE 'android_%' ";
        query += "ORDER BY rootpage DESC;";

this should make it working, the tables are deleted in the reverse order that they have been created. So the tables which have a constraint on other tables will be deleted first. tell me if it is working on your side

jepiqueau commented 3 years ago

@rukshankr in json object the null value should be replaced by "NULL" to be compatible with iOS so the object should be :

{ 
  database: "testdb",
  version: 1,
  encrypted: false,
  mode: "full",
  tables: [
    { 
      name: "access",
      schema: [ 
        { column: "AccessID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "Access", value: "TEXT NOT NULL" }
      ],
      values: [
        [ "A101", "Update, delete" ],
        [ "A102", "View" ]
      ]
    },
    { 
      name: "asset",
      schema: [
        { column: "AssetID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "AssetType", value: "TEXT DEFAULT NULL" },
        { column: "Status", value: "TEXT DEFAULT NULL" },
        { column: "GPSLatitude", value: "TEXT DEFAULT NULL" },
        { column: "GPSLongitude", value: "TEXT DEFAULT NULL" },
        { column: "Region", value: "TEXT DEFAULT NULL" },
        { column: "Division", value: "TEXT DEFAULT NULL" },
        { column: "SubDivision", value: "TEXT DEFAULT NULL" },
        { column: "NearestMilePost", value: "TEXT DEFAULT NULL" },
        { column: "LastTestedDate", value: "TEXT DEFAULT NULL" }
      ],
      values: [
        [ "A101", "NULL", "Functions", "40.741895", "-73.989308", "NY", "Manhatten", "Bronx", "MP251", "2019-08-14T00:00:00.000Z" ],
        [ "A102", "NULL", "Functions", "40.96418572610003", "-76.5923811201172", "PA", "Mechanicsville", "Brook Avenue", "MP211", "2018-09-12T03:16:39.000Z" ],
        [ "A103", "NULL", "Not fucntioning", "39.283157046013734", "-80.50712966683095", "WV", "Lake Floyd", "Country route", "MP511", "2018-01-24T07:36:06.000Z" ],
        [ "A104", "NULL", "Functions", "50.651895", "-29.889308", "NC", "Carolina", "Suburbs", "MP564", "2018-01-24T07:36:06.000Z" ],
        [ "A105", "NULL", "Working", "40.742066", "-73.989204", "a", "c", "v", "b", "2020-11-26T00:00:00.000Z" ],
        [ "A106", "NULL", "as", "40.742023", "-73.989252", "d", "d", "a", "s", "2020-11-25T00:00:00.000Z" ]
      ]
    },
    {
      name: "role",
      schema: [
        { column: "RoleID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "Title", value: "TEXT NOT NULL" },
        { column: "CreatedDate", value: "TEXT NOT NULL" },
        { column: "UpdatedDate", value: "TEXT DEFAULT NULL" },
        { column: "DeletedDate", value: "TEXT DEFAULT NULL" }
      ],
      values: [
        [ "R101", "Supervisor", "2018-09-12T06:24:04.000Z", "NULL", "NULL" ],
        [ "R102", "Inspector", "2019-05-16T16:16:23.000Z", "2019-10-25T03:52:31.000Z", "NULL" ],
        [ "R103", "Engineer", "2018-08-15T07:29:21.000Z", "NULL", "NULL" ]
      ]
    },
    {
      name: "user",
      schema: [
        { column: "UserID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "name", value: "TEXT NOT NULL" },
        { column: "Email", value: "TEXT NOT NULL" },
        { column: "Password", value: "TEXT NOT NULL" },
        { column: "Region", value: "TEXT NOT NULL" },
        { column: "RoleID", value: "TEXT NOT NULL" },
        { constraint: "user_ibfk_1", value: "FOREIGN KEY (RoleID) REFERENCES role (RoleID) ON DELETE CASCADE" }
      ],
      values: [
        [ "EMP101", "Edith Franco", "Edith.F@gmail.com", "$2b$10$XiczolHXWQIYIvfHR4XCk.WRMMNkBKejohH3NwWeGdheQToZrJ3KC", "CAL", "R102" ],
        [ "EMP102", "Sofie Andrew", "Sofie.A@gmail.com", "$2b$10$skJne7h0YrStWOGPHutEhuCrQQbFWmuh.55GYSYWsjYK2XfWuajJG", "CAL", "R101" ],
        [ "EMP103", "Eren Johns", "Eren.J@gmail.com", "$2b$10$XGAJtiLV5/TrVEYBNC6axO2vYsjbiYXAsoAShOP3UvH7YCQYO69C2", "NY", "R101" ],
        [ "EMP104", "Nyle Franklin", "Nyle.F@gmail.com", "$2b$10$hG9goEpz.q4bwICgMn0JH.XeWiUNN4059SqOwXEiFsbjqyz4z1JYy", "TX", "R103" ],
        [ "EMP105", "Robson Eaton", "Robson.E@gmail.com", "$2b$10$YCQ92k1H6FfgJZMuJou2Quo1e5kcafyX0taibfxqztk.Scxfo4AKW", "NC", "R103" ]
      ]
    },
    {
      name: "device",
      schema: [
        { column: "DeviceID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "UserID", value: "TEXT NOT NULL" },
        { column: "PIN", value: "TEXT NOT NULL" },
        { constraint: "device_ibfk_1", value: "FOREIGN KEY (UserID) REFERENCES user(UserID) ON DELETE CASCADE" }
      ],
      values: [
        [ "D101", "EMP101", "8426" ],
        [ "D102", "EMP102", "6248" ],
        [ "D103", "EMP103", "7946" ],
        [ "D104", "EMP104", "4613" ],
        [ "D105", "EMP105", "1234" ]
      ]
    },
    {
      name: "repair",
      schema: [
        { column: "AssetID", value: "TEXT NOT NULL" },
        { column: "CreatedDate", value: "TEXT NOT NULL" },
        { column: "EngineerID", value: "TEXT DEFAULT NULL" },
        { column: "CompletedDate", value: "TEXT DEFAULT NULL" },
        { column: "comments", value: "TEXT DEFAULT NULL" },
        { constraint: "PK_repair", value: "PRIMARY KEY (AssetID, CreatedDate)" },
        { constraint: "repair_ibfk_2", value: "FOREIGN KEY (EngineerID) REFERENCES user(UserID) ON DELETE CASCADE" },
        { constraint: "repair_ibfk_1", value: "FOREIGN KEY (AssetID) REFERENCES asset(AssetID) ON DELETE CASCADE" }
      ],
      values: [
        [ "A101", "2020-04-17T00:00:00.000Z", "EMP105", "2021-03-19T00:00:00.000Z", "Complete" ],
        [ "A101", "2020-04-17T23:16:38.000Z", "EMP105", "2020-11-18T00:48:00.000Z", "Complete" ],
        [ "A101", "2020-11-11T00:00:00.000Z", "EMP103", "2020-12-10T00:00:00.000Z", "THis is a comment" ],
        [ "A101", "2020-11-15T16:38:55.000Z", "NULL", "NULL", "COmment" ],
        [ "A102", "2020-05-16T09:45:09.000Z", "NULL", "NULL", "NULL" ],
        [ "A102", "2020-05-26T09:45:09.000Z", "NULL", "NULL", "NULL" ],
        [ "A104", "2021-03-16T00:00:00.000Z", "EMP102", "2021-03-19T00:00:00.000Z", "Fixed" ],
        [ "A104", "2021-03-17T00:00:00.000Z", "EMP102", "NULL", "Fixed" ],
        [ "A106", "2020-11-13T19:26:00.000Z", "NULL", "2021-03-27T00:00:00.000Z", "NULL" ]
      ]
    },
    {
      name: "roleaccess",
      schema: [
        { column: "RoleID", value: "TEXT NOT NULL" },
        { column: "AccessID", value: "TEXT NOT NULL" },
        { column: "CreatedDate", value: "TEXT NOT NULL" },
        { column: "UpdatedDate", value: "TEXT DEFAULT NULL" },
        { column: "DeletedDate", value: "TEXT DEFAULT NULL" },
        { constraint: "PK_roleaccesss", value: "PRIMARY KEY (RoleID, AccessID)" },
        { constraint: "roleaccess_ibfk_1", value: "FOREIGN KEY (RoleID) REFERENCES role(RoleID) ON DELETE CASCADE" },
        { constraint: "roleaccess_ibfk_2", value: "FOREIGN KEY (AccessID) REFERENCES access(AccessID) ON DELETE CASCADE" }
      ],
      values: [
        [ "R101", "A101", "2019-11-22T07:20:15.000Z", "NULL", "NULL" ],
        [ "R102", "A101", "2019-12-27T12:13:30.000Z", "NULL", "NULL" ],
        [ "R103", "A101", "2019-09-13T00:00:00.000Z", "NULL", "2020-06-24T06:24:33.000Z" ],
        [ "R103", "A102", "2020-01-24T05:19:29.000Z", "2020-04-17T07:22:09.000Z", "NULL" ]
      ]
    },
    {
      name: "testmodule",
      schema: [
        { column: "TestModID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "SupervisorID", value: "TEXT NOT NULL" },
        { column: "Description", value: "TEXT NOT NULL" },
        { constraint: "testmodule_ibfk_1", value: "FOREIGN KEY (SupervisorID) REFERENCES user (UserID) ON DELETE CASCADE" }
      ],
      values: [
        [ "TM101", "EMP102", "Check Lights" ],
        [ "TM102", "EMP105", "Check Energy source" ]
      ]
    },
    {
      name: "test",
      schema: [
        { column: "TestID", value: "TEXT PRIMARY KEY NOT NULL" },
        { column: "DateIssued", value: "TEXT NOT NULL" },
        { column: "AssetID", value: "TEXT NOT NULL" },
        { column: "InspectorID", value: "TEXT NOT NULL" },
        { column: "Result", value: "TEXT DEFAULT NULL" },
        { column: "SupervisorID", value: "TEXT NOT NULL" },
        { column: "DateCompleted", value: "TEXT DEFAULT NULL" },
        { column: "Frequency", value: "INTEGER NOT NULL" },
        { column: "Priority", value: "INTEGER DEFAULT NULL" },
        { column: "TestModID", value: "TEXT NOT NULL" },
        { column: "comments", value: "TEXT DEFAULT NULL" },
        { constraint: "test_ibfk_1", value: "FOREIGN KEY (AssetID) REFERENCES asset(AssetID) ON DELETE CASCADE" },
        { constraint: "test_ibfk_2", value: "FOREIGN KEY (InspectorID) REFERENCES user(UserID) ON DELETE CASCADE" },
        { constraint: "test_ibfk_3", value: "FOREIGN KEY (SupervisorID) REFERENCES user (UserID) ON DELETE CASCADE" },
        { constraint: "test_ibfk_4", value: "FOREIGN KEY (TestModID) REFERENCES testmodule (TestModID) ON DELETE CASCADE" }
      ],
      values: [
        [ "T101", "2019-09-20T08:25:04.000Z", "A102", "EMP104", "Completed", "EMP105", "2020-07-16T19:13:09.000Z", 2, 0, "TM102", "This is a comment" ],
        [ "T102", "2020-04-23T01:17:28.000Z", "A101", "EMP101", "Pending", "EMP103", "NULL", 1, 1, "TM101", "" ],
        [ "T103", "2020-03-19T00:00:00.000Z", "A102", "EMP104", "Pending", "EMP102", "NULL", 3, 0, "TM102", "" ],
        [ "T104", "2020-07-16T19:13:09.000Z", "A102", "EMP101", "Fail", "EMP102", "2020-05-16T09:45:09.000Z", 1, 1, "TM102", "Just to check if a change happened again" ],
        [ "T105", "2020-11-20T08:40:18.000Z", "A106", "EMP104", "Fail", "EMP103", "2020-11-27T00:21:00.000Z", 1, 1, "TM102", "Checked" ],
        [ "T106", "2020-07-16T19:13:09.000Z", "A102", "EMP101", "NULL", "EMP102", "NULL", 1, 1, "TM102", "NULL" ],
        [ "T110", "2021-03-27T10:23:15.000Z", "A102", "EMP101", "NULL", "EMP102", "NULL", 1, 3, "TM101", "NULL" ]
      ]
    }
  ]
}
jepiqueau commented 3 years ago

@rukshankr this is fixed in release 3.0.0-beta.8. Thanks and good luck for your work

rukshankr commented 3 years ago

@rukshankr waiting for the fix you could do this in the sqlite/SQLITE/UtilsDrop.java file change in the getTablesNames

        query += "AND name NOT LIKE 'android_%';";

by

        query += "AND name NOT LIKE 'android_%' ";
        query += "ORDER BY rootpage DESC;";

this should make it working, the tables are deleted in the reverse order that they have been created. So the tables which have a constraint on other tables will be deleted first. tell me if it is working on your side

It did work. Thank you so much! I was stuck here for days.

I have another simple question if you don't mind: what should happen if I import the same data as a partial Import after populating the db with the full import? Should it simply ignore the existing values or should it give an error, like it happens with mine right now?

This really is an awesome plugin. Thank you for creating it!

jepiqueau commented 3 years ago

@rukshankr The full import drop all tables first, the local import does not do it. So you cannot reload the same data. The local is made for synchronization between the remote and the local database. So only things have changed from the last full or local import should be part of the json object. ie new tables, indexes, triggers or data. Hope it is clear. I updated the release to 3.0.0-beta.9 as the changes lead to an other error