Here is my input json to insert into a MySQL table that contains some columns with json as column type
Request body
{
"medium":["first","second"],
"material":["hello","funny"],
"style":["hello","test","funny"],
"subject":"test",
"category":"hello category",
"width":2,
"height":2,
"depth":2
}
insert.js
var art = {
medium:req.body.medium,
material:req.body.material,
style:req.body.style,
subject:req.body.subject,
category:req.body.category,
width:req.body.width,
height:req.body.height,
depth:req.body.depth
};
console.log(art);
db.query("INSERT INTO cushbu_art SET ? "db.query("UPDATE cushbu_art SET ?",function(error,result,callback){
console.log(error)
})
Here is the error i am getting
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''second',
material= 'hello', 'funny',style= 'hello', 'test', 'funny', `su' at line 1
But when i try to install directly to json field (via phpmyadmin) it works fine
Here is the output of json before insert ie (console.log(art))
{ medium: [ 'first', 'second' ],
material: [ 'hello', 'funny' ],
style: [ 'hello', 'test', 'funny' ],
subject: 'test',
category: 'hello category',
width: '2',
height: '2',
depth: '2' }
I think its the problem with single quotes in each fields
via Jabaa
No comments:
Post a Comment