Compare commits

...

15 Commits

Author SHA1 Message Date
Govindass
b2a53078a6 add gradle fatJar task 2020-05-02 20:02:25 +03:00
Govindas
83f71e147b
Update HikariCP, should fix a lot of issues 2020-05-02 19:48:35 +03:00
Govindass
e610fc1357 Remove unused class 2020-05-02 19:30:48 +03:00
Govindass
aa1a1d14c7
add synchronous 2019-09-30 15:28:32 +03:00
Govindass
3a1ec76a0b
Delete EffSyncExecuteStatement.java 2019-09-30 15:27:26 +03:00
Govindass
2eb691cd69
Delete EffExecuteStatement.java 2019-09-30 15:27:16 +03:00
Govindass
6dbd2effb3
Delete plugin.yml 2019-09-30 15:26:48 +03:00
Govindass
88b76f1b5b
Add files via upload 2019-09-30 15:25:37 +03:00
Bryan Terce
b692047878
0.2.1 Hotfix 2019-06-26 01:56:29 -07:00
Bryan Terce
3e57cae866
Fix sync execute logic (fixes #16) 2019-06-26 01:55:08 -07:00
Bryan Terce
1e95b818eb
0.2.0 Update 2019-06-22 12:12:27 -07:00
Bryan Terce
688ea9d46b
Manually fix README 2019-06-22 12:11:29 -07:00
Bryan Terce
dd6d574479
Update README 2019-06-22 12:09:59 -07:00
Bryan Terce
1f6091eb95
Add synchronous execution flag 2019-06-22 12:09:17 -07:00
Bryan Terce
74d4918f44
Fix lifespan syntax 2019-06-22 12:05:22 -07:00
6 changed files with 73 additions and 42 deletions

View File

@ -3,35 +3,21 @@
> Sensible SQL support for Skript.
---
### Expression `Data Source` => `datasource`
Stores the connection information for a data source. This should be saved to a variable in a
`script load` event or manually through an effect command.
The url format for your database may vary! The example provided uses a MySQL database.
#### Syntax
```
[the] data(base|[ ]source) [(of|at)] %string%
```
#### Examples
```
set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
```
---
### Effect `Execute Statement`
Executes a statement on a database and optionally stores the result in a variable. Expressions
embedded in the query will be escaped to avoid SQL injection.
<p>
If a single variable, such as `{test}`, is passed, the variable will be set to the number of
affected rows.
<p>
If a list variable, such as `{test::*}`, is passed, the query result will be mapped to the list
variable in the form `{test::<column name>::<row number>}`
Specifying `synchronously` will make skript-db execute the query on the event thread, which is useful for async
events. Note that skript-db will ignore this flag if you attempt to run this on the main thread.
#### Syntax
```
execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in) [the] [var[iable]] %-objects%]
[synchronously] execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in) [the] [var[iable]] %-objects%]
```
#### Examples
@ -39,7 +25,7 @@ execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|
execute "select * from table" in {sql} and store the result in {output::*}
```
```
execute "select * from %{table variable}%" in {sql} and store the result in {output::*}
execute "select * where player=%{player}%" in {sql} and store the result in {output::*}
```
---
@ -70,3 +56,20 @@ execute unsafe {fully dynamic query} in {sql}
---
### Expression `Data Source` => `datasource`
Stores the connection information for a data source. This should be saved to a variable in a
`script load` event or manually through an effect command.
The url format for your database may vary! The example provided uses a MySQL database.
#### Syntax
```
[the] data(base|[ ]source) [(of|at)] %string% [with [a] [max[imum]] [connection] life[ ]time of %timespan%]"
```
#### Examples
```
set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
```
---

View File

@ -1,5 +1,5 @@
group 'com.btk5h.skript-db'
version '0.1.1'
version '0.2.1'
buildscript {
repositories {
@ -31,7 +31,7 @@ repositories {
dependencies {
shadow 'org.spigotmc:spigot-api:1.11-R0.1-SNAPSHOT'
shadow 'ch.njol:skript:2.2-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.6.2'
compile 'com.zaxxer:HikariCP:3.4.3'
}
task buildReadme(type: Javadoc) {
@ -43,3 +43,13 @@ task buildReadme(type: Javadoc) {
options.addStringOption('file', 'README.md')
options.addStringOption('markdown', '-quiet')
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.mkyong.DateUtils'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.btk5h.skriptdb.SkriptDB

View File

@ -41,18 +41,19 @@ import ch.njol.util.Kleenean;
* If a list variable, such as `{test::*}`, is passed, the query result will be mapped to the list
* variable in the form `{test::<column name>::<row number>}`
*
* Specifying `synchronously` will make skript-db execute the query on the event thread, which is useful for async
* events. Note that skript-db will ignore this flag if you attempt to run this on the main thread.
*
* @name Execute Statement
* @pattern execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in)
* @pattern [synchronously] execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in)
* [the] [var[iable]] %-objects%]
* @example execute "select * from table" in {sql} and store the result in {output::*}
* @example execute "select * from %{table variable}%" in {sql} and store the result in {output::*}
* @example execute "select * where player=%{player}%" in {sql} and store the result in {output::*}
* @since 0.1.0
*/
public class EffExecuteStatement extends Delay {
static {
Skript.registerEffect(EffExecuteStatement.class,
"execute %string% (in|on) %datasource% " +
"[and store [[the] (output|result)[s]] (to|in) [the] [var[iable]] %-objects%]");
Skript.registerEffect(EffExecuteStatement.class, "[(1¦synchronously)] execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in) [the] [var[iable]] %-objects%]");
}
static String lastError;
@ -65,9 +66,25 @@ public class EffExecuteStatement extends Delay {
private VariableString var;
private boolean isLocal;
private boolean isList;
private boolean isSync;
private void continueScriptExecution(Event e, String res) {
lastError = res;
if (getNext() != null) {
TriggerItem.walk(getNext(), e);
}
}
@Override
protected void execute(Event e) {
boolean isMainThread = Bukkit.isPrimaryThread();
if (isSync) {
String result = executeStatement(e);
continueScriptExecution(e, result);
} else {
CompletableFuture<String> sql =
CompletableFuture.supplyAsync(() -> executeStatement(e), threadPool);
@ -76,20 +93,17 @@ public class EffExecuteStatement extends Delay {
err.printStackTrace();
}
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
lastError = res;
if (getNext() != null) {
TriggerItem.walk(getNext(), e);
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> continueScriptExecution(e, res));
});
}
});
});
}
@Override
protected TriggerItem walk(Event e) {
debug(e, true);
if (!isSync) {
SkriptUtil.delay(e);
}
execute(e);
return null;
}
@ -251,6 +265,7 @@ public class EffExecuteStatement extends Delay {
}
dataSource = (Expression<HikariDataSource>) exprs[1];
Expression<?> expr = exprs[2];
isSync = parseResult.mark == 1;
if (expr instanceof Variable) {
Variable<?> varExpr = (Variable<?>) expr;
var = SkriptUtil.getVariableName(varExpr);

View File

@ -32,7 +32,7 @@ public class ExprDataSource extends SimpleExpression<HikariDataSource> {
static {
Skript.registerExpression(ExprDataSource.class, HikariDataSource.class,
ExpressionType.COMBINED, "[the] data(base|[ ]source) [(of|at)] %string% " +
"[with [a] [max[imum]] [connection] life[ ]time of %timespan%]");
"[with [a] [max[imum]] [connection] life[ ]time of %-timespan%]");
}
private static Map<String, HikariDataSource> connectionCache = new HashMap<>();

View File

@ -1,4 +1,4 @@
name: skript-db
version: 0.1.1
version: 0.3.0-Govindas
main: com.btk5h.skriptdb.SkriptDB
depend: [Skript]