Welcome to SkriptTools.net!

SkriptTools is now part of the skUnity family! skUnity will keep SkriptTools running, updating and adding new features.


- You can now search scripts by author by doing "author:name". For example: "author:nfell2009"

- Login to SkriptTools using your skUnity account to save your favourite scripts and come back to them

Login

Script Viewer

View the code of the script directly in your browser without downloading anything.

Current File: Skript_MySQL.sk - Download / View on the skUnity Parser

# // (C) LeVence

script options:
    $ db url jdbc:mysql://$URL:$PORT/$DATABASE
    $ db username $USER
    $ db password $PASSWORD

options:
	Table: $TABLE


on load:
	update "CREATE TABLE IF NOT EXISTS `{@Table}` (`ID` varchar(255),`Value` varchar(255))"
	update "ALTER TABLE {@Table} ADD UNIQUE (ID, Value)"

function thisMySQLUpdateValue(id:text, value:text) :: text:
	set {_SetResult::*} to objects in column "ID" from result of query "SELECT * FROM {@Table} WHERE ID = '%{_id}%'" and close
	set {_GetResult} to false
	loop {_SetResult::*}:
		If loop-value is {_id}:
			set {_GetResult} to true
	If {_GetResult} is false:
		update "INSERT INTO `{@Table}` (`ID`,`Value`) VALUES ('%{_id}%', '%{_value}%')"
		return "&e%{_id}% &ahas been succesfully &5&lCREATED &awith value &e%{_value}% &ain table &b{@Table}"
	else:
		update "UPDATE `{@Table}` SET `Value` = '%{_value}%' WHERE `{@Table}`.`ID` ='%{_id}%'"
		return "&e%{_id}% &ahas been succesfully &5&lUPDATED &awith value &e%{_value}% &ain table &b{@Table}"
	
function thisMySQLRemoveValue(id:text) :: text:
	set {_SetResult::*} to objects in column "ID" from result of query "SELECT * FROM {@Table} WHERE ID = '%{_id}%'" and close
	set {_GetResult} to false
	loop {_SetResult::*}:
		If loop-value is {_id}:
			set {_GetResult} to true
	If {_GetResult} is true:
		update "DELETE FROM {@Table} WHERE ID = '%{_id}%'"
		return "&e%{_id}% &ahas been succesfully &5&lDELETED &afrom table &b{@Table}"
	else:
		return "&cID &e%{_id}% &ccouldn't be found in table &b{@Table}"

function thisMySQLReadValue(id:text) :: text:
	set {_SetResult::*} to objects in column "Value" from result of query "SELECT * FROM {@Table} WHERE ID = '%{_id}%'" and close
	delete {_GetResult}
	loop {_SetResult::*}:
		If loop-value is set:
			set {_GetResult} to loop-value
	If {_GetResult} is set:
		return "&aThe value of &b%{_id}% &ais &b%{_GetResult}% &ain table &b{@Table}"
	else:
		return "&cID &e%{_id}% &ccouldn't be found in table &b{@Table}"

command /mysql [<text>] [<text>] [<text>]:
	trigger:
		If arg-1 is not set:
			message " &c>> &6/mysql update <id> <value>"
			message " &c>> &6/mysql remove <id>"
			message " &c>> &6/mysql read <id>"
		else:
			If arg-1 is not "update", "remove" or "read":
				message " &c>> &6/mysql update <id> <value>"
				message " &c>> &6/mysql remove <id>"
				message " &c>> &6/mysql read <id>"
			else:
				If arg-1 is "update":
					If arg-2 is not set:
						message "&c>> Please enter an ID"
						stop
					If arg-3 is not set:
						message "&c>> Please enter a value"
						stop
					set {_getResult} to thisMySQLUpdateValue(arg-2, arg-3)
					message " &c>> %{_getResult}%"
				If arg-1 is "remove":
					If arg-2 is not set:
						message "&c>> Please enter an ID"
						stop
					set {_getResult} to thisMySQLRemoveValue(arg-2)
					message " &c>> %{_getResult}%"
				If arg-1 is "read":
					If arg-2 is not set:
						message "&c>> Please enter an ID"
						stop
					set {_getResult} to thisMySQLReadValue(arg-2)
					message " &c>> %{_getResult}%"