poggit / libasynql

Asynchronous MySQL access library for PocketMine plugins.
https://poggit.github.io/libasynql
Apache License 2.0
132 stars 44 forks source link

Cannot register stored procedure #68

Closed Ree-jp closed 2 years ago

Ree-jp commented 2 years ago

Describe the bug Cannot register stored procedure

Sample code

$this->db->executeGeneric("coral_reef.init.functions.values.add");
-- #!mysql
-- #{ coral_reef
-- #    { init
-- #        { functions
-- #            { values
-- #                { add
DELIMITER //
CREATE PROCEDURE "add_value"(IN _xuid BIGINT, IN _type VARCHAR(99), IN _subtype VARCHAR(99), IN _value INT)
BEGIN
    SELECT value
    INTO @get_value
    FROM VIRTUAL_VALUES
    WHERE xuid = _xuid
      AND type = _type
      AND subtype = _subtype;

    SET @int_value = CAST(@get_value AS SIGNED) + _value;

    INSERT INTO VIRTUAL_VALUES
    VALUES (_xuid, _type, _subtype, @int_value)
    ON DUPLICATE KEY UPDATE value = @int_value;
END //
DELIMITER ;
-- #                }
-- #            }
-- #        }
-- #    }
-- #}

Expected behavior register stored procedure

Environment OS: docker(debian) PocketMine version: 3.25.0

Error contents

SQL EXECUTION error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //
CREATE PROCEDURE "add_value"(IN _xuid BIGINT, IN _type VARCHAR(9...' at line 1, for query DELIMITER //
CREATE PROCEDURE "add_value"(IN _xuid BIGINT, IN _type VARCHAR(99), IN _subtype VARCHAR(99), IN _value INT)
BEGIN
SELECT value
INTO @get_value
FROM VIRTUAL_VALUES
WHERE xuid = _xuid
AND type = _type
AND subtype = _subtype;
SET @int_value = CAST(@get_value AS SIGNED) + _value;
INSERT INTO VIRTUAL_VALUES
VALUES (_xuid, _type, _subtype, @int_value)
ON DUPLICATE KEY UPDATE value = @int_value;
END //
DELIMITER ; | []

When I ran this query directly, it registered successfully image

SOF3 commented 2 years ago

Delimiter is a command for the MySQL CLI client, not a regular query. Libasynql has the same rules as mysqli::query().

Try deleting the two DELIMITER statements.

Ree-jp commented 2 years ago

thank you!