Reputation: 857
I'm tring to use native @ionic-native/sqlite module with ionic3. If I create a SQLite db in the default location the database gets created.
constructor( public sqlite: SQLite) {
this.initDatabase();
}
initDatabase(){
config = {
name: 'offline.db',
location: 'default'
}
this.sqlite.create(this.config).then(async (db: SQLiteObject) => {
await db.executeSql(`
CREATE TABLE IF NOT EXISTS cond_pag (
id_codizione_pag varchar(4),
descrizione varchar(150),
CONSTRAINT cond_pag_pk PRIMARY KEY (id_codizione_pag)
)`,{});
})
.catch(e => {
console.log(e);
});
}
}
but if I try to use the sd card insetad
config = {
name: 'offline.db',
location: '/sdcard'
}
ionic throws an error
Error: Valid iOS database location could not be determined in openDatabase call
at newSQLError (SQLitePlugin.js:26)
at Object.<anonymous> (SQLitePlugin.js:581)
at Object.openDatabase (SQLitePlugin.js:59)
at index.js:199
at new t (polyfills.js:3)
at SQLite.create (index.js:198)
at SQLite.value [as create] (decorators.js:49)
at DatabaseProvider.webpackJsonp.200.DatabaseProvider.initDatabase (database.ts:28)
at new DatabaseProvider (database.ts:20)
at _createClass (core.js:10933)
what's missing?
Upvotes: 0
Views: 315
Reputation: 26
The following code works for me
initDatabase(){
config = {
name: '/sdcard/offline.db', // file:///sdcard/offline.db
location: 'default'
}
this.sqlite.create(this.config).then(async (db: SQLiteObject) => {
await db.executeSql(`
CREATE TABLE IF NOT EXISTS cond_pag (
id_codizione_pag varchar(4),
descrizione varchar(150),
CONSTRAINT cond_pag_pk PRIMARY KEY (id_codizione_pag)
)`,{});
})
.catch(e => {
console.log(e);
});
}
Upvotes: 1