+ SQLTable 类新增了几个方法

+ SQLColumn 类新增关于 char 的构造器
This commit is contained in:
坏黑 2018-09-03 19:07:20 +08:00
parent 9585dab04d
commit b4f06444ab
4 changed files with 44 additions and 11 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId> <groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId> <artifactId>TabooLib</artifactId>
<version>4.22</version> <version>4.23</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -22,7 +22,7 @@ public class SQLColumn {
private SQLColumnOption[] columnOptions; private SQLColumnOption[] columnOptions;
/** /**
* 文本类型常用构造器 * 文本 类型常用构造器
* new SQLColumn(SQLColumnType.TEXT, "username"); * new SQLColumn(SQLColumnType.TEXT, "username");
*/ */
public SQLColumn(SQLColumnType columnType, String columnName) { 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); * new SQLColumn(SQLColumnType.TEXT, "username", SQLColumnOption.PRIMARY_KEY, SQLColumnOption.AUTO_INCREMENT);
*/ */
public SQLColumn(SQLColumnType columnType, String columnName, SQLColumnOption... columnOptions) { public SQLColumn(SQLColumnType columnType, String columnName, SQLColumnOption... columnOptions) {
@ -38,7 +48,7 @@ public class SQLColumn {
} }
/** /**
* 数据类型常用构造器 * 数据 类型常用构造器
* new SQLColumn(SQLColumnType.TEXT, "player_group", "PLAYER"); * new SQLColumn(SQLColumnType.TEXT, "player_group", "PLAYER");
*/ */
public SQLColumn(SQLColumnType columnType, String columnName, Object defaultValue) { public SQLColumn(SQLColumnType columnType, String columnName, Object defaultValue) {
@ -99,25 +109,25 @@ public class SQLColumn {
for (SQLColumnOption options : columnOptions) { for (SQLColumnOption options : columnOptions) {
switch (options) { switch (options) {
case NOTNULL: case NOTNULL:
builder.append(" not null"); builder.append(" NOT NULL");
break; break;
case PRIMARY_KEY: case PRIMARY_KEY:
builder.append(" primary key"); builder.append(" PRIMARY KEY");
break; break;
case AUTO_INCREMENT: case AUTO_INCREMENT:
builder.append(" auto_increment"); builder.append(" AUTO_INCREMENT");
break; break;
case UNIQUE_KEY: case UNIQUE_KEY:
builder.append(" unique key"); builder.append(" UNIQUE KEY");
break; break;
default: default:
} }
} }
if (defaultValue != null) { if (defaultValue != null) {
if (defaultValue instanceof String) { if (defaultValue instanceof String) {
builder.append(" default '").append(defaultValue).append("'"); builder.append(" DEFAULT '").append(defaultValue).append("'");
} else { } else {
builder.append(" default ").append(defaultValue); builder.append(" DEFAULT ").append(defaultValue);
} }
} }
return builder.toString(); return builder.toString();

View File

@ -60,7 +60,11 @@ public class SQLTable {
return executeQuery("select * from " + tableName + " where " + where); 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); return executeUpdate("update " + tableName + " set " + update + " where " + where);
} }

View File

@ -3,6 +3,9 @@ package me.skymc.taboolib.other;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Random; import java.util.Random;
/**
* @author sky
*/
public class NumberUtils { public class NumberUtils {
private static Random random = new Random(); 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 @Deprecated
public static Random getRand() { public static Random getRand() {
return random; return random;