SQLite Bug in capacitor project

Wappler 7.7.5, macOS 15.7.4

I encountered a console error in my capacitor project while sqlite paged query. When sorting is enabled in query. Without sorting there is no issue in query. I submitted the error to AI for a solution and received this response. Please check if it can be fixed from Wappler end.

Console Error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name')
    at n (dmxCapacitorSQLite.js:7:1521)
    at dmxCapacitorSQLite.js:7:3819
    at Array.map (<anonymous>)
    at dmxCapacitorSQLite.js:7:3786
    at dmx.ast2sql (dmxCapacitorSQLite.js:7:3895)
    at Capacitor.sqlite.paged (dmxCapacitorSQLite.js:7:6205)
    at r._execStep (dmxAppConnect.js:9:35040)
    at dmxAppConnect.js:9:34542.

AI Solution Found:

Fix TypeError in dmxCapacitorSQLite.js

The goal is to fix the TypeError: Cannot read properties of undefined (reading 'name') which occurs in the ast2sql function of dmxCapacitorSQLite.js.

Proposed Changes

Capacitor SQLite Plugin

[MODIFY]

dmxCapacitorSQLite.js

I will apply several fixes to the ast2sql function:

  1. Null-safety for table name extraction: Update the n function to safely access table.name.

    • From: function n(e){return a(e.table.name||e.table||t.table.name||t.table)}

    • To: function n(e){return a((e.table && e.table.name) || e.table || (t.table && t.table.name) || t.table)}

  2. Null-safety for FROM clause: Update the o function to safely access t.table.name.

    • From: function o(t){return "FROM "+a(t.table.name||t.table)...}

    • To: function o(t){return "FROM "+a((t.table && t.table.name) || t.table)...}

  3. Fix variable typos: In groupBy.map and orders.map callbacks, change n(i) to n(e). The variable i refers to a function, which is incorrect in this context; e is the current element in the map.

    • groupBy.map((e=>(t.joins&&t.joins.length?n(i)+".":"")+a(e.column))) -> groupBy.map((e=>(t.joins&&t.joins.length?n(e)+".":"")+a(e.column)))

    • orders.map((e=>(t.joins&&t.joins.length?n(i)+".":"")+a(e.column)...)) -> orders.map((e=>(t.joins&&t.joins.length?n(e)+".":"")+a(e.column)...))

Verification Plan

Automated Tests

  • I will create a small node script in /tmp/verify_sqlite.js that mimics the dmx.ast2sql function (since it's a pure function) and test it with various AST inputs, including those with missing table properties and with joins.

Manual Verification

  • The user should run the application on an Android device (as reported) and verify that the error no longer appearing when performing SQLite operations.

Did the AI fix work for you? It did point me to the incorrect code, but I believe the groupBy and orders fix he applies is wrong. Instead of changing i to e it should be changed to e.column.

Here is my update: dmxCapacitorSQLite.zip (11.2 KB)

Yes, after code changes by AI, it was working as expected. But I removed the order and condition from the query and using it as a simple paged query without any condition, sort, filter…. I’ll update provided file in wappler and check. If any error encountered, I’ll keep you posted.

@patrick , I’ve updated the given file and re-added sort in my paged query.

Here is the screenshot of implementations and errors.

select `employees`.`id`, `employees`.`pr_id`, `employees`.`emp_id`, `employees`.`emp_name`, `employees`.`user_type`, `employees`.`status`, `employees`.`face_descriptor`, `employees`.`cr_date`, `employees`.`last_update`, `employees`.`synced`, `company`.`comp_id`, `company`.`company_name`, `employees`.`company_id` from `company_employees` as `employees` inner join `company` on `company`.`id` = `employees`.`company_id` order by `employees`.`id` DESC

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name')
    at n (dmxCapacitorSQLite.js:7:1503)
    at dmxCapacitorSQLite.js:7:3802
    at Array.map (<anonymous>)
    at dmxCapacitorSQLite.js:7:3770
    at dmx.ast2sql (dmxCapacitorSQLite.js:7:3884)
    at Capacitor.sqlite.paged (dmxCapacitorSQLite.js:7:6170)
    at r._execStep (dmxAppConnect.js:9:35040)
    at dmxAppConnect.js:9:34542

I see that I forgot one of the AI fixes, here a new update.

dmxCapacitorSQLite.zip (11.2 KB)

Fixed in Wappler 7.7.7