Skip to content

Conversation

@paulstelzer
Copy link

@paulstelzer paulstelzer commented Dec 18, 2025

Add support for SPM using the official capacitor tool https://github.com/ionic-team/capacitor-plugin-converter

All changes made by the tool. I am only adjusted the Package.swift to add ZIPFoundation and SQLCipher.

I have tested in my own project and it seems to work. Would be great if other could test it too. I am only tested with unencrypted data (not with decrypted data)

Fixes #568

@robingenz
Copy link
Member

Here is a dev version for testing:

npm i @capacitor-community/sqlite@7.0.2-dev.5a79381.1766041651

@marcosav
Copy link

Hi, I have tested it with encrypted data and works with no issues.

@true-perfect-code
Copy link

true-perfect-code commented Jan 21, 2026

@robingenz

Thank you for taking care of the further development of the plugin! Good luck with it.

We have installed the development version, but we are getting SCALAR VIOLATION errors. Looking at GitHub, it seems that this problem was already solved in 2022 (see #319 )

Currently, we obtain values as follows

const result = await this._db.query({
    database: this._dbName,
    statement: sql,
    values: cleanValues
});

if (result && Array.isArray(result.values) && result.values.length > 0) {
    const rows = result.values;
    const firstRow = rows[0];
    const keys = Object.keys(firstRow);

    /**
     * STRICT CHECKING (Methodology: Fail-Fast)
     * If more than one row OR more than one column is returned,
     * there is a logical error in the SQL.
     */
    if (rows.length > 1 || keys.length > 1) {
        const violationMsg = `SCALAR VIOLATION: SQL delivered ${rows.length} rows and  ${keys.length} columns. Exactly what is expected 1x1.`;
        pE_Common.log(violationMsg, "error");

        // Error case: We abort so that the developer can correct the SQL.
        finalModel = pE_Common.toScalar(null, false, violationMsg);
        return JSON.stringify(finalModel);
    }

Now we would have to do it this way (so that it also works on Android)

if (result && Array.isArray(result.values) && result.values.length > 0) {
    // --- NEW: iOS Metadaten-Shift ---
    let rows = result.values;

    // If the first object only contains the column names for iOS, we remove it for validation.
    if (rows.length > 1 && rows[0].hasOwnProperty('ios_columns')) {
        pE_Common.log("iOS Metadaten-Header erkannt und für Validierung entfernt.", "info");
        rows = rows.slice(1); // Erstellt eine Kopie ohne den Header
    }
    // --------------------------------

Which is correct, option 1 or 2?

Thanks
pc

EDIT:
After investigating the codebase, we found that in the current master branch, there's an addToResponse function in UtilsSQLCipher.swift that explicitly filters out ios_columns entries:

let keysInArray1 = ["ios_columns"]
mRespSet = mRespSet.filter({ dict2 in
    // ... filtering logic to remove ios_columns
})

This indicates that somewhere in the iOS code, ios_columns is still being generated (likely in fetchColumnData or similar), but should be filtered out before returning results to the JavaScript layer.
Our hypothesis: The Capacitor Migration Tool may have either:

  1. Not correctly migrated this filter logic, or
  2. The filter isn't being called in certain query code paths (e.g., direct query() calls)

Impact: This breaks API consistency between Android and iOS. Our workaround (Option 2) works but forces platform-specific handling in JavaScript, which defeats the purpose of a cross-platform plugin.
Expected behavior: Option 1 should be correct - the plugin should return clean data arrays on both platforms without the ios_columns header. The filtering should happen in the native Swift layer before data reaches JavaScript.
Could you verify that addToResponse (or similar filtering) is properly called in all query paths in the SPM version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Swift Package Manager

4 participants