2017-11-19 03:49:49 +00:00
|
|
|
# skript-db
|
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
> Sensible SQL support for Skript.
|
|
|
|
---
|
2017-11-19 03:49:49 +00:00
|
|
|
|
|
|
|
### Expression `Data Source` => `datasource`
|
2017-11-22 00:58:47 +00:00
|
|
|
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.
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
The url format for your database may vary! The example provided uses a MySQL database.
|
2017-11-19 03:49:49 +00:00
|
|
|
#### Syntax
|
2017-11-22 00:58:47 +00:00
|
|
|
```
|
|
|
|
[the] data(base|[ ]source) [(of|at)] %string%
|
|
|
|
```
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
#### Examples
|
2017-11-19 03:49:49 +00:00
|
|
|
```
|
2017-11-19 04:13:13 +00:00
|
|
|
set {sql} to the database "mysql://localhost:3306/mydatabase?user=admin&password=12345&useSSL=false"
|
2017-11-19 03:49:49 +00:00
|
|
|
```
|
|
|
|
|
2017-11-19 03:52:52 +00:00
|
|
|
---
|
|
|
|
|
2017-11-19 03:49:49 +00:00
|
|
|
### Effect `Execute Statement`
|
2017-11-22 00:58:47 +00:00
|
|
|
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.
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
If a single variable, such as `{test}`, is passed, the variable will be set to the number of
|
|
|
|
affected rows.
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
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>}`
|
2017-11-19 03:49:49 +00:00
|
|
|
#### Syntax
|
2017-11-22 00:58:47 +00:00
|
|
|
```
|
|
|
|
execute %string% (in|on) %datasource% [and store [[the] (output|result)[s]] (to|in) [the] [var[iable]] %-objects%]
|
|
|
|
```
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
#### Examples
|
2017-11-19 03:49:49 +00:00
|
|
|
```
|
|
|
|
execute "select * from table" in {sql} and store the result in {output::*}
|
2017-11-22 00:58:47 +00:00
|
|
|
```
|
|
|
|
```
|
2017-11-19 03:49:49 +00:00
|
|
|
execute "select * from %{table variable}%" in {sql} and store the result in {output::*}
|
|
|
|
```
|
|
|
|
|
2017-11-19 03:52:52 +00:00
|
|
|
---
|
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
### Expression `Last Data Source Error` => `text`
|
|
|
|
Stores the error from the last executed statement, if there was one.
|
2017-11-19 03:49:49 +00:00
|
|
|
#### Syntax
|
|
|
|
```
|
2017-11-22 00:58:47 +00:00
|
|
|
[the] [last] (sql|db|data(base|[ ]source)) error
|
2017-11-19 03:49:49 +00:00
|
|
|
```
|
|
|
|
|
2017-11-19 03:52:52 +00:00
|
|
|
---
|
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
### Expression `Unsafe Expression` => `text`
|
|
|
|
Opts out of automatic SQL injection protection for a specific expression in a statement.
|
2017-11-19 03:49:49 +00:00
|
|
|
#### Syntax
|
2017-11-22 00:58:47 +00:00
|
|
|
```
|
|
|
|
unsafe %text%
|
|
|
|
```
|
2017-11-19 03:49:49 +00:00
|
|
|
|
2017-11-22 00:58:47 +00:00
|
|
|
#### Examples
|
|
|
|
```
|
|
|
|
execute "select %unsafe {columns variable}% from %{table variable}%" in {sql}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
execute unsafe {fully dynamic query} in {sql}
|
|
|
|
```
|
2017-11-19 03:52:52 +00:00
|
|
|
|
|
|
|
---
|
2017-11-22 00:58:47 +00:00
|
|
|
|