0

I am using Ionic 2 and SQLite trying to insert a comment in the table and point_id to be equal to second highest point_id of particular match. So I wrote following query, but Ionic 2 is throwing me

sqlite3_prepare_v2 failure: no such column: match_id

INSERT INTO comments (point_id, match_id, comment, created_at)
VALUES((
   SELECT name.point_id 
   FROM (
       SELECT point_id from undo 
       WHERE match_id = ? 
       ORDER BY point_id DESC 
       LIMIT 2) AS name 
   WHERE match_id = ? 
   ORDER BY point_id LIMIT 1), ?, ?, ?)

My whole ionic 2 code is

NativeStorage.getItem('matchID').then(matchID => {
          let query = 'INSERT INTO comments (point_id, match_id, comment, created_at) '+
                      'VALUES((SELECT name.point_id FROM (SELECT point_id from undo WHERE match_id = ? ORDER BY point_id DESC LIMIT 2) AS name WHERE match_id = ? ORDER BY point_id LIMIT 1), ?, ?, ?)';
            this.db.executeSql(query, [matchID.value, matchID.value, matchID.value, data.comment, new Date()]).then(data_comment => {
              let toast = this.toastCtrl.create({
                message: 'Comment was added successfully',
                duration: 2000,
                position: 'top'
              });

              toast.present();
              console.log("comment entered", data_comment);
            }, err => console.error("ERROR enter comment in match tracker ", err))
          })

Thank you very much.

1 Answer 1

1

I changed my SQLite query and now it works fine. If somebody else needs this here it is:

INSERT INTO comments (point_id, match_id, comment, created_at)
VALUES((
    SELECT point_id from undo 
    WHERE match_id = ? 
    ORDER BY point_id DESC 
    LIMIT 1 OFFSET 1), ?, ?, ?)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.