Error : {"message":"sqlite3_prepare_v2 failure: near \"id\": syntax error","code":5}

Viewed 1681

I have a object below and i want to save it to a sqlite database but I kept getting the error. below is the snippet of the object that I want to save. I already used JSON.Stringify but still i cant get the correct answer.

[{"id":0,"inputName":"Seeds","cost":"100"},
{"id":2,"inputName":"Chemicals(Insecticide,Pesticide,Fungicide)","cost":"100"},
{"id":0,"inputName":"ASample","cost":"100"}]

Here is my sample insert query code

    this.storeInput = JSON.stringify(this.input);
    this.storeLabor = JSON.stringify(this.labor);
    this.storeAdmin = JSON.stringify(this.admin);
    this.sqlite.create({
      name: 'ionicdb.db',
      location: 'default'
        }).then((db: SQLiteObject) => {
          db.executeSql('INSERT INTO `carrots_expenses`(`input`, `labor`, `admin`) VALUES("'+this.storeInput+'","'+this.storeLabor+'","'+this.storeAdmin+'")', {})

            }).catch(e => console.log(JSON.stringify(e)))

This is how I created the table

db.executeSql('CREATE TABLE IF NOT EXISTS carrots_expenses(`rowid` int auto_increment primary key, `input` JSON DEFAULT NULL, `labor` JSON DEFAULT NULL, `admin` JSON DEFAULT NULL)', {})

I spend too much time searching for the answer and I can`t find it, I might miss keywords to search for something.

0 Answers
Related