Я вызываю хранимую процедуру, и она дает синтаксическую ошибку, я не могу понять это. Кто-нибудь может помочь?
"sqlMessage": "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 '\"billToId\":137,\"shipToId\":137,\"loadingId\":137,\"loadingLocationId\":2,\"billToLocat' at line 1",
Это JSON, который я передаю в виде строки.
Вот хранимая процедура:
drop procedure if exists createRequisition;
DELIMITER $$
CREATE PROCEDURE createRequisition(p_reqBranchId INT,p_unloadingJson JSON,locationsString text,p_quantity FLOAT,
p_expectedDeliveryDate DATE,p_loadingDate DATE,p_refId VARCHAR(255),p_notes TEXT,p_createdBy VARCHAR(255),p_vehicleId INT, p_vehicleName VARCHAR(255),p_isWeb int,p_priority int,p_editId int)
BEGIN
-- call SP_TMS_CreateRequisition()
declare lastReqCode int;
declare d_ReqCode text;
declare d_branchCode text;
declare lastInsert INT;
declare d_branchIdsStr text;
START transaction;
if(p_editId is null) then
BEGIN
SET d_branchCode = (select group_concat(freighterCode) from Freighters join Branches on freighterId = branchFreighterId where branchId = p_reqBranchId);
SET d_branchIdsStr = (select group_concat(branchId) from Branches where branchFreighterId = (select branchFreighterId from Branches where branchId = p_reqBranchId) );
SET lastReqCode = (SELECT if(max(CAST(substring(reqCode,5) AS UNSIGNED))>0,max(CAST(substring(reqCode,5) AS UNSIGNED)),0) FROM Requisitions where find_in_set(reqBranchId,d_branchIdsStr));
set d_ReqCode = (select concat(d_branchCode,lastReqCode+1));
INSERT INTO Requisitions(reqCode,reqBranchId,vehicleId,vehicleName,loadingUnloadingJson,quantity,originalQuantity,deliveryDate,loadingDate,referenceNumber,notes,createdAt,createdBy,updatedAt,reqIsWeb,priority)
VALUES(d_ReqCode,p_reqBranchId,p_vehicleId, p_vehicleName,p_unloadingJson,p_quantity,p_quantity,p_expectedDeliveryDate,p_loadingDate,p_refId,p_notes,NOW(),p_createdBy,NOW(),p_isWeb,p_priority);
set lastInsert = (SELECT LAST_INSERT_ID());
set locationsString = replace(locationsString,'reqId',lastInsert);
set @reqLocationInsert = concat('INSERT INTO RequisitionDetails (requisitionId,billToBranchId,shipToBranchId,loadingBranchId,loadingLocationId,billToLocationId,shipToLocationId,skuId,skuQuantity,skuWeight,requisitionJson) VALUES',locationsString);
PREPARE stmt from @reqLocationInsert;
EXECUTE stmt;
select lastInsert as reqId;
END;
else
BEGIN
UPDATE `Requisitions`
SET
`vehicleId` = p_vehicleId,
`vehicleName` = p_vehicleName,
`loadingDate` = loadingDate,
`referenceNumber` = p_refId,
`notes` = p_notes,
`updatedAt` = now(),
`updatedBy` = p_createdBy,
`priority` = p_priority
WHERE `reqId` = p_editId;
DELETE from RequisitionDetails where requisitionId = p_editId;
set @reqLocationInsert = concat('INSERT INTO RequisitionDetails (requisitionId,billToBranchId,shipToBranchId,loadingBranchId,loadingLocationId,billToLocationId,shipToLocationId,skuId,skuQuantity,skuWeight,requisitionJson) VALUES',locationsString);
PREPARE stmt from @reqLocationInsert;
EXECUTE stmt;
select lastInsert as reqId;
END;
end if;
COMMIT;
END
И параметры, которые яПрохожу: call createRequisition (5, null, '(reqId, 137,137,137,2,2,2,493, {\ "billToId \": 137, \ "shipToId \": 137, \ "loadingId \": 137, \ "loadingLocationId \ ": 2, \" billToLocationId \ ": 2, \" shipToLocationId \ ": 2, \" skuId \ ": 493, \" skuWeight \ ": 30, \" loadingbranchName \ ": \" New Branch \ ", \ "loadingCompanyName \": \ "Teja & Teja Pvt. Ltd \", \ "loadingErpCode \": \ "WERT \", \ "loadingShortName \": \ "Калькутта \", \ "loadingLongName \": \ "Западная Бенгалия, Индия \ ", \" shipToCompanyName \ ": \" Teja & Teja Pvt. Ltd \ ", \" shipTobranchName \ ": \" New Branch \ ", \" shipToErpCode \ ": \" WERT \ ", \"shipToShortName \": \ "Калькутта \", \ "shipToLongName \": \ "Западная Бенгалия, Индия \", \ "billToBranchName \": \ "New Branch \", \ "billToCompanyName \": \ "Teja & TejaPvt. Ltd \ ", \" billToErpCode \ ": \" WERT \ ", \" billToShortName \ ": \" Калькутта \ ", \" billToLongName \ ": \" Западная Бенгалия, Индия \ ", \" skuQuantity \ ": 10}) ', 10, null,' 2019-10-18 ','111', 'Just Do It', '17', 2, 'Open Daala zzz', 1, 'HIGH', null)