Hi all,
I'm trying to convert my app to using MySQL, I've converted the tables without any problems, right now I did one procedure by hand... I don't know 100% if it's okay...under SQL I was able to add it , only thing is I don't know how to execute it even from the query :
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUser`(IN OP varchar(10),
IN ID int,
IN Name varchar(50),
IN Password varchar(50),
IN Rights int,
IN ModifierID int,
IN ModifyDate datetime,
IN LockedUserID int,
OUT BackID int ,
OUT ERROR int
)
BEGIN
DECLARE locked int;
DECLARE CheckInsert int;
DECLARE CheckModify int;
SET CheckInsert = 0;
SET CheckModify = 0;
SELECT count(*) INTO CheckInsert from User where Name=@Name;
SELECT count(*) INTO CheckModify from User where Name=@Name and id<>@id;
select locked = ifnull(Locked, 0) from User where ID = @ID;
IF @OP='LOCK' THEN
IF @lock=0 THEN
UPDATE User set Locked=1,LockedUserID=@LockedUserID
where ID=@ID;
END IF;
IF @lock=1 THEN
UPDATE User set Locked=0,LockedUserID=''
where ID=@ID;
END IF;
END IF;
IF @OP='INS' THEN
IF (CheckInsert = 0) THEN
INSERT INTO User(Name,Password,Rights,ModifierID,ModifyDate)
VALUES(ltrim(rtrim(@Name)), ltrim(rtrim(@Password)), @Rights, @ModifierID, @ModifyDate);
SELECT @ERROR = '0';
SELECT @BackID = IDENT_CURRENT('[User]');
ELSE
SELECT @ERROR='1';
END IF;
END IF;
IF @OP='UPD' THEN
IF (CheckModify = 0) THEN
UPDATE User SET Name=ltrim(rtrim(@Name)),
Password=ltrim(rtrim(@Password)),
Rights=@Rights,
ModifierID=@ModifierID,
ModifyDate=@ModifyDate
where ID=@ID;
SELECT @ERROR='0';
ELSE
SELECT @ERROR='1';
END IF;
END IF;
IF @OP='DEL' THEN
DELETE FROM User where ID=@ID;
END IF;
END
I've tried : CALL spUser('INS','11','Test','test','1','0','2014-05-26 00:13:00','0','0','0') , but it complains about last 2 variables, which our OUT , I don't know why I need to specify it here... : Error Code: 1414. OUT or INOUT argument 9 for routine _planb.spUser is not a variable or NEW pseudo-variable in BEFORE trigger
Anyway from Lazarus, I was able to connect to this db by using MySQL protocol, I was able to select a table and display data... but for some reason when I insert a ZStoredProcedure , it does not display available Stored Procedures (under MSSQL 2008 r2 it does get them...) so I manually entered them by name spUser , and manually added the 10 parameters...but then it complains about Syntax error.
Can someone point out the mistake here ?
Greetings
Robert