From b4f06444abb7d73f191545f3bb844fe411a030bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 3 Sep 2018 19:07:20 +0800 Subject: [PATCH] =?UTF-8?q?+=20SQLTable=20=E7=B1=BB=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BA=86=E5=87=A0=E4=B8=AA=E6=96=B9=E6=B3=95=20+=20SQLColumn?= =?UTF-8?q?=20=E7=B1=BB=E6=96=B0=E5=A2=9E=E5=85=B3=E4=BA=8E=20char=20?= =?UTF-8?q?=E7=9A=84=E6=9E=84=E9=80=A0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../taboolib/mysql/builder/SQLColumn.java | 28 +++++++++++++------ .../taboolib/mysql/builder/SQLTable.java | 6 +++- .../me/skymc/taboolib/other/NumberUtils.java | 19 +++++++++++++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 995be96..1ecd919 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.22 + 4.23 UTF-8 diff --git a/src/main/java/me/skymc/taboolib/mysql/builder/SQLColumn.java b/src/main/java/me/skymc/taboolib/mysql/builder/SQLColumn.java index cf7ce3f..dd6463f 100644 --- a/src/main/java/me/skymc/taboolib/mysql/builder/SQLColumn.java +++ b/src/main/java/me/skymc/taboolib/mysql/builder/SQLColumn.java @@ -22,7 +22,7 @@ public class SQLColumn { private SQLColumnOption[] columnOptions; /** - * 文本类型常用构造器 + * 文本 类型常用构造器 * new SQLColumn(SQLColumnType.TEXT, "username"); */ public SQLColumn(SQLColumnType columnType, String columnName) { @@ -30,7 +30,17 @@ public class SQLColumn { } /** - * 主键类型常用构造器 + * CHAR 类型常用构造器 + * + * @param columnType + * @param columnName + */ + public SQLColumn(SQLColumnType columnType, int m, String columnName) { + this(columnType, m, 0, columnName, null); + } + + /** + * 主键 类型常用构造器 * new SQLColumn(SQLColumnType.TEXT, "username", SQLColumnOption.PRIMARY_KEY, SQLColumnOption.AUTO_INCREMENT); */ public SQLColumn(SQLColumnType columnType, String columnName, SQLColumnOption... columnOptions) { @@ -38,7 +48,7 @@ public class SQLColumn { } /** - * 数据类型常用构造器 + * 数据 类型常用构造器 * new SQLColumn(SQLColumnType.TEXT, "player_group", "PLAYER"); */ public SQLColumn(SQLColumnType columnType, String columnName, Object defaultValue) { @@ -99,25 +109,25 @@ public class SQLColumn { for (SQLColumnOption options : columnOptions) { switch (options) { case NOTNULL: - builder.append(" not null"); + builder.append(" NOT NULL"); break; case PRIMARY_KEY: - builder.append(" primary key"); + builder.append(" PRIMARY KEY"); break; case AUTO_INCREMENT: - builder.append(" auto_increment"); + builder.append(" AUTO_INCREMENT"); break; case UNIQUE_KEY: - builder.append(" unique key"); + builder.append(" UNIQUE KEY"); break; default: } } if (defaultValue != null) { if (defaultValue instanceof String) { - builder.append(" default '").append(defaultValue).append("'"); + builder.append(" DEFAULT '").append(defaultValue).append("'"); } else { - builder.append(" default ").append(defaultValue); + builder.append(" DEFAULT ").append(defaultValue); } } return builder.toString(); diff --git a/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java b/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java index 601195d..5cdb888 100644 --- a/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java +++ b/src/main/java/me/skymc/taboolib/mysql/builder/SQLTable.java @@ -60,7 +60,11 @@ public class SQLTable { return executeQuery("select * from " + tableName + " where " + where); } - public RunnableUpdate executeUpdate(String where, String update) { + public RunnableQuery executeSelect() { + return executeQuery("select * from " + tableName); + } + + public RunnableUpdate executeUpdate(String update, String where) { return executeUpdate("update " + tableName + " set " + update + " where " + where); } diff --git a/src/main/java/me/skymc/taboolib/other/NumberUtils.java b/src/main/java/me/skymc/taboolib/other/NumberUtils.java index 988dd4c..f811baa 100644 --- a/src/main/java/me/skymc/taboolib/other/NumberUtils.java +++ b/src/main/java/me/skymc/taboolib/other/NumberUtils.java @@ -3,6 +3,9 @@ package me.skymc.taboolib.other; import java.text.DecimalFormat; import java.util.Random; +/** + * @author sky + */ public class NumberUtils { private static Random random = new Random(); @@ -52,6 +55,22 @@ public class NumberUtils { } } + public static Boolean getBooleanAbbreviation(String str) { + if (str == null || str.isEmpty()) { + return false; + } + if (str.length() < 4) { + char var = str.charAt(0); + if (var == 'y' || var == 'Y' || var == 't' || var == 'T' || var == '1') { + return true; + } + if (var == 'n' || var == 'N' || var == 'f' || var == 'F' || var == '0') { + return false; + } + } + return getBoolean(str); + } + @Deprecated public static Random getRand() { return random;