Denizen Script Commands


Commands are always written with a '-' before them, and are the core component of any script, the primary way to cause things to happen.
Learn about how commands work in The Beginner's Guide.


Showing 1 out of 175 commands...
NameSQL
Syntaxsql [id:<ID>] [disconnect/connect:<server> (username:<username>) (password:<secret>) (ssl:true/{false})/query:<query>/update:<update>]
Short DescriptionInteracts with a MySQL server.
Full DescriptionThis command is used to interact with a MySQL server. It can update the database or query it for information.

This commands exists primarily for interoperability with pre-existing databases and external services.
It should never be used for storing data that only Denizen needs to use. Consider instead using Command:flag.

The general usage order is connect -> update/query -> disconnect.
It is not required that you disconnect right after using, and in fact encouraged that you keep a connection open where possible.

When connecting, the server format is IP:Port/Database, EG 'localhost:3306/test'.
You can also append options to the end, like 'localhost:3306/test?autoReconnect=true'
Store your password in the Denizen secrets file at 'plugins/Denizen/secrets.secret'. Refer to ObjectTypeSecretTag for usage info.

You can switch whether SSL is used for the connection (defaults to false).

Note that when using tag, it is recommended you escape unusual inputs to avoid SQL injection.

The SQL command is merely a wrapper for SQL queries, and further usage details should be gathered from an official MySQL query reference rather than from Denizen command help.

SQL connections are not instant - they can take several seconds, or just never connect at all.
It is recommended you hold the command by doing "- ~sql ..." rather than just "- sql ..."
as this will delay the commands following the SQL command until after the SQL operation is complete.

If you have an SQL database server other than MySQL, be sure to include the driver prefix (defaults to "mysql://" when unspecified).
Related Tags<entry[saveName].result_list> returns a ListTag of all row ListTags from a query or update command. That's a ListTag of ListTags, so for example to get the second entry of the first row you'd use "result_list.get[1].get[2]"
<entry[saveName].affected_rows> returns how many rows were affected by an update command.
<util.sql_connections> Returns a list of all SQL connections opened by Command:sql.
Usage Example
#Use to connect to an SQL server.
- ~sql id:name connect:localhost:3306/test username:space password:<secret[sql_pw]>
Usage Example
#Use to connect to an SQL server over an SSL connection.
- ~sql id:name connect:localhost:3306/test username:space password:<secret[sql_pw]> ssl:true
Usage Example
#Use to connect to an SQL server with a UTF8 text encoding.
- ~sql id:name connect:localhost:3306/test?characterEncoding=utf8 username:space password:<secret[sql_pw]>
Usage Example
#Use to update an SQL server.
- ~sql id:name "update:CREATE table things(id int,column_name1 varchar(255),column_name2 varchar(255));"
Usage Example
#Use to update an SQL server.
- ~sql id:name "update:INSERT INTO things VALUES (3, 'hello', 'space');"
Usage Example
#Use to query an SQL server.
- ~sql id:name "query:SELECT id,column_name1,column_name2 FROM things;" save:saveName
- narrate <entry[saveName].result_list>
Usage Example
#Use to query an SQL server.
- ~sql id:name "query:SELECT id,column_name1,column_name2 FROM things WHERE id=3;" save:saveName2
- narrate <entry[saveName2].result_list>
Usage Example
#Use to disconnect from an SQL server.
- sql disconnect id:name
Groupcore
Sourcehttps://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/core/SQLCommand.java#L34