Name | SQL |
Syntax | sql [id:<ID>] [disconnect/connect:<server> (username:<username>) (password:<secret>) (ssl:true/{false})/query:<query>/update:<update>] |
Short Description | Interacts with a MySQL server. |
Full Description | This 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 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 SecretTag 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 sql.
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Group | core |
Source | https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/core/SQLCommand.java#L34 |