mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-25 03:35:16 +01:00
Incomplete stuff
This commit is contained in:
parent
a7b9ca92ec
commit
12b195598a
2
pom.xml
2
pom.xml
@ -395,7 +395,7 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>6.3.0.jre8-preview</version>
|
||||
<version>6.3.3.jre8-preview</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.datasource.sqlextensions.SqlExtensionsFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
@ -25,19 +26,96 @@ public class MsSQL extends SqlDataSource {
|
||||
super.setConnectionArguments();
|
||||
|
||||
// Database URL
|
||||
ds.setDataSourceClassName("com.microsoft.sqlserver.jdbc.SQLServerDataSource");
|
||||
ds.setJdbcUrl("jdbc:sqlserver://" + host + ":" + port + ";databaseName="+ database + ";user=" + username + ";password=" + password);
|
||||
ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
ds.setJdbcUrl("jdbc:sqlserver://" + host + ":" + port + ";databaseName=" + database);
|
||||
ds.addDataSourceProperty("user", username);
|
||||
ds.addDataSourceProperty("password", password);
|
||||
ds.addDataSourceProperty("database.name", database);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTables() throws SQLException {
|
||||
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
||||
// Create table with ID column if it doesn't exist
|
||||
String sql = "IF object_id('" + tableName + "') IS NOT NULL\n"
|
||||
String sql = "IF object_id('" + tableName + "') IS NOT NULL"
|
||||
+ " CREATE TABLE " + tableName
|
||||
+ " (" + col.ID + " INT CHECK (" + col.ID + " > 0) IDENTITY"
|
||||
+ ", PRIMARY KEY (" + col.ID + ")) CHARACTER SET = utf8;";
|
||||
st.executeUpdate(sql);
|
||||
+ ", PRIMARY KEY (" + col.ID + "));";
|
||||
//st.executeUpdate(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkColumns() throws SQLException {
|
||||
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
||||
DatabaseMetaData md = con.getMetaData();
|
||||
if (isColumnMissing(md, col.NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD " + col.NAME + " NVARCHAR(255) NOT NULL UNIQUE;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REAL_NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD " + col.REAL_NAME + " NVARCHAR(255) NOT NULL;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.PASSWORD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD " + col.PASSWORD + " NVARCHAR(255) NOT NULL;");
|
||||
}
|
||||
|
||||
if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD " + col.SALT + " NVARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD " + col.IP + " NVARCHAR(40) NOT NULL;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD " + col.LAST_LOGIN + " BIGINT NOT NULL DEFAULT 0;");
|
||||
} else {
|
||||
migrateLastLoginColumn(con, md);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' , ADD "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0' , ADD "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
} else {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " MODIFY "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_WORLD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.LASTLOC_WORLD + " NVARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.EMAIL + " NVARCHAR(255) DEFAULT 'your@email.com';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD "
|
||||
+ col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0';");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
@ -70,6 +71,80 @@ public class MySQL extends SqlDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkColumns() throws SQLException {
|
||||
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
||||
DatabaseMetaData md = con.getMetaData();
|
||||
if (isColumnMissing(md, col.NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.NAME + " VARCHAR(255) NOT NULL UNIQUE AFTER " + col.ID + ";");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.REAL_NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REAL_NAME + " VARCHAR(255) NOT NULL AFTER " + col.NAME + ";");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.PASSWORD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
}
|
||||
|
||||
if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.LAST_LOGIN + " BIGINT NOT NULL DEFAULT 0;");
|
||||
} else {
|
||||
migrateLastLoginColumn(con, md);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LAST_LOGIN + " , ADD "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_X + " , ADD "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_Y);
|
||||
} else {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " MODIFY "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_WORLD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0' AFTER " + col.EMAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return DataSourceType.MYSQL;
|
||||
|
@ -138,80 +138,9 @@ public abstract class SqlDataSource implements DataSource {
|
||||
/**
|
||||
* Creates any required column if they don't exist.
|
||||
*/
|
||||
private void checkColumns() throws SQLException {
|
||||
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
||||
DatabaseMetaData md = con.getMetaData();
|
||||
if (isColumnMissing(md, col.NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.NAME + " VARCHAR(255) NOT NULL UNIQUE AFTER " + col.ID + ";");
|
||||
}
|
||||
protected abstract void checkColumns() throws SQLException;
|
||||
|
||||
if (isColumnMissing(md, col.REAL_NAME)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.REAL_NAME + " VARCHAR(255) NOT NULL AFTER " + col.NAME + ";");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.PASSWORD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
}
|
||||
|
||||
if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.SALT + " VARCHAR(255);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IP)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LAST_LOGIN)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.LAST_LOGIN + " BIGINT NOT NULL DEFAULT 0;");
|
||||
} else {
|
||||
migrateLastLoginColumn(con, md);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_X)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LAST_LOGIN + " , ADD "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_X + " , ADD "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_Y);
|
||||
} else {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " MODIFY "
|
||||
+ col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY "
|
||||
+ col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_WORLD)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0' AFTER " + col.EMAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||
protected boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
return !rs.next();
|
||||
}
|
||||
@ -662,7 +591,7 @@ public abstract class SqlDataSource implements DataSource {
|
||||
*
|
||||
* @throws SQLException .
|
||||
*/
|
||||
private void migrateLastLoginColumn(Connection con, DatabaseMetaData metaData) throws SQLException {
|
||||
protected void migrateLastLoginColumn(Connection con, DatabaseMetaData metaData) throws SQLException {
|
||||
final int columnType;
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, col.LAST_LOGIN)) {
|
||||
if (!rs.next()) {
|
||||
|
Loading…
Reference in New Issue
Block a user