简体   繁体   中英

node.js - Error: SQLITE_ERROR: near "users": syntax error

I'm trying to put a JSON object "Synced" (Which you will see in the code) This is the code for a function "addServer(userid, serverid)" The function is being required from another javascript file

     db.all(`SELECT * FROM Users WHERE Tag = ? LIMIT 1`, userid, async(error,element) => {

       if(element[0].Synced === '') {
         var sJSON = {
           users:{
             [userid]:4,
           },
           servers:[`${serverid}`]
         }

        var serverJSON = JSON.stringify(sJSON)
         console.log(serverJSON)
} else { 
  //Else statement not done yet
}
 db.run(`UPDATE Users SET Synced = "${serverJSON}" WHERE Tag = "${userid}"`)
})

Solved. Needed to change quoting.

As Dave Newton said, I had to check my quoting. What I did was change my double quotes to single quotes which solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM