query has not been loaded: libasynql issue

Discussion in 'Development' started by Atomization, Apr 13, 2019.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    111
    i keep getting this error:
    Code:
    InvalidArgumentException: "The query afterlife.checkplayer has not been loaded"
    here is my sql file and code:

    PHP:
    -- #!mysql
    -- #{ afterlife
    -- #  { init
    CREATE TABLE IF NOT EXISTS afterlife(
      
    id int(11AUTO_INCREMENT PRIMARY KEY NOT NULL,
      
    name varchar(30NOT NULL,
      
    kills int(5NOT NULL,
      
    deaths int(5NOT NULL,
      
    ratio FLOAT NOT NULL,
      
    totalXP int(5NOT NULL,
      
    xp int(5NOT NULL,
      
    level int(5NOT NULL,
      
    streak int(5NOT NULL
    );
    -- 
    #  }
    -- #  { checkplayer
    -- #    :name
    SELECT COUNT(*) FROM afterlife WHERE name = :name;
    -- 
    #  }
    -- #}
    the identifier `afterlife.init` works and `afterlife.checkplayer` does not. Why?

    PHP:
    <?php
    // Main class

    class Main extends PluginBase {

        public static 
    $instance;

        public function 
    onEnable() : void {
            
    self::$instance $this;
            
    DataHandler::create();
        }

        public function 
    onDisable() : void {
            
    DataHandler::disConnect();
        }

        public static function 
    getInstance() : Main {
            return 
    self::$instance;
        }
    }

    // DataHandler class

    use poggit\libasynql\libasynql;
    use 
    poggit\libasynql\DataConnector;

    class 
    DataHandler {

        public static 
    $database;

        public static function 
    create () {
            
    $main Main::getInstance();

            
    self::$database libasynql::create($main$main->getConfig()->get("database"), [
                
    "mysql" => "mysql.sql"
            
    ]);

            
    self::$database->executeGeneric("afterlife.init"); // this query works
            
    self::$database->waitAll();
        }

        public static function 
    disConnect () {
            if(isset(
    self::$database)) self::getDatabase()->close();
        }

        public static function 
    getDatabase() : DataConnector {
            return 
    self::$database;
        }
    }
    and im trying to select a query onJoin to see if the player exists in the db or not
    PHP:
    public function onJoin(PlayerJoinEvent $event) {  
        
    DataHandler::getDatabase()->executeSelect("afterlife.checkplayer", ['name' => $event->getPlayer()->getName()]);
    }
     
    Last edited: Apr 14, 2019
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,555
    GitHub:
    muqsit
    Case sensitivity perhaps? Try afterlife.checkplayer instead of afterlife.checkPlayer.
    If your id column's values are non-negative, you may want to change it's data type to INT UNSIGNED... to allocate more space. See: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
     
    Last edited: Apr 14, 2019
  3. Atomization

    Atomization Baby Zombie

    Messages:
    111
    that did not fix my issue
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,910
    GitHub:
    sof3
    I can't spot the problem by just inspecting your code. Consider trying the `libasynql def` command and see what queries are detected:
    Code:
    php libasynql.phar def src Queries resources/mysql.sql
    
     
  5. Atomization

    Atomization Baby Zombie

    Messages:
    111
    i found my problem... i created my sql file inside of my plugins data folder, NOT my plugins resource folder.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,910
    GitHub:
    sof3
    Then how came the first query worked o_O
     
  7. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    I think the one on the resource folder is outdated
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.