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!

Hello, i've found a strange bug what is probably caused by skript-db.
Whenever i use the line 3, i cant get the %event-block% anymore. It always tells me "air".
code_language.skript:
on break:
    set {_sk_ID} to "%x-coord of event-block%,%y-coord of event-block%,%z-coord of event-block%"
    execute "SELECT * FROM `SkriptJobs` WHERE `sk_ID` = '%unsafe {_sk_ID}%'" in {sql} and store result in {_output::*}
event-block%,%z-coord of event-block%'"
    send "%event-block%"

You might think now; Just store the event-block in a local variable?
code_language.skript:
set {_block} to event-block
That works only for a moment and i'm getting the right block-type. But (!) when placed after line 3 it tells me again "Air". Is skript-db affecting variables? It seems like they are getting changed when i use that line.

Do you have any idea why this happens?
 
code_language.skript:
        execute "UPDATE nickname SET nick='%arg 1%' WHERE player_name='%name of player%'" in {sql}

Although I wrote this code, it does not work. How can do it?
 
Hello, i've found a strange bug what is probably caused by skript-db.
Whenever i use the line 3, i cant get the %event-block% anymore. It always tells me "air".
code_language.skript:
on break:
    set {_sk_ID} to "%x-coord of event-block%,%y-coord of event-block%,%z-coord of event-block%"
    execute "SELECT * FROM `SkriptJobs` WHERE `sk_ID` = '%unsafe {_sk_ID}%'" in {sql} and store result in {_output::*}
event-block%,%z-coord of event-block%'"
    send "%event-block%"

You might think now; Just store the event-block in a local variable?
code_language.skript:
set {_block} to event-block
That works only for a moment and i'm getting the right block-type. But (!) when placed after line 3 it tells me again "Air". Is skript-db affecting variables? It seems like they are getting changed when i use that line.

Do you have any idea why this happens?
Did you try setting the variable to type of event-block instead?

This is not a bug. Skript's event-block refers to the live state of the block, not a snapshot of the block when the event was dispatched. You can see this by replacing the query with a delay.
code_language.skript:
        execute "UPDATE nickname SET nick='%arg 1%' WHERE player_name='%name of player%'" in {sql}

Although I wrote this code, it does not work. How can do it?
When you embed variables in a query, do not surround it in quotes.
 
Thanks for the reply :emoji_slight_smile:
I found a solution:
set {_block} to "%event-block%" parsed as item type
 
code_language.skript:
command /ap-update <text>:
    trigger:
        broadcast "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%"
        execute "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%" in {sql}

This code don't work. How can fix this?
[doublepost=1529576073,1529504667][/doublepost]
code_language.skript:
command /ap-update <text>:
    trigger:
        broadcast "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%"
        execute "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%" in {sql}

This code don't work. How can fix this?
Can someone help me?
 
code_language.skript:
command /ap-update <text>:
    trigger:
        broadcast "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%"
        execute "UPDATE nickname SET balance=%balance of arg 1% WHERE playername=%arg 1%" in {sql}

This code don't work. How can fix this?
[doublepost=1529576073,1529504667][/doublepost]
Can someone help me?
Please post whatever errors you're getting.
 
There's nothing in last sql error?

I found the problem.

This code run:
code_language.skript:
command /ap-update <text>:
    trigger:
        execute "UPDATE nickname SET balance='100' WHERE playername=%arg 1%" in {sql}

But if I do "% balance of arg 1%", it does not work.
 
Hey, sorry its me again with the same problem :/
It seems like the new Skript dev37 Update has broken the option to use local variables with skript-db completley.

code_language.skript:
set {_x} to "%x-coord of event-block%"
set {_y} to "%y-coord of event-block%"
set {_z} to "%z-coord of event-block%"
set {_world} to "%event-world%" parsed as text
execute "SELECT * FROM SkriptJobs WHERE X=%{_x}% and (Y=%{_y}% and Z=%{_z}% and World=%{_World}%)" in {sql} and store result in {_output}
(Not working - none of the local variables are usable, it only works with standard variable, which would produce a massiv variable.csv) - But that worked in Skript dev36 :emoji_astonished:

I have also tried to use after the "Select":
code_language.skript:
set {_block} to "%event-block%" parsed as item type
#Or
%type of event-block%
which arent working anymore on Skript dev37+ :emoji_frowning:
Is there a way you can fix that? I kinda works with Skellett but that isnt an option for me, since its Skellett's mysql strings are not working.
 
Hey, sorry its me again with the same problem :/
It seems like the new Skript dev37 Update has broken the option to use local variables with skript-db completley.

code_language.skript:
set {_x} to "%x-coord of event-block%"
set {_y} to "%y-coord of event-block%"
set {_z} to "%z-coord of event-block%"
set {_world} to "%event-world%" parsed as text
execute "SELECT * FROM SkriptJobs WHERE X=%{_x}% and (Y=%{_y}% and Z=%{_z}% and World=%{_World}%)" in {sql} and store result in {_output}
(Not working - none of the local variables are usable, it only works with standard variable, which would produce a massiv variable.csv) - But that worked in Skript dev36 :emoji_astonished:

I have also tried to use after the "Select":
code_language.skript:
set {_block} to "%event-block%" parsed as item type
#Or
%type of event-block%
which arent working anymore on Skript dev37+ :emoji_frowning:
Is there a way you can fix that? I kinda works with Skellett but that isnt an option for me, since its Skellett's mysql strings are not working.
Are you getting any errors?
 
Yes, it basically say's that the variables are empty.
Nl16h0J.jpg

Also, every other used local variables are empty after i use "execute "SELECT * FROM (...)"
Bensku wrote into his changelog, that he "Fixed local variables being local to events instead of triggers"
Maybe that caused the current problem?
 
So is there any way to use "return {_something}" in skript functions while using "execute "SELECT..."?
I know that there are SkQuery functions, but they are unecessary complicated and there are no syntax or examples for it...

Also:

code_language.skript:
    execute "SELECT `wave` FROM `infected` WHERE `arenaID` = %{_arena}%" in {sql.minigames} and store the result in {_r::*}
    broadcast "%{_r::wave::1}%"

Returns "true", but it should broadcast wave number.
[doublepost=1532027095,1532025950][/doublepost]Found the problem:

Skript-db returns true or false if your column type is tinyint.
Not funny ;-;
 
So is there any way to use "return {_something}" in skript functions while using "execute "SELECT..."?
I know that there are SkQuery functions, but they are unecessary complicated and there are no syntax or examples for it...

Also:

code_language.skript:
    execute "SELECT `wave` FROM `infected` WHERE `arenaID` = %{_arena}%" in {sql.minigames} and store the result in {_r::*}
    broadcast "%{_r::wave::1}%"

Returns "true", but it should broadcast wave number.
[doublepost=1532027095,1532025950][/doublepost]Found the problem:

Skript-db returns true or false if your column type is tinyint.
Not funny ;-;
Skript's functions expect your code to return without delays. skript-db delays your code until a response is returned to prevent your server from freezing. You can use skript-mirror's custom effects for this.
 
Skript's functions expect your code to return without delays. skript-db delays your code until a response is returned to prevent your server from freezing. You can use skript-mirror's custom effects for this.
code_language.skript:
effect getPlayerAmount %string%:
    trigger:
        delay the effect
        execute "SELECT `playersAmt` FROM `infected` WHERE `arenaID` = %expr-1%" in {sql.minigames} and store the result in {_r::*}
        return {_r::playersAmt::1}

Error:
code_language.skript:
The return statement can only be used in a function (afunctions.sk, line 22: return {_r::playersAmt::1}')

@btk5h how can I return value using skript-mirror's effects?
 
Last edited:
code_language.skript:
[00:57:59 WARN]: java.util.concurrent.CompletionException: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:sqlite:/C:/Users/Me/Desktop/TEST/plugins/jobs.db
[00:57:59 WARN]:        at java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
[00:57:59 WARN]:        at java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
[00:57:59 WARN]:        at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
[00:57:59 INFO]: [Skript] Successfully reloaded test.sk.
[00:57:59 WARN]:        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[00:57:59 WARN]:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[00:57:59 WARN]:        at java.lang.Thread.run(Unknown Source)
[00:57:59 WARN]: Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:sqlite:/C:/Users/Me/Desktop/TEST/plugins/jobs.db
[00:57:59 WARN]:        at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:88)
[00:57:59 WARN]:        at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:325)
[00:57:59 WARN]:        at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114)
[00:57:59 WARN]:        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:104)
[00:57:59 WARN]:        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:97)
[00:57:59 WARN]:        at com.btk5h.skriptdb.skript.EffExecuteStatement.executeStatement(EffExecuteStatement.java:104)
[00:57:59 WARN]:        at com.btk5h.skriptdb.skript.EffExecuteStatement.lambda$execute$1(EffExecuteStatement.java:72)
[00:57:59 WARN]:        ... 4 more
[00:57:59 WARN]: Caused by: java.sql.SQLException: No suitable driver
[00:57:59 WARN]:        at java.sql.DriverManager.getDriver(Unknown Source)
[00:57:59 WARN]:        at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:81)
[00:57:59 WARN]:        ... 10 more
>

code_language.skript:
on load:
    set {test} to the database "sqlite:/C:/Users/Me/Desktop/TEST/plugins/jobs.db"
    execute unsafe "CREATE TABLE IF NOT EXISTS `sqlite` (`ID` int(11) NOT NULL AUTO_INCREMENT,primary key (id))" in {test}

i'm doing it wrong?
 
Is it possible to have multiple sql statements within the same query? i tried to separate them using a semicone but it somehow rejects those
 
@btk5h How can I use the result from this query in a message:

SELECT SUM(amount) FROM `currency` WHERE 1

I tried:
execute "SELECT SUM(amount) FROM `currency` WHERE 1;" in {_sql} and store the result in {_r::*}
message "&2%{_r::1}% Dollar"

But does not work.
[doublepost=1548688936,1545079366][/doublepost]Can mysql stuff be used in functions?
[doublepost=1548763778][/doublepost]I can not get it to work in 1.13.2. Always receiving this error:
https://i.imgur.com/8st6iEf.png
[doublepost=1550052818][/doublepost]Any update on the error, yet? Is thi plugin abandoned?