Rename VARCHAR to varchar

This commit is contained in:
Rsl1122 2017-08-16 18:38:19 +03:00
parent 5204d52d78
commit 268dae902f
10 changed files with 66 additions and 13 deletions

View File

@ -0,0 +1,39 @@
package main.java.com.djrapitops.plan.database.sql;
import main.java.com.djrapitops.plan.Log;
public class Select extends SqlParser {
private int conditions = 0;
public Select(String start) {
super(start);
}
public static Select from(String table, String... columns) {
Select parser = new Select("SELECT ");
int size = columns.length;
for (int i = 0; i < size; i++) {
if (size > 1 && i > 0) {
parser.append(", ");
}
parser.append(columns[i]);
}
parser.append(" FROM ").append(table);
Log.debug(parser.toString());
return parser;
}
public Select where(String... conditions) {
append(" WHERE ");
for (int i = 0; i < conditions.length; i++) {
if (this.conditions > 0) {
append(" AND ");
}
append("(").append(conditions[i]).append(")");
this.conditions++;
}
return this;
}
}

View File

@ -6,7 +6,11 @@ public class Sql {
public static final String LONG = "bigint";
public static final String BOOL = "boolean";
public static String VARCHAR(int length) {
private Sql() {
throw new IllegalStateException("Variable Class");
}
public static String varchar(int length) {
return "varchar("+length+")";
}
}

View File

@ -93,6 +93,16 @@ public class TableSqlParser extends SqlParser {
return this;
}
/**
* Used for ALTER TABLE sql statements.
*
* @param column column to modify
* @return TableSqlParser object
*/
public static TableSqlParser newColumn(String column, String type) {
return new TableSqlParser("").column(column, type);
}
@Override
public String toString() {
append(")");

View File

@ -38,7 +38,7 @@ public class CommandUseTable extends Table {
public boolean createTable() {
try {
execute(TableSqlParser.createTable(tableName)
.column(columnCommand, Sql.VARCHAR(20)).notNull()
.column(columnCommand, Sql.varchar(20)).notNull()
.column(columnTimesUsed, Sql.INT).notNull()
.toString()
);

View File

@ -40,7 +40,7 @@ public class IPsTable extends UserIDTable {
try {
execute(TableSqlParser.createTable(tableName)
.column(columnUserID, Sql.INT).notNull()
.column(columnIP, Sql.VARCHAR(20)).notNull()
.column(columnIP, Sql.varchar(20)).notNull()
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
.toString()
);

View File

@ -45,7 +45,7 @@ public class KillsTable extends Table {
execute(TableSqlParser.createTable(tableName)
.column(columnKillerUserID, Sql.INT).notNull()
.column(columnVictimUserID, Sql.INT).notNull()
.column(columnWeapon, Sql.VARCHAR(30)).notNull()
.column(columnWeapon, Sql.varchar(30)).notNull()
.column(columnDate, Sql.LONG).notNull()
.foreignKey(columnKillerUserID, usersTable.getTableName(), usersTable.getColumnID())
.foreignKey(columnVictimUserID, usersTable.getTableName(), usersTable.getColumnID())

View File

@ -40,7 +40,7 @@ public class NicknamesTable extends UserIDTable {
try {
execute(TableSqlParser.createTable(tableName)
.column(columnUserID, Sql.INT).notNull()
.column(columnNick, Sql.VARCHAR(75)).notNull()
.column(columnNick, Sql.varchar(75)).notNull()
.column(columnCurrent, Sql.BOOL).notNull().defaultValue(false)
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
.toString()

View File

@ -37,8 +37,8 @@ public class SecurityTable extends Table {
public boolean createTable() {
try {
execute(TableSqlParser.createTable(tableName)
.column(columnUser, Sql.VARCHAR(100)).notNull().unique()
.column(columnSaltedHash, Sql.VARCHAR(100)).notNull().unique()
.column(columnUser, Sql.varchar(100)).notNull().unique()
.column(columnSaltedHash, Sql.varchar(100)).notNull().unique()
.column(columnPermLevel, Sql.INT).notNull()
.toString()
);

View File

@ -99,9 +99,9 @@ public class UsersTable extends Table {
try {
execute(TableSqlParser.createTable(tableName)
.primaryKeyIDColumn(usingMySQL, columnID, Sql.INT)
.column(columnUUID, Sql.VARCHAR(36)).notNull().unique()
.column(columnGeolocation, Sql.VARCHAR(50)).notNull()
.column(columnLastGM, Sql.VARCHAR(15)).notNull()
.column(columnUUID, Sql.varchar(36)).notNull().unique()
.column(columnGeolocation, Sql.varchar(50)).notNull()
.column(columnLastGM, Sql.varchar(15)).notNull()
.column(columnLastGMSwapTime, Sql.LONG).notNull()
.column(columnPlayTime, Sql.LONG).notNull()
.column(columnLoginTimes, Sql.INT).notNull()
@ -110,10 +110,10 @@ public class UsersTable extends Table {
.column(columnMobKills, Sql.INT).notNull()
.column(columnRegistered, Sql.LONG).notNull()
.column(columnOP, Sql.BOOL).notNull().defaultValue(false)
.column(columnName, Sql.VARCHAR(16)).notNull()
.column(columnName, Sql.varchar(16)).notNull()
.column(columnBanned, Sql.BOOL).notNull().defaultValue(false)
.column(columnContainsBukkitData, Sql.BOOL).notNull().defaultValue(false)
.column(columnLastWorld, Sql.VARCHAR(255)).notNull()
.column(columnLastWorld, Sql.varchar(255)).notNull()
.column(columnLastWorldSwapTime, Sql.LONG).notNull()
.primaryKey(usingMySQL, columnID)
.toString()

View File

@ -43,7 +43,7 @@ public class WorldTable extends Table {
try {
execute(TableSqlParser.createTable(tableName)
.primaryKeyIDColumn(usingMySQL, columnWorldId, Sql.INT)
.column(columnWorldName, Sql.VARCHAR(100)).notNull()
.column(columnWorldName, Sql.varchar(100)).notNull()
.primaryKey(usingMySQL, columnWorldId)
.toString()
);