diff --git a/Zutil.jar b/Zutil.jar index d5e96e2..7aba28f 100755 Binary files a/Zutil.jar and b/Zutil.jar differ diff --git a/src/zutil/db/DBConnection.java b/src/zutil/db/DBConnection.java index 3606fdc..dc38bc7 100755 --- a/src/zutil/db/DBConnection.java +++ b/src/zutil/db/DBConnection.java @@ -207,10 +207,10 @@ public class DBConnection implements Closeable{ } /** - * Executes an query and cleans up after itself. + * Executes a query and cleans up after itself. * - * @param stmt is the query - * @param handler is the result handler + * @param stmt is the query to run + * @param handler is the result handler that will be called with the output of the execution * @return the object from the handler */ public static T exec(PreparedStatement stmt, SQLResultHandler handler) throws SQLException{ @@ -228,28 +228,28 @@ public class DBConnection implements Closeable{ } else return null; - }catch(SQLException sqlex){ - logger.log(Level.WARNING, null, sqlex); + }catch(SQLException e){ + logger.log(Level.WARNING, null, e); }finally{ if(result != null){ try { result.close(); - } catch (SQLException sqlex) { - logger.log(Level.WARNING, null, sqlex); + } catch (SQLException e) { + logger.log(Level.WARNING, null, e); } result = null; } } } - }catch(SQLException sqlex){ - logger.log(Level.WARNING, null, sqlex); + }catch(SQLException e){ + logger.log(Level.WARNING, null, e); // Cleanup } finally { if (stmt != null) { try { stmt.close(); - } catch (SQLException sqlex) { - logger.log(Level.WARNING, null, sqlex); + } catch (SQLException e) { + logger.log(Level.WARNING, null, e); } stmt = null; } @@ -257,6 +257,32 @@ public class DBConnection implements Closeable{ return null; } + /** + * Executes an query and cleans up after itself. + * + * @param stmt is the query to run + * @return a array of ints representing the number of updates for each batch statements + */ + public static int[] execBatch(PreparedStatement stmt) throws SQLException{ + try{ + // Execute + return stmt.executeBatch(); + }catch(SQLException e){ + logger.log(Level.WARNING, null, e); + // Cleanup + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + logger.log(Level.WARNING, null, e); + } + stmt = null; + } + } + return new int[0]; + } + /** * Sets the pool that this connection belongs to * diff --git a/src/zutil/db/DBUpgradeHandler.java b/src/zutil/db/DBUpgradeHandler.java index 3287473..2ee3cb7 100755 --- a/src/zutil/db/DBUpgradeHandler.java +++ b/src/zutil/db/DBUpgradeHandler.java @@ -107,17 +107,15 @@ public class DBUpgradeHandler { List refTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult()); List targetTables = reference.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult()); + PreparedStatement stmt; for(String table : targetTables){ if(refTables.contains(table)){ // Get reference structure - PreparedStatement stmt = reference.getPreparedStatement("PRAGMA table_info(?)"); - stmt.setString(1, table); - List refStruct = DBConnection.exec(stmt, new TableStructureResultHandler()); - + List refStruct = reference.exec("PRAGMA table_info("+table+")", + new TableStructureResultHandler()); // Get target structure - stmt = target.getPreparedStatement("PRAGMA table_info(?)"); - stmt.setString(1, table); - List targetStruct = DBConnection.exec(stmt, new TableStructureResultHandler()); + List targetStruct = target.exec("PRAGMA table_info("+table+")", + new TableStructureResultHandler()); // Check existing columns for(DBColumn column : refStruct) {