capacitor-community / sqlite

Community plugin for native & electron SQLite databases
MIT License
426 stars 104 forks source link

exportToJson getSchema Exception #504

Closed dtrigo closed 3 months ago

dtrigo commented 4 months ago

Describe the bug Android version, plugin release v5.5.0

When trying to make a full export an unexpected Exception is thrown at ExportToJson.java (no sync table created, since no import is expected)

https://github.com/capacitor-community/sqlite/blob/7a1c4a61aa823a6dc0afc4d8ec87eb8784d44edb/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java#L365C57-L365C57

To Reproduce schema: CREATE TABLE IF NOT EXISTS table1 ( one_id INTEGER NOT NULL, two_id INTEGER NOT NULL, three_status INTEGER NOT NULL, four_id INTEGER NOT NULL, date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, five INTEGER DEFAULT 0, six INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (one_id, two_id, three_status, four_id) );

referenced line (365): row[1] = sc.substring(cPar + 2); gives an *** ERROR ExportToJson: ExportToJson CreateExportObject: GetTablesFull: length=66; index=67

Expected behavior

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

dtrigo commented 4 months ago

By the way, modifying the code to

case "PRIMARY" -> { oPar = sc.indexOf("("); cPar = sc.indexOf(")"); String pk = sc.substring(oPar + 1, cPar); row[0] = "CPK" + pk.replaceAll("§", ""); row[0] = row[0].replaceAll(" ", ""); row[1] = sc.substring(cPar + 1); jsonRow.setConstraint(row[0]); }

makes it work as expected

jepiqueau commented 4 months ago

@dtrigo if you do not have a sync_table you cannot export the data

dtrigo commented 4 months ago

@dtrigo if you do not have a sync_table you cannot export the data

So...It wouldn't be more accurate giving that error when the function is called?

It feels a bit odd since there are some checks for that data when export is partial....

Moreover, since the error given is accesing an string index out of bounds

jepiqueau commented 4 months ago

@dtrigo Thanks for your comment i will make the fix

jepiqueau commented 3 months ago

@dtrigo what are the reason behind exporting à database whithout having a sync table the issue you had was really à bug in Java so i would like to understand your user case so i can reopen the way of exporting whithout a sync table . Can you answer me quickly please

dtrigo commented 3 months ago

@jepiqueau Our usecase is that our app deeply relies on SQLite, specially important on non-network-online zones, sometimes (rare) we need to analize what's inside the sqlite to debug a process. Let's say, It would be nice to have to fully undestand what's happening when something goes bad

jepiqueau commented 3 months ago

@dtrigo and for this you are using exportToJson. I will put back the ability to run exportToJson without having a sync_table. Is that ok for you

dtrigo commented 3 months ago

@jepiqueau That would be perfect! Thanks

jepiqueau commented 3 months ago

@dtrigo Fixed in 5.5.2

dtrigo commented 3 months ago

@jepiqueau Nice! Thanks