Whenever I attempt to access information from a pre-populated SQLite database, an error message pops up:
sqlite3_prepare_v2 failure: no such table 'plant'
As far as my knowledge goes, SQLite first searches for the mydb.db file in the /www directory by default. If it fails to locate the pre-populated mydb.db file, it generates an empty database. Consequently, the 'plant' table is not found because the newly created blank database does not include this table. Despite confirming that the database actually exists in the /www folder and contains the 'plant' table when checked using sqlite3 mydb.db
followed by .tables
in the terminal.
The reason behind its inability to read from the pre-populated mydb.db file remains a mystery to me.
Directory Structure (starting from root):
/src
-/app
--/app.component.ts
/www
-/mydb.db
app.component.ts:
constructor(public platform: Platform, private sqlite: SQLite ) {
platform.ready().then(() => {
this.getData();
});
}
getData() {
this.sqlite.create({
name: 'mydb.db',
location: 'default'
}).then((db: SQLiteObject) => {
db.executeSql('SELECT * FROM plant ORDER BY id ASC', [])
.then(res => {
// Carry Out Desired Actions
}).catch(e => console.log("FAIL executeSql:", e));
})
}
I've experimented with several suggested solutions from StackOverflow, like uninstalling the app from my device, initiating a new Ionic project, transferring app and configuration files over, and specifying a direct path in the database location. However, the issue persists where it continues attempting to access information from the empty database it creates.