FredyH / MySQLOO

MySQLOO
GNU Lesser General Public License v2.1
138 stars 55 forks source link

Can't create procedures #107

Closed ApertureDevelopment closed 2 years ago

ApertureDevelopment commented 2 years ago

I don't know why this is happening, but since my SQL syntax works as intended with the mysql client and MySQL workbench, I assume that this is a problem caused by mysqloo.

Basically I am unable to create procedures because I am getting SQL syntax errors. But the thing is, it works just as intended when running directly using the mysql client or mysql workbench. This is certainly a issue when trying to avoid issues such as auto_increment gaps

This is the query I am trying to run:

DELIMITER ESL

CREATE PROCEDURE msync_createUser(IN pro_steamid VARCHAR(20), IN pro_steamid64 VARCHAR(17), IN pro_nickname VARCHAR(30), IN pro_joined DATETIME)
BEGIN
    IF EXISTS(SELECT p_user_id FROM tbl_users WHERE steamid64=pro_steamid64 AND steamid=pro_steamid) THEN
        -- check nickname
        IF (SELECT nickname FROM tbl_users WHERE steamid64=pro_steamid64) != pro_nickname THEN
            UPDATE tbl_users SET nickname=pro_nickname WHERE steamid64=pro_steamid64;
        END IF;
    ELSE
        -- CREATE USER
        INSERT INTO tbl_users (steamid, steamid64, nickname, joined )
        VALUES (
            pro_steamid,
            pro_steamid64,
            pro_nickname,
            pro_joined
        );
    END IF;
END ESL

DELIMITER ;

I am running it as

local procedure = database:query([[
--query
]])
procedure:start()

It seems that running any query containing the DELIMITED paramater will cause this issue, but not when being executed on the server directly

FredyH commented 2 years ago

The reason this does not work is because DELIMITED is not an SQL command but rather a keyword that the mysql CLI uses to split queries into single statements. Try creating the procedure without the DELIMITER command and it should work.

ApertureDevelopment commented 2 years ago

Alright, this issue was on me. I thought I needed to set the delimited to something else to not get issues with the semicolons. But yeah, One only needs to do that for the MySQL client