storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.14k stars 713 forks source link

ionic capacitor android: executeSql always returns a rejected promise #999

Open skrs13 opened 2 years ago

skrs13 commented 2 years ago

ionic version - 6.18.1
cordova --version: 11.0.0 Angular CLI: 13.1.4 Android: 12 (SDK: 31)

executeSql API always returns a rejected promise even for successful execution of queries. For instance, the following table creation returns an error but the table is created successfully - I've verified this by downloading the .db file and opening it with DB Browser for SQLite.

query = `CREATE TABLE IF NOT EXISTS test_table 
                 id INTEGER PRIMARY KEY NOT NULL,
                 col1 INTEGER NULL DEFAULT NULL,
                 col2 CHAR(20) NULL DEFAULT NULL,
                 col3 CHAR(20) NULL DEFAULT NULL,`
        this.dbEngine
            .executeSql(query)
            .then(() => {
                console.log('Table created');
            })
            .catch((e) => {
                console.log(`Table creation error: ${JSON.stringify(e)}`);
            });

Android Logcat has the following output:

Msg: Table creation error: {"rows":{"length":0},"rowsAffected":0}

I have also verified successful insertions into the table but the promise is always returned as rejected. Any query executed with executeSql returns as rejected. But the same query executed with sqlBatch returns a resolved promise.