X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FGigiPreparedStatement.java;h=4dea5f981f68eb28679734eb1ed88c74e2dc7328;hb=a61a2d320cc2bb730528832133a8220cb5b80d68;hp=411b1fd5fb840056fa5000acc58d1d8be7a164aa;hpb=a0232b6e40e7e09767f0444d24e18bf12dafc362;p=gigi.git diff --git a/src/org/cacert/gigi/database/GigiPreparedStatement.java b/src/org/cacert/gigi/database/GigiPreparedStatement.java index 411b1fd5..4dea5f98 100644 --- a/src/org/cacert/gigi/database/GigiPreparedStatement.java +++ b/src/org/cacert/gigi/database/GigiPreparedStatement.java @@ -22,11 +22,7 @@ public class GigiPreparedStatement implements AutoCloseable { public GigiPreparedStatement(String stmt, boolean scroll) { try { - if (scroll) { - target = DatabaseConnection.getInstance().prepareInternalScrollable(stmt); - } else { - target = DatabaseConnection.getInstance().prepareInternal(stmt); - } + target = DatabaseConnection.getInstance().prepareInternal(stmt, scroll); } catch (SQLException e) { throw new Error(e); } @@ -53,6 +49,19 @@ public class GigiPreparedStatement implements AutoCloseable { } } + public boolean executeMaybeUpdate() { + try { + int updated = target.executeUpdate(); + if (updated > 1) { + throw new Error("More than one record (" + updated + ") updated."); + } + return updated == 1; + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + public boolean execute() { try { return target.execute(); @@ -80,6 +89,15 @@ public class GigiPreparedStatement implements AutoCloseable { } } + public void setEnum(int parameterIndex, DBEnum x) { + try { + target.setString(parameterIndex, x.getDBName()); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + public void setDate(int parameterIndex, Date x) { try { target.setDate(parameterIndex, x); @@ -120,6 +138,14 @@ public class GigiPreparedStatement implements AutoCloseable { } } + public int getParameterCount() { + try { + return target.getParameterMetaData().getParameterCount(); + } catch (SQLException e) { + throw new Error(e); + } + } + private void handleSQL(SQLException e) { // TODO Auto-generated method stub @@ -133,7 +159,11 @@ public class GigiPreparedStatement implements AutoCloseable { } PreparedStatement tg = target; target = null; - DatabaseConnection.getInstance().returnStatement(tg); + try { + DatabaseConnection.getInstance().returnStatement(tg); + } catch (SQLException e) { + throw new Error(e); + } }