I’ve created stored procedure which accepts XML as varchar. It accept two input parameter One is having customer data which gets inserted into Customer table & Other is related to address of customer which gets inserted into address table. Issue is with second parameter. Only customer data is getting inserted into the Customer table where as nothing gets inserted into Address table. I’ve executed procedure from MySQL with same parameter (which is getting passed from c#) and data is getting inserted into both tables.
Below is the code
DreamFactory.Model.Database.StoredProcParam oCustomerParam = new DreamFactory.Model.Database.StoredProcParam();
oCustomerParam.Name = “CustomerXML”;
oCustomerParam.ParamType = “IN”;
oCustomerParam.Type = “Varchar”;
oCustomerParam.Length = 1000;
oCustomerParam.Value = customerXML;
DreamFactory.Model.Database.StoredProcParam oAddressParam = new DreamFactory.Model.Database.StoredProcParam();
oAddressParam.Name = "AddressXML";
oAddressParam.ParamType = "IN";
oAddressParam.Type = "Varchar";
oAddressParam.Length = 1000;
oAddressParam.Value = addressXML;
DreamFactory.Model.Database.StoredProcParam[] Params = new DreamFactory.Model.Database.StoredProcParam[2];
Params[0] = oCustomerParam;
Params[1] = oAddressParam;
databaseAPI.CallStoredProcAsync(“AddCustomer”, Params);
----------------------------------------PROCEDURE---------------------------------
DELIMITER $$
CREATE DEFINER=root
@localhost
PROCEDURE AddCustomer
(CustomerXML Varchar(1000), AddressXML VARCHAR(1000))
BEGIN
DECLARE XML varchar(100);
DECLARE i INT; DECLARE CountElement INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SELECT ‘An error has occurred, operation rollbacked and the stored procedure was terminated’;
END;
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
ROLLBACK;
SELECT ‘An error has occurred, operation rollbacked and the stored procedure was terminated’;
END;
START TRANSACTION;
INSERT INTO Customer(FirstName, LastName, isActive, CreatedOn)
(SELECT extractValue(CustomerXML,’/Customers/Customer[1]/FirstName/text()’),
extractValue(CustomerXML,’/Customers/Customer[1]/LastName/text()’),1, CURDATE());
SET @CustomerID = LAST_INSERT_ID();
/INSERT INTO Names(Third)VALUES(@CustomerID);/
SET i = 1;
SET CountElement = ExtractValue(@AddressXML, ‘(Count(/Addresses/Address))’);
WHILE i <= CountElement Do
INSERT INTO Address(CustomerID, Street, State, City, Zip, OwnerName)
(SELECT @CustomerID, extractValue(AddressXML,’/Addresses/Address[$i]/Street/text()’),
extractValue(AddressXML,’/Addresses/Address[$i]/State/text()’),
extractValue(AddressXML,’/Addresses/Address[$i]/City/text()’),
extractValue(AddressXML,’/Addresses/Address[$i]/Zip/text()’),
extractValue(AddressXML,’/Addresses/Address[$i]/OwnerName/text()’));
SET i = i + 1;
END WHILE;
COMMIT;
END
AM I MISSING SOMETHING