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.
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.
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); });
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