Bug fixes
This commit is contained in:
parent
c33ce0e60f
commit
72170b490b
2 changed files with 11 additions and 18 deletions
BIN
Zutil.jar
BIN
Zutil.jar
Binary file not shown.
|
|
@ -74,7 +74,7 @@ public class DBUpgradeHandler {
|
||||||
|
|
||||||
private void upgradeCreateTabels() throws SQLException {
|
private void upgradeCreateTabels() throws SQLException {
|
||||||
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
List<String> targetTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> targetTables = target.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
|
|
||||||
for(String table : refTables){
|
for(String table : refTables){
|
||||||
if(!targetTables.contains(table)){
|
if(!targetTables.contains(table)){
|
||||||
|
|
@ -91,23 +91,20 @@ public class DBUpgradeHandler {
|
||||||
|
|
||||||
private void upgradeDropTables() throws SQLException {
|
private void upgradeDropTables() throws SQLException {
|
||||||
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
List<String> targetTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> targetTables = target.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
|
|
||||||
for(String table : targetTables){
|
for(String table : targetTables){
|
||||||
if(!refTables.contains(table)){
|
if(!refTables.contains(table)){
|
||||||
logger.fine("Dropping table: ");
|
logger.fine("Dropping table: " + table);
|
||||||
PreparedStatement stmt = target.getPreparedStatement("DROP TABLE ?");
|
target.exec("DROP TABLE " + table);
|
||||||
stmt.setString(1, table);
|
|
||||||
DBConnection.exec(stmt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeAlterTables() throws SQLException {
|
private void upgradeAlterTables() throws SQLException {
|
||||||
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
List<String> targetTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
List<String> targetTables = target.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult<String>());
|
||||||
|
|
||||||
PreparedStatement stmt;
|
|
||||||
for(String table : targetTables){
|
for(String table : targetTables){
|
||||||
if(refTables.contains(table)){
|
if(refTables.contains(table)){
|
||||||
// Get reference structure
|
// Get reference structure
|
||||||
|
|
@ -121,16 +118,12 @@ public class DBUpgradeHandler {
|
||||||
for(DBColumn column : refStruct) {
|
for(DBColumn column : refStruct) {
|
||||||
if(!targetStruct.contains(column)) {
|
if(!targetStruct.contains(column)) {
|
||||||
logger.fine("Adding column '" + column.name + "' to table: " + table);
|
logger.fine("Adding column '" + column.name + "' to table: " + table);
|
||||||
stmt = target.getPreparedStatement("ALTER TABLE ? ADD COLUMN ? ? ?");
|
target.exec("ALTER TABLE "+table+" ADD COLUMN"
|
||||||
stmt.setString(1, table); // Table name
|
+ " " + column.name // Column name
|
||||||
stmt.setString(2, column.name); // Column name
|
+ " " + column.type // Column type
|
||||||
stmt.setString(2, column.type); // Column type
|
+ (column.defaultValue != null ? " DEFAULT '"+column.defaultValue+"'" : "")
|
||||||
stmt.setString(2, ""+// Column constraints
|
+ (column.notNull ? " NOT NULL" : "")
|
||||||
(column.defaultValue != null ? " DEFAULT '"+column.defaultValue+"'" : "")+
|
+ (column.publicKey ? " PRIMARY KEY" : ""));
|
||||||
(column.notNull ? " NOT NULL" : "")+
|
|
||||||
(column.publicKey ? " PRIMARY KEY" : "")
|
|
||||||
);
|
|
||||||
DBConnection.exec(stmt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check unnecessary columns
|
// Check unnecessary columns
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue