poggit / libasynql

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

The variable `foo` is not used anywhere in the query! Check for typos. #86

Closed xqwtxon closed 1 year ago

xqwtxon commented 1 year ago

Stack Error Message

Error: The variable kills is not used anywhere in the query! Check for typos.
File: virions/src/poggit/libasynql/generic/GenericStatementImpl
Line: 187

Table

-- #{ setKills
-- #    :player_name string
-- #    :kills int
INSERT OR IGNORE INTO Practice (player_name, kills) VALUES (:player_name, 0);
-- #&
UPDATE Practice SET kills = :kills WHERE player_name = :player_name;
-- #}
-- #{ getKills
-- #    :player_name string
SELECT kills FROM Practice WHERE player_name = :player_name; 
-- #}

Code

<?php

declare(strict_types=1);

namespace PrideCore\Utils;

use poggit\libasynql\libasynql;
use poggit\libasynql\DataConnector;
use pocketmine\utils\SingletonTrait;
use pocketmine\utils\Config;
use PrideCore\Core;

class Database {
    use SingletonTrait;

    public function getDatabase() : DataConnector{
        return libasynql::create(Core::getInstance(), $this->getConfig()->get("database"), [
            "sqlite" => "sqlite.sql",
            "mysql" => "mysql.sql",
        ]);
    }

    public function getConfig() : Config{
        return new Config(Core::getInstance()->getDataFolder() . "database.yml", Config::YAML);
    }

    public function init() : void{
        $this->getDatabase()->executeGeneric("init");
        $this->getDatabase()->waitAll();
    }
}

Screenshots or Links

Screenshot_2022_0912_220952

Endermanbugzjfc commented 1 year ago

TL;DR

A variable is treated as unused if you do not use it in the first statement of -- #&.

xqwtxon commented 1 year ago

Check full statements provided in the attachements.

SOF3 commented 1 year ago

cannot be reproduced with the latest master by taking your SQL code above and prepending -- #!sqlite in front. Can you upload your file directly?

xqwtxon commented 1 year ago

cannot be reproduced with the latest master by taking your SQL code above and prepending -- #!sqlite in front. Can you upload your file directly?

the full statement file sqlite.sql is uploaded on above.

Im using sqlite based to my config.

Endermanbugzjfc commented 1 year ago

cannot be reproduced with the latest master by taking your SQL code above and prepending -- #!sqlite in front. Can you upload your file directly?

the full statement file sqlite.sql is uploaded on above.

Im using sqlite based to my config.

You do not have -- #!sqlite at the heading. Your file is not even correct.

SOF3 commented 1 year ago

please upload the exact file you had a problem with ,not copy paste. I suspect you have some invisible characters there.

xqwtxon commented 1 year ago

Hello???

SOF3 commented 1 year ago

@xqwtxon I said, do not copy-paste the file, including pastebin. Upload your file directly by dragging the file into this webpage, or by clicking the upload bar below the comment box.

xqwtxon commented 1 year ago

@xqwtxon I said, do not copy-paste the file, including pastebin. Upload your file directly by dragging the file into this webpage, or by clicking the upload bar below the comment box.

Screenshot_2022_0914_145645

Leafres commented 1 year ago

@xqwtxon Put it in a ZIP file

xqwtxon commented 1 year ago

@xqwtxon Put it in a ZIP file

mysql.sql.zip

SOF3 commented 1 year ago

Your error is on these lines

-- #{ setWins
-- #    :player_name string
-- #    :kills int
INSERT OR IGNORE INTO Practice (player_name, wins) VALUES (:player_name, 0);
-- #&
UPDATE Practice SET wins = :wins WHERE player_name = :player_name;
-- #}

you wrote :wins instead of :kills

however I agree that the error message needs improvement to reflect which statement is wrong.