mirror of
https://e.coding.net/circlecloud/DataStorage.git
synced 2024-12-04 04:08:53 +00:00
fix: 修复SQL错误
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
e28c3a00fb
commit
2d951d12a2
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>DataStorage</artifactId>
|
<artifactId>DataStorage</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1.1</version>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -13,6 +13,7 @@ import me.clip.placeholderapi.PlaceholderHook;
|
|||||||
import pw.yumc.YumCore.commands.CommandSub;
|
import pw.yumc.YumCore.commands.CommandSub;
|
||||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
import pw.yumc.YumCore.commands.annotation.Cmd;
|
||||||
import pw.yumc.YumCore.commands.annotation.Help;
|
import pw.yumc.YumCore.commands.annotation.Help;
|
||||||
|
import pw.yumc.YumCore.commands.annotation.Sort;
|
||||||
import pw.yumc.YumCore.commands.interfaces.Executor;
|
import pw.yumc.YumCore.commands.interfaces.Executor;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import pw.yumc.YumCore.sql.DataBase;
|
import pw.yumc.YumCore.sql.DataBase;
|
||||||
@ -68,9 +69,10 @@ public class DataStorage extends JavaPlugin implements Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sort(0)
|
||||||
@Cmd
|
@Cmd
|
||||||
@Help(value = "创建一个键值对", possibleArguments = "<键> <值>")
|
@Help(value = "创建一个键值对", possibleArguments = "<键> <值>")
|
||||||
public void create(CommandSender sender, String key, Integer value) {
|
public void create(CommandSender sender, String key, int value) {
|
||||||
try {
|
try {
|
||||||
if (createValue(key, value)) {
|
if (createValue(key, value)) {
|
||||||
sender.sendMessage("§a成功创建了 §3" + key + " §a初始值为 §d" + value);
|
sender.sendMessage("§a成功创建了 §3" + key + " §a初始值为 §d" + value);
|
||||||
@ -82,9 +84,10 @@ public class DataStorage extends JavaPlugin implements Executor {
|
|||||||
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sort(3)
|
||||||
@Cmd
|
@Cmd
|
||||||
@Help(value = "移除一个键值对", possibleArguments = "<键>")
|
@Help(value = "移除一个键值对", possibleArguments = "<键>")
|
||||||
public void remove(CommandSender sender, String key, Integer value) {
|
public void remove(CommandSender sender, String key, int value) {
|
||||||
try {
|
try {
|
||||||
if (removeValue(key)) {
|
if (removeValue(key)) {
|
||||||
sender.sendMessage("§a成功移除了 §3" + key);
|
sender.sendMessage("§a成功移除了 §3" + key);
|
||||||
@ -96,9 +99,10 @@ public class DataStorage extends JavaPlugin implements Executor {
|
|||||||
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sort(1)
|
||||||
@Cmd
|
@Cmd
|
||||||
@Help(value = "键key的值添加value", possibleArguments = "<键> <值>")
|
@Help(value = "键key的值添加value", possibleArguments = "<键> <值>")
|
||||||
public void add(CommandSender sender, String key, Integer value) {
|
public void add(CommandSender sender, String key, int value) {
|
||||||
try {
|
try {
|
||||||
if (incValue(key, value)) {
|
if (incValue(key, value)) {
|
||||||
sender.sendMessage("§a成功给了 §3" + key + " §a增加了 §e" + value + " §a目前的值为 §d" + getValue(key));
|
sender.sendMessage("§a成功给了 §3" + key + " §a增加了 §e" + value + " §a目前的值为 §d" + getValue(key));
|
||||||
@ -110,9 +114,10 @@ public class DataStorage extends JavaPlugin implements Executor {
|
|||||||
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sort(2)
|
||||||
@Cmd
|
@Cmd
|
||||||
@Help(value = "键key的值添加value", possibleArguments = "<键> <值>")
|
@Help(value = "键key的值添加value", possibleArguments = "<键> <值>")
|
||||||
public void del(CommandSender sender, String key, Integer value) {
|
public void del(CommandSender sender, String key, int value) {
|
||||||
try {
|
try {
|
||||||
if (decValue(key, value)) {
|
if (decValue(key, value)) {
|
||||||
sender.sendMessage("§a成功给了 §3" + key + " §c减少了 §e" + value + " §a目前的值为 §d" + getValue(key));
|
sender.sendMessage("§a成功给了 §3" + key + " §c减少了 §e" + value + " §a目前的值为 §d" + getValue(key));
|
||||||
@ -125,23 +130,23 @@ public class DataStorage extends JavaPlugin implements Executor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean createValue(String key, int value) throws SQLException {
|
private boolean createValue(String key, int value) throws SQLException {
|
||||||
return db.getDataBaseCore().update("INSERT INTO " + tableName + " (" + kfields + ", " + vfields + ") VALUES ('" + key + "', '" + value + "')") != 0;
|
return db.getDataBaseCore().update("INSERT INTO " + tableName + " (`" + kfields + "`, `" + vfields + "`) VALUES ('" + key + "', '" + value + "')") != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeValue(String key) throws SQLException {
|
private boolean removeValue(String key) throws SQLException {
|
||||||
return db.getDataBaseCore().update("DELETE FROM " + tableName + " WHERE " + kfields + " = '" + key + "'") != 0;
|
return db.getDataBaseCore().update("DELETE FROM " + tableName + " WHERE `" + kfields + "` = '" + key + "'") != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean incValue(String key, int value) throws SQLException {
|
private boolean incValue(String key, int value) throws SQLException {
|
||||||
return db.getDataBaseCore().update("UPDATE " + tableName + " SET " + vfields + " = " + vfields + " + " + value + " WHERE " + kfields + " = '" + key + "'") != 0;
|
return db.getDataBaseCore().update("UPDATE " + tableName + " SET `" + vfields + "` = " + vfields + " + " + value + " WHERE `" + kfields + "` = '" + key + "'") != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean decValue(String key, int value) throws SQLException {
|
private boolean decValue(String key, int value) throws SQLException {
|
||||||
return db.getDataBaseCore().update("UPDATE " + tableName + " SET " + vfields + " = " + vfields + " + " + value + " WHERE " + kfields + " = '" + key + "'") != 0;
|
return db.getDataBaseCore().update("UPDATE " + tableName + " SET `" + vfields + "` = `" + vfields + "` - " + value + " WHERE `" + kfields + "` = '" + key + "'") != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getValue(String key) throws SQLException {
|
private int getValue(String key) throws SQLException {
|
||||||
ResultSet result = db.getDataBaseCore().query("SELECT " + vfields + " FROM " + tableName + " WHERE " + kfields + " = '" + key + "' LIMIT 1");
|
ResultSet result = db.getDataBaseCore().query("SELECT `" + vfields + "` FROM " + tableName + " WHERE `" + kfields + "` = '" + key + "' LIMIT 1");
|
||||||
if (result.next()) { return result.getInt(1); }
|
if (result.next()) { return result.getInt(1); }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user