Resource icon

Addon skript-db 0.2.0

  • 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!

So i had this working with skellett's syntax but i'm running into an (expected) issue now ith skript-db
code_language.skript:
command /isonline <string>:
        permission: *
        trigger:
                send "%isonline(arg-1)%"

function isonline(p: string) :: boolean:
        execute "SELECT server FROM playerdata.status WHERE ign='%{_p}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}
        if {_r} is set:
                return true
        else:
                return false
It now throws this:

A return statement after a delay is useless, as the calling trigger will resume when the delay starts (and won't get any returned value) (duel.sk, line 17: return false')

is there not a way to wait for the database to complete the request in functions like it was possible with skellett?

EDIT:
Oh, and i also get the error mentioned above using mariadb :emoji_frowning:
http://www.paste.org/88803
my max connections are set to 151. After i encounter that error the database becomes unaccessible for all other things too, i had to stop the minecraft server to free up connections again.

EDIT2:
tl;dr basically the issues of the 2 people before me
 
Last edited:
So i had this working with skellett's syntax but i'm running into an (expected) issue now ith skript-db
code_language.skript:
command /isonline <string>:
        permission: *
        trigger:
                send "%isonline(arg-1)%"

function isonline(p: string) :: boolean:
        execute "SELECT server FROM playerdata.status WHERE ign='%{_p}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}
        if {_r} is set:
                return true
        else:
                return false
It now throws this:

A return statement after a delay is useless, as the calling trigger will resume when the delay starts (and won't get any returned value) (duel.sk, line 17: return false')

is there not a way to wait for the database to complete the request in functions like it was possible with skellett?

EDIT:
Oh, and i also get the error mentioned above using mariadb :emoji_frowning:
http://www.paste.org/88803
my max connections are set to 151. After i encounter that error the database becomes unaccessible for all other things too, i had to stop the minecraft server to free up connections again.

EDIT2:
tl;dr basically the issues of the 2 people before me
The first issue isn't an issue. Skellett should not have functioned the way it does, only because its done badly can it be used in functions. You can use skquery functions if you would like to have a wait or other asynchronous effect and still return a value. Why are you even using sql to detect if someone is online?
 
The first issue isn't an issue. Skellett should not have functioned the way it does, only because its done badly can it be used in functions. You can use skquery functions if you would like to have a wait or other asynchronous effect and still return a value. Why are you even using sql to detect if someone is online?

yeah i know, i was a bit surprised when skellett worked like that out of the box but it was really handy and performed well. as a skript user i dont see a reason to moan about (hacky) workarounds, thats its primary use anyways :emoji_stuck_out_tongue:.
because i want to improve my knowledge about databases and their syntaxes,
also thats just an example.

hmm i tried doing it with skq functions but it didnt get me too far...
 
yeah i know, i was a bit surprised when skellett worked like that out of the box but it was really handy and performed well. as a skript user i dont see a reason to moan about (hacky) workarounds, thats its primary use anyways :emoji_stuck_out_tongue:.
because i want to improve my knowledge about databases and their syntaxes,
also thats just an example.

hmm i tried doing it with skq functions but it didnt get me too far...
I doubt it worked with Skellet to be honest, I'm sure it returned old values from the former call of the function instead of returning the actual value, just because how Skript works.

And skQ functions aren't hard to learn, it's just declaring the function:

code_language.skript:
func "isOnline":

Run your code, for example:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

then using the access pragma to access the variable with a transient object:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

  #you need use a transient object so the value gets passed correctly
  set transient "output" to {_r} != null

  $ access #this is called access pragma
  set {_isOnline} to transient "output"

And lastly, return so skQuery knows when you want return the value:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

  #you need use a transient object so the value gets passed correctly
  set transient "output" to {_r} != null

  $ access #this is called access pragma
  set {_isOnline} to transient "output"
  return

Now, you just have to access it:

code_language.skript:
command /isonline <string>:
  permission: *
  trigger:
    
    access "isOnline" from arg-1
    send "%{_isOnline}%"
 
  • Like
Reactions: L0v0lup
I doubt it worked with Skellet to be honest, I'm sure it returned old values from the former call of the function instead of returning the actual value, just because how Skript works.

And skQ functions aren't hard to learn, it's just declaring the function:

code_language.skript:
func "isOnline":

Run your code, for example:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

then using the access pragma to access the variable with a transient object:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

  #you need use a transient object so the value gets passed correctly
  set transient "output" to {_r} != null

  $ access #this is called access pragma
  set {_isOnline} to transient "output"

And lastly, return so skQuery knows when you want return the value:

code_language.skript:
func "isOnline":

  set {_player} to parameter 1
  execute "SELECT server FROM playerdata.status WHERE ign='%{_player}%' and (faction=true or safe=true or vanilla=true or lobby=true)" in {playerdatadb} and store result in {_r}

  #you need use a transient object so the value gets passed correctly
  set transient "output" to {_r} != null

  $ access #this is called access pragma
  set {_isOnline} to transient "output"
  return

Now, you just have to access it:

code_language.skript:
command /isonline <string>:
  permission: *
  trigger:
   
    access "isOnline" from arg-1
    send "%{_isOnline}%"
wow, this should be in the docs

awesome explanation, thank you
 
im trying to get the value of the field tokens but if i do

code_language.skript:
        execute "SELECT Tokens FROM Users WHERE Name='l'" in {sql} and store the result in {output::*}
        broadcast "SELECT Tokens FROM Users WHERE Name='l'"
        loop {output::*}:
            broadcast loop-value
        broadcast "%{output::*}%"
i get Tokens instead of the desired value
 
im trying to get the value of the field tokens but if i do

code_language.skript:
        execute "SELECT Tokens FROM Users WHERE Name='l'" in {sql} and store the result in {output::*}
        broadcast "SELECT Tokens FROM Users WHERE Name='l'"
        loop {output::*}:
            broadcast loop-value
        broadcast "%{output::*}%"
i get Tokens instead of the desired value
The first layer of the list variable contains the names of the columns. You want to loop through the second layer, or {output::Tokens::*}
 
I'm having the same issue as pepper82 and the others, when this skript gets loaded: https://gist.github.com/wokka1/b83a1494d5dc466d96bde204d5e4dad4 it creates 10 connections to mysql, from looking at show processlist at the console. If I reload the skript after an edit, it doesn't close those 10, but opens 10 more. They do not seem to close until you stop the minecraft server.

It's possible I have something in my code wrong, I'm not a programmer.

Also, my select statement works fine in the mysql console, but I'm getting "
set Invalid argument value: java.io.NotSerializableException to last database error" output via the last sql error statement.

This is running paperclip b1264, latest skript dev32c, skRayFall and skUtilities addons, plus several spigot/bukkit plugins. I can give you that list if needed for troubleshooting.

Thanks
 
Good evening,
Can you give me an example?
6dcb23a6fb.png
 
@btk5h would you prefer we open up issues on github for you on these reports or is this forum the best/easiest way for you?
 
@btk5h would you prefer we open up issues on github for you on these reports or is this forum the best/easiest way for you?
I would prefer if you guys created Github issues since they're a lot easier to track. I'll try to remember any issues brought up on the forums, but there's always the chance I'll forget.
 
Hi, :emoji_slight_smile:
Does Skript-db support NVAR?
I have problem with this for exemple:

set {_id} to "♂"
execute "INSERT INTO Table(`id`) VALUES (%{_id}%)" in {sql}

I get "?".
 
How can you list all the values you receive from SELECT query in one row?

Example:
execute "SELECT spieler,grund,strafe,moderator,datum,jailname FROM {@jail_table} WHERE spieler = %{_warnplayer}% AND strafe = 'WARNING'" in {sql} and store the result in {_output::*}

Now I want to list all the results in this format:
PLAYER: ABC - GRUND: ABC etc.
PLAYER: ABC - GRUND: ABC etc.
etc.
 
Last edited:
How can you list all the values you receive from SELECT query in one row?

Example:
execute "SELECT spieler,grund,strafe,moderator,datum,jailname FROM {@jail_table} WHERE spieler = %{_warnplayer}% AND strafe = 'WARNING'" in {sql} and store the result in {_output::*}

Now I want to list all the results in this format:
PLAYER: ABC - GRUND: ABC etc.
PLAYER: ABC - GRUND: ABC etc.
etc.
Entries in the same row share the same loop-index.
code_language.skript:
execute "SELECT spieler,grund,strafe,moderator,datum,jailname FROM {@jail_table} WHERE spieler = %{_warnplayer}% AND strafe = 'WARNING'" in {sql} and store the result in {_output::*}
loop {_output::spieler::*}:
  message "%loop-value% - %{_output::grund::%loop-index%}%"
 
  • Like
Reactions: pepper82
Hello,
I have error :/
code_language.skript:
HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)

Edit: After two or three requests my mysql is blocked and also blocks access with phpmyadmin.
Edit: I found, the connections are not closed at each reload, could you add an effect to close a connection to the database?
 
Last edited: