capacitor-community / sqlite

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

bug: Partial Table Error in exportToJson #590

Closed nblixt closed 4 days ago

nblixt commented 5 days ago

Thank you for maintaining this plugin!

Plugin version: @capacitor-community/sqlite versions 5.7.0 and 5.7.4.

Platform(s): iOS. Android is unaffected.

Current behavior: When calling await CapacitorSQLite.exportToJson({database: this.dbName, jsonexportmode: "partial", encrypted: false}), the console output in Safari shows this error: exportToJson: Error get tables ‘Partial’ failed : Error value is not (string, nsnull,int64,double,[UInt8])

Expected behavior: exportToJson should create a JSON export of my local DB.

Steps to reproduce: Here is my process when my app starts:

Other information: My issue might be related to issue #513. Though, that issue was fixed in v5.6.1-3.

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

Installed Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 5.7.4
  @capacitor/android: 5.7.4
  @capacitor/ios: 5.7.4

[success] iOS looking great! 👌
[success] Android looking great! 👌
nblixt commented 5 days ago

I did some more experimenting. Assuming the previous issue #513 was on to something with the types, I tried removing certain columns from my tables until I got the export working correctly. It looks like my exports work with data for column types integer, text, and boolean.

I started getting failures when attempting to export data from a table that used the real type, which I was using to record latitude and longitude. Once I removed those columns from the schema and repeated the export, everything worked as expected.

In summation, there might be an issue using exportToJson with the column of type real.

robingenz commented 5 days ago

Thanks for reporting that. Would you be willing to create a PR?

nblixt commented 4 days ago

I did more testing and arrived at user error being the source of the issue. I was previously collecting latitude and longitude from device, but temporarily our client wanted to suspend collecting that data. When I looked back at how the data was being created, I found that I had replaced the previous geolocation values with empty strings.

The presence of an empty string in a REAL column was throwing an error only when using exportToJson. Since this isn't how that should be used, I'm going to close this issue.

Thank you for your time.