db.query( `開始; INSERT INTO 地址(地址、郵遞區號、城市、州、國家) VALUES('Something', 69420, 'Something', 'Something', 'Something');選擇 LAST_INSERT_ID() INTO @mysql_address_id; INSERT INTO Companies (owner, org_nr, name) VALUES('Something', 133769420, 'Something');選擇 LAST_INSERT_ID() INTO @mysql_company_id; INSERT INTO 使用者(公司、成員、管理者)VALUES(@mysql_company_id, 'someid', 1); INSERT INTO CompanyDetails (shippingAddress、company、shortName、ourReference) VALUES(@mysql_address_id, @mysql_company_id, 'Something', 'Something');提交;`, (錯誤,結果)=> { if (err) 返回 res.status(422).json(err); 返回 res.status(200).json(結果); } );</前> <p>顯示的錯誤是:</p>{"code":"ER_PARSE_ERROR","errno":1064,"sqlMessage":"您的 SQL 語法錯誤;檢查與您的MariaDB 伺服器版本相對應的手冊,了解在'INSERT INTO Addresses (address, postal_code, city, state, Country) VALUES('Ve...' at line 1","sqlState" 附近使用的正確語法: "42000","index":0,"sql":"BEGIN; INSERT INTO 地址 (地址, 郵遞區號, 城市, 州, 國家) VALUES('Something', 69420, 'Something', 'Something' , ' Something'); SELECT LAST_INSERT_ID() INTO @mysql_address_id; INSERT INTO Companies (owner, org_nr, name) VALUES('someid', 133769420, 'Something'); SELECT LAST_INSERT_ID() INTO9420, 'Something'); SELECT ,管理員)VALUES(@mysql_company_id,'someid',1); INSERT INTO CompanyDetails(shippingAddress,company,shortName,ourReference)VALUES(@mysql_address_id,@mysql_company_id,'Something','Somethingthing'); ;/pre> <p>有人知道這可能是什麼原因引起的嗎?任何幫助都會不勝感激:)</p>
P粉0374504672023-08-27 10:14:45
我在這裡找到了解決方案:https://stackoverflow.com/a/23267627/13214923 原來node-mysql預設不支援多個語句。
透過新增
{multipleStatements: true,}
到我的連接池配置中,它就像魔術般地工作了 :)