mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Should we update existing tables? Also, are you good with MySQL?
This commit is contained in:
parent
0efb9d62ca
commit
edfbc8d474
@ -24,10 +24,13 @@ import org.bukkit.block.Biome;
|
|||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.PlotMain.connection;
|
import static com.intellectualcrafters.plot.PlotMain.connection;
|
||||||
@ -99,6 +102,8 @@ public class DBFunc {
|
|||||||
"`timestamp` timestamp not null DEFAULT CURRENT_TIMESTAMP," +
|
"`timestamp` timestamp not null DEFAULT CURRENT_TIMESTAMP," +
|
||||||
"PRIMARY KEY (`id`)" +
|
"PRIMARY KEY (`id`)" +
|
||||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
|
||||||
|
|
||||||
|
|
||||||
stmt.addBatch(
|
stmt.addBatch(
|
||||||
"CREATE TABLE IF NOT EXISTS `plot_helpers` (" +
|
"CREATE TABLE IF NOT EXISTS `plot_helpers` (" +
|
||||||
"`plot_plot_id` int(11) NOT NULL," +
|
"`plot_plot_id` int(11) NOT NULL," +
|
||||||
@ -132,6 +137,36 @@ public class DBFunc {
|
|||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
stmt.clearBatch();
|
stmt.clearBatch();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adding missing columns (for older versions)
|
||||||
|
* + get current columns (continue if they do not match the current number of columns)
|
||||||
|
* + get data from plot_id column
|
||||||
|
* - create column (plot_id_x,plot_id_z,world)
|
||||||
|
* - populate plot_id_x, plot_id_z with data from plot_id
|
||||||
|
* - populate world column with PlotMain.config.getString("plot_world") - which will be set from previous release;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `plot`
|
||||||
|
*/
|
||||||
|
int target_len = 6;
|
||||||
|
ArrayList<String> ids = new ArrayList<String>();
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
String table = "plot";
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM `"+table+"`");
|
||||||
|
ResultSetMetaData md = rs.getMetaData();
|
||||||
|
int len = md.getColumnCount();
|
||||||
|
if (len<target_len) {
|
||||||
|
HashSet<String> cols = new HashSet<String>();
|
||||||
|
for (int i = 1; i <= len; i++) {
|
||||||
|
cols.add(md.getColumnName(i));
|
||||||
|
}
|
||||||
|
while (rs.next()) {
|
||||||
|
ids.add(rs.getString("plot_id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user