SQLite can't executeSql

Dears,
I’m using SQLite with Ionic 2 RC0. on IOS platform.
I’m trying to make simple query with SQLite but it fails my code is:
import { SQLite } from 'ionic-native';
constructor() { this.db = new SQLite(); this.db.openDatabase({ name: 'cache.db', location: 'default' }).then(() => { alert('Databse Opened'); this.db.executeSql('CREATE TABLE IF NOT EXISTS photos (id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT NOT NULL UNIQUE, imageBase64String TEXT)', {}).then(() => {console.log('Table Created')}, (err) => { console.error('Unable to execute sql: ', err); }); }, (err) => { console.error('Unable to open database: ', err); }); }

The database is opened but when i try to execute any SQL it gives me an Error:
Unable to execute sql: TypeError: undefined is not an object (evaluating 't._objectInstance')
I tried to dump the database connection and i get :
{"_objectInstance":{"version":"1.0","_db":{"_name":"cache.db"},"_txnQueue":{"length":0},"_running":false,"_currentTask":null}}

Note: I tried both plugins:
cordova-plugin-sqlite-2
cordova-plugin-sqlite
and i get the same error.

any help will be appreciated
regards.

3 Likes

The same problem here.

Any response!!! i’m delayed for 3 days now because of that issue ???

I’ve been using the sqlite plugin fine with RC0 - where exactly are you getting your error?

Have you tried the exact same example on this page to make sure it works?

Thank you richard for you replay,
I’m using the instructions on refered page.
I attached the code in my question it’s the same on the documentation page.
Really I don’t know where is the error.
I’m getting the error when I try to excute any Query.

Post your query code

Sorry richard for late response,
My query code is shown in question.
this.db.executeSql('CREATE TABLE IF NOT EXISTS photos (id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT NOT NULL UNIQUE, imageBase64String TEXT)', {}).then(() => {console.log('Table Created')}, (err) => { console.error('Unable to execute sql: ', err); });

Hi

I found a creppy solution by that issue, it is still working in Android and iOS

The documentation says:
Execute SQL on the opened database. Note, you must call openDatabase first, and ensure it resolved and successfully opened the database.

By some reason the database don’t is open succesfully, so try to open again

public database: SQLite;

 this.database = new SQLite();

this.database.openDatabase({name: "data.db", location: "default"}).then(() => {
         
    this.database.executeSql('Insert statement', []).then((data) => {
       
    }, (error) => {
        console.log("ERROR insert: " + error);
    });

 }, (error) => {
     console.log("ERROR open database: ", error);
 });
1 Like

I wrote a small project to make it easier to work with sqlite here if anybody is interested: ionix-sqlite.