Clarky
Clarky

Reputation: 49

SELECT ERROR SQLITE.ALL - Prepare Error 1

I'm trying to run a query on a local SQL db file that I have preloaded data into however when it runs I'm getting the error "SELECT ERROR SQLITE.ALL - Prepare Error 1".

I have tried getting the database connection in a separate function instead of using arrow functions as well as re-installing the application on my iOS sim but this had no affect.

I have a database.service.ts file which contains:

public getdbConnection() {
    if(!Sqlite.exists("drills.db"))
    {
        Sqlite.copyDatabase("drills.db")
    }
    return new Sqlite("drills.db")
    }

public getTopics() {
    this.getdbConnection().then(db => {
        db.all("SELECT * FROM drills").then(rows => {
            console.log("Selected")
            for(var row in rows) {
                console.log("RESULT", rows[row]);
            }
        }, error => {
            console.log("SELECT ERROR", error);
        });
    });
}

And in my menu.componet.ts I call it using:

    ngOnInit(): void {
    this.database.getTopics();
}

Am I going wrong with how I connect to the local DB? It's stored under the src folder eg src/drills.db?

Upvotes: 1

Views: 285

Answers (1)

Manoj
Manoj

Reputation: 21908

You must make sure the DB file is copied in your bundle. The example code assumes you use .sqlite extension but since you are using .db you must adjust the webpack config accordingly.

Use,

{ from: { glob: "**/*.db" } }

Upvotes: 2

Related Questions