poggit / libasynql

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

Error: "Unsupported variable type" when type is valid. #51

Closed ghost closed 3 years ago

ghost commented 3 years ago

Description: I am executing a 'Insert' query with 2 string variables. Valid variable types are being passed to those variables, but I am getting a "Unsupported variable type" exception.

Sample code

public function registerPlayer($player, string $setting): void{
        if($player instanceof Player) $player = $player->getName();
        if(!$this->isPlayerRegistered($player)){
            $this->playerData[strtolower($player)] = ["username" => $player, "setting" => $setting];
            $this->database->executeInsert("manage.register", ["player" => $player, "setting" => $setting]);
        }
    }
-- #    { register
-- #      :player string
-- #      :setting string
INSERT INTO player_form_settings
VALUES
(
username = :player,
setting = :setting
);
-- #    }
$this->registerPlayer("Dapro5173", "formui");

Expected behavior A row is inserted into the table: username -> Dapro5173, setting -> formui

Environment OS: Windows 10 PocketMine version: 3.18.0

SOF3 commented 3 years ago

What database type are you using?

SOF3 commented 3 years ago

Please provide a full error if possible.

ghost commented 3 years ago

Full Error

I am using MySQL (self hosted, MariaDB).

ghost commented 3 years ago

The 'create table' query works fine.

SOF3 commented 3 years ago

Could you try to modify this and show the value of $variable->getType()? https://github.com/poggit/libasynql/blob/0192bcd58db0ef25160ec49f309eb2417e4726ac/libasynql/src/poggit/libasynql/generic/MysqlStatementImpl.php#L69

ghost commented 3 years ago

'string' is echoed when I do:

echo $variable->getType();
SOF3 commented 3 years ago

That'd be strange. This line is supposed to handle that case. Can you var_dump() it and check if it is really string(6) "string"? https://github.com/poggit/libasynql/blob/0192bcd58db0ef25160ec49f309eb2417e4726ac/libasynql/src/poggit/libasynql/generic/MysqlStatementImpl.php#L85

ghost commented 3 years ago

I can confirm that it returns string(6) "string".

I was playing around with things and fixed the issue. However, it is passing NULL to the table instead of the strings. Not sure if this is on my end or the virions. (Most likely mine).

ghost commented 3 years ago

It is an issue with the virion.

$this->database->executeInsert("manage.register", ["player" => "Dapro5173", "setting" => "formui"]);
-- #    { register
-- #      :player string
-- #      :setting string
INSERT INTO player_form_settings
VALUES
(
username = :player,
setting = :setting
);
SOF3 commented 3 years ago

This doesn't make sense just by reading the code. Could you try to debug why the switch-case with string doesn't return?

CortexPE commented 3 years ago

Try

INSERT INTO `player_form_settings` (`username`, `setting`) VALUES (:player,
:setting);

On Sat, Mar 20, 2021, 11:18 Chan Kwan Yin @.***> wrote:

This doesn't make sense just by reading the code. Could you try to debug why the switch-case with string doesn't return?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/poggit/libasynql/issues/51#issuecomment-803235396, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEHQQFBE6GPBBVWE2BMWDGDTEQHXLANCNFSM4ZNSSCWA .

SOF3 commented 3 years ago

that shouldn't affect this bug

Muqsit commented 3 years ago

It might be that the \pocketmine\Player import is missing or has a typo in it.

Btw, shouldn't it be VALUES(:player, :setting) rather than VALUES(username = :player, setting = :setting)?

SOF3 commented 3 years ago

yes it should be, but that shouldn't cause the crash above.

ghost commented 3 years ago

The import is correct. I've tried using: VALUES(:player, :setting) and it worked. The unsupported variable error no longer shows, so I assume I fixed it without realizing it. Thank you for all your help!

SOF3 commented 3 years ago

how could that be even relevant...