· 6 years ago · Jul 04, 2019, 06:02 PM
1script options:
2 $ db url jdbc:mysql://IP:3306/DATABASE
3 $ db username USER
4 $ db password PASSWORD
5
6options:
7 Table: TABLENAME
8
9
10on load:
11 update "CREATE TABLE IF NOT EXISTS `{@Table}` (`id` varchar(255),`value` varchar(255))"
12 update "ALTER TABLE {@Table} ADD UNIQUE (id, value)"
13
14function thisMySQLUpdatevalue(id:text, value:text) :: text:
15 set {_SetResult::*} to objects in column "id" from result of query "SELECT * FROM {@Table} WHERE id = '%{_id}%'" and close
16 set {_GetResult} to false
17 loop {_SetResult::*}:
18 If loop-value is {_id}:
19 set {_GetResult} to true
20 If {_GetResult} is false:
21 update "INSERT INTO `{@Table}` (`id`,`value`) valueS ('%{_id}%', '%{_value}%')"
22 return "&e%{_id}% &ahas been succesfully &5&lCREATED &awith value &e%{_value}% &ain table &b{@Table}"
23 else:
24 update "UPDATE `{@Table}` SET `value` = '%{_value}%' WHERE `{@Table}`.`id` ='%{_id}%'"
25 return "&e%{_id}% &ahas been succesfully &5&lUPDATED &awith value &e%{_value}% &ain table &b{@Table}"
26
27function thisMySQLRemovevalue(id:text) :: text:
28 set {_SetResult::*} to objects in column "id" from result of query "SELECT * FROM {@Table} WHERE id = '%{_id}%'" and close
29 set {_GetResult} to false
30 loop {_SetResult::*}:
31 If loop-value is {_id}:
32 set {_GetResult} to true
33 If {_GetResult} is true:
34 update "DELETE FROM {@Table} WHERE id = '%{_id}%'"
35 return "&e%{_id}% &ahas been succesfully &5&lDELETED &afrom table &b{@Table}"
36 else:
37 return "&cid &e%{_id}% &ccouldn't be found in table &b{@Table}"
38
39function thisMySQLReadvalue(id:text) :: text:
40 set {_SetResult::*} to objects in column "value" from result of query "SELECT * FROM {@Table} WHERE id = '%{_id}%'" and close
41 delete {_GetResult}
42 loop {_SetResult::*}:
43 If loop-value is set:
44 set {_GetResult} to loop-value
45 If {_GetResult} is set:
46 return "&aThe value of &b%{_id}% &ais &b%{_GetResult}% &ain table &b{@Table}"
47 else:
48 return "&cid &e%{_id}% &ccouldn't be found in table &b{@Table}"
49
50command /mysql [<text>] [<text>] [<text>]:
51 trigger:
52 If arg-1 is not set:
53 message " &c>> &6/mysql update <id> <value>"
54 message " &c>> &6/mysql remove <id>"
55 message " &c>> &6/mysql read <id>"
56 else:
57 If arg-1 is not "update", "remove" or "read":
58 message " &c>> &6/mysql update <id> <value>"
59 message " &c>> &6/mysql remove <id>"
60 message " &c>> &6/mysql read <id>"
61 else:
62 If arg-1 is "update":
63 If arg-2 is not set:
64 message "&c>> Please enter an id"
65 stop
66 If arg-3 is not set:
67 message "&c>> Please enter a value"
68 stop
69 set {_getResult} to thisMySQLUpdatevalue(arg-2, arg-3)
70 message " &c>> %{_getResult}%"
71 If arg-1 is "remove":
72 If arg-2 is not set:
73 message "&c>> Please enter an id"
74 stop
75 set {_getResult} to thisMySQLRemovevalue(arg-2)
76 message " &c>> %{_getResult}%"
77 If arg-1 is "read":
78 If arg-2 is not set:
79 message "&c>> Please enter an id"
80 stop
81 set {_getResult} to thisMySQLReadvalue(arg-2)
82 message " &c>> %{_getResult}%"