1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Addon skript-db 0.2.0

Sensible SQL support for Skript

  1. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    btk5h submitted a new resource:

    skript-db - Sensible SQL support for Skript

    Read more about this resource...
     
  2. Tai1er

    Tai1er New Member

    Joined:
    Jan 30, 2017
    Messages:
    7
    Likes Received:
    0
    Hi, :emoji_grinning:

    I have some problems with variables in query.
    When I try this,
    "execute "INSERT INTO Coordonnees (`id`,`region`) VALUES ('%{_x}%', 1)" in {sql}"

    I receive this mysql error:
    "Parameter index out of range (1 > number of parameters, which is 0)."

    It works normaly without %{_x}% in the query.
     
    #2 Tai1er, Nov 20, 2017
    Last edited: Nov 20, 2017
  3. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    This is a quirk caused by skript-db's automatic SQL injection protection. If you want to embed Skript expressions into a query, don't surround them in quotes or perform any escaping yourself. Skript-db will handle this part for you.

    Try removing the apostrophes around the expression like so:
    Code (Skript):
    1. execute "INSERT INTO Coordonnees (`id`,`region`) VALUES (%{_x}%, 1)" in {sql}
    --- Double Post Merged, Nov 21, 2017, Original Post Date: Nov 20, 2017 ---
    It's a bad idea to make IO operations block the main thread. Long running queries can halt the server for noticeable periods of time, creating undesirable server lag. The fact that functions cannot have wait statements is an issue that should be resolved on Skript's end.

    Although I've never used MundoSK myself, you might be able to workaround your issue using this feature.
     
  4. Tai1er

    Tai1er New Member

    Joined:
    Jan 30, 2017
    Messages:
    7
    Likes Received:
    0
    Thanks for your fast answer. :emoji_grinning:

    The async expression from MundoSK changes anythink.
    The expression "execute" is like a "wait" for Skript.
     
    #4 Tai1er, Nov 21, 2017
    Last edited: Nov 21, 2017
  5. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    There isn't really much you can do about this. The only workaround is using skquery functions which *are* compatible with async effects. I have used this a lot with reqn. They kinda suck, and skQuery shouldn't really be used anymore but at least it works. Another thing you can do is use mundosk custom events as functions and communicate the data through variables that you can grab with skript-mirror.
     
  6. MartinOdum

    MartinOdum Member

    Joined:
    Jan 26, 2017
    Messages:
    112
    Likes Received:
    13
    Hello, I'm switching from skellett's mysql to this and I ran into an issue
    Code (Skript):
    1. command /mysqltest:
    2.     trigger:
    3.         execute "INSERT INTO data (`uuid`, `displayname`, `username`, `first login`, `last login`) VALUES (%uuid of player%, %display name of player%, %name of player%, %year from date now%-%month from date now%-%day of month from date now% %hours from date now%:%minutes from date now%:00, %year from date now%-%month from date now%-%day of month from date now% %hours from date now%:%minutes from date now%:00)" in {x_sql}
    and this is my table setup, using skellett syntax but just to show the data types
    Code (Skript):
    1. mysql update "CREATE TABLE IF NOT EXISTS `data` (`uuid` varchar(255), `displayname` varchar(255), `username` varchar(255), `first login` DATETIME, `last login` DATETIME)"
    So when I ran that command there would not be any changes in the database and I figured maybe it was something within the date formatting since its so long that some character in there might be screwing with the syntax or something so I shortened it to the following and it worked:
    Code (Skript):
    1.  
    2. execute "INSERT INTO data (`uuid`, `displayname`, `username`) VALUES (%uuid of player%, %display name of player%, %name of player%)" in {x_sql}
    So basically my question is do you know why it doesn't work with the first code? I don't get any errors or anything it just doesn't insert any data in


    And this is what the database looks like, the first row is an input from a while ago using skellett's syntax and the second row is my shortened version of the code using skript-db
    [​IMG]
     
  7. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    I don't know the issue however the date formatting would be much better stored as epoch time
     
    MartinOdum likes this.
  8. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    skript-db doesn't support dates right now, so you'll need work around this using skript-db's unsafe expression to bypass SQL injection protection.
    Code (Skript):
    1.  
    2. set {_first login} to "'%year from date now%-%month from date now%-%day of month from date now% %hours from date now%:%minutes from date now%:00'"
    3. set {_last login} to "'%year from date now%-%month from date now%-%day of month from date now% %hours from date now%:%minutes from date now%:00'"
    4. execute "INSERT INTO data (`uuid`, `displayname`, `username`, `first login`, `last login`) VALUES (%uuid of player%, %display name of player%, %name of player%, %unsafe {_first login}%, %unsafe {_last login}%)" in {x_sql}
    Also, for future reference, skript-db errors are kept in a separate "last sql error" expression.
     
    MartinOdum likes this.
  9. MartinOdum

    MartinOdum Member

    Joined:
    Jan 26, 2017
    Messages:
    112
    Likes Received:
    13
    good idea, I'll probably switch to that, thanks!

    Ah i see, thanks for the info and quick reply!
     
  10. FUZIK

    FUZIK Active Member

    Joined:
    Jan 26, 2017
    Messages:
    115
    Likes Received:
    10
    please add to `todo` list :emoji_fingers_crossed:
    Code (Skript):
    1. command sql:
    2.     trigger:
    3.         execute "select `default` from `sql-database`" in {sql} and store result in {_test::*}
    4.         broadcast "test:%{_test::default::*}%"
    5.  
    6.         set {_arg} to "default"
    7.         execute "select %{_arg}% from `sql-database`" in {sql} and store result in {_test_arg::*}
    8.         broadcast "test_arg:%{_test_arg::%{_arg}%::*}%"
    Code (Skript):
    1. [INFO]: test:data and store
    2. [INFO]: test_arg:data, data and data
    ps this is bug report)
     
  11. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    Could you post more details about how your database and tables are set up so I can replicate this?
     
  12. FUZIK

    FUZIK Active Member

    Joined:
    Jan 26, 2017
    Messages:
    115
    Likes Received:
    10
    what information about the database do you need?
     
  13. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    From an empty database, what queries would I execute to set up tables and entries?
     
  14. pepper82

    pepper82 Member

    Joined:
    Jan 26, 2017
    Messages:
    272
    Likes Received:
    1
    I keep getting "Too many connections" error after some time (like when executing 5 insert - operations in a row). And my max-connections in mysql is set to 100. Are you closing them correctly?

    https://hastebin.com/upiviyifab.swift
     
    #14 pepper82, Nov 28, 2017
    Last edited: Nov 28, 2017
  15. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    That's strange, even if the connections weren't being closed correctly, the connection pool should be limited to 10 connections. I'll look into it, but I'll need more information to replicate this issue.
     
  16. pepper82

    pepper82 Member

    Joined:
    Jan 26, 2017
    Messages:
    272
    Likes Received:
    1
    What information do you need?
     
  17. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    159
    I just need enough information to reproduce the issue on my own machine.
     
  18. pepper82

    pepper82 Member

    Joined:
    Jan 26, 2017
    Messages:
    272
    Likes Received:
    1
    So there is the script that causes this error when you enter the command ~7 times in a row:

    Code (Skript):
    1. options:
    2.     database: yourdatabase
    3.     user: youruser
    4.     password: yourpassword
    5.  
    6. command /mysqlinsertcode:
    7.     trigger:
    8.         set {_code} to "test"
    9.         set {_sql} to the database "mysql://localhost:3306/{@database}?user={@user}&password={@password}&useSSL=false"
    10.         execute "INSERT INTO yourtable (`username`, `uuid`, `code`) VALUES (%name of player%, %uuid of player%, %{_code}%)" in {_sql}
    Database: Server-Version: 10.1.26-MariaDB - mariadb.org binary distribution
    Skript: latest bensku skript release
    Server: PaperSpigot (latest 1.12.2)
     
  19. xXAndrew28Xx

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    34
    Likes Received:
    23
    Medals:
    I wonder if this is a MariaDB specific issue. There is a JDBC driver for MariaDB.
     
  20. MartinOdum

    MartinOdum Member

    Joined:
    Jan 26, 2017
    Messages:
    112
    Likes Received:
    13
    Hey is there any way to run sql code under a return function? Basically I have a bank system and I'd like to have a function that would return the player's bank balance and then I would just run the function under async, the code below is what I'm talking about

    Code (Skript):
    1. function checkbankbalance(p: player) :: number:
    2.     async:
    3.         execute "select * from BankData where uuid = %{_p}'s uuid%" in {x_sql} and store the result in {_result::*}
    4.     if {_result::balance::*} is not set:
    5.         return 0
    6.     else:
    7.         set {_balance} to "%{_result::balance::*}%" parsed as number
    8.         return {_balance}
    9. command /bankbalance:
    10.     trigger:
    11.         async:
    12.             set {_balance} to checkbankbalance(player)
    13.         send "&aBank: &c$%{_balance}%" to player
    At the moment the code doesn't work I get the skript error: "A return statement after a delay is useless, as the calling trigger will resume when the delay starts..."
     

Share This Page

Loading...