我有一個MySQL表使用這些設置:使用JSON插入到MySQL JSON格式欄的NodeJS
CREATE TABLE `WorkOrders` (
`workorder_id` int(11) NOT NULL AUTO_INCREMENT,
`intertype_id` int(11) NOT NULL,
`equipment_id` int(11) NOT NULL,
`reason_id` int(11) NOT NULL,
`requester_id` int(11) NOT NULL,
`workorder_creationdatetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`phase_id` int(11) NOT NULL,
`criticality_id` int(11) NOT NULL,
`workorder_targetdate` date DEFAULT NULL,
`workorder_enddatetime` datetime DEFAULT NULL,
`workorder_content` json DEFAULT NULL,
PRIMARY KEY (`workorder_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
列 'workorder_content' 有一個JSON數據類型。
然後我有一個使用NodeJS api鏈接到數據庫的AngularJS + Bootstrap。
我試圖使用該腳本將數據插入到我的表:
connection.acquire(function(err, con) {
con.query('INSERT INTO WorkOrders SET ?', workorder.workorder.int, function(err, result) {
con.release();
console.log(err);
if (err) {
res.send({status: 1, message: 'WorkOrder creation failed'});
} else {
res.send({status: 0, message: 'WorkOrder created successfully'});
}
});
});
這裏是什麼workorder.workorder.int包含:
{ phase_id: 1,
intertype_id: '14',
reason_id: '1',
equipment_id: '2',
requester_id: '24',
criticality_id: '29',
workorder_content:
{ adresse_client: 'sefsdf',
type_machin: '1',
type_truc: '8',
truc_cocher: true,
truc_radio: '11',
date_debut: '12/07/2017' } }
我在控制檯的NodeJS錯誤是: {錯誤:UNKNOWN_CODE_PLEASE_REPORT:無效的JSON文本:「無效的值。」在值(或列)的'位置1'[object object]中。
你能幫我嗎?
謝謝。
我現在正在workorder.workorder.int中使用這個:{「phase_id」:1,「intertype_id」:「14」,「reason_id」:「1」,「equipment_id」:「2」,「requester_id」: 「24」, 「criticality_id」: 「29」, 「workorder_content」:{ 「adresse_client」: 「sefsdf」, 「type_machin」: 「1」, 「type_truc」: 「8」, 「truc_cocher」:真 「truc_radio」 :「11」,「date_debut」:「12/07/2017」}}但我有這個錯誤:錯誤:ER_PARSE_ERROR:你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在''{\「phase_id \」附近使用正確的語法:1,\「intertype_id \」:\「14 \」,\「reason_id \」:\「1 \ 「,\」equipment_id \「:\」'在第1行 – malignois