X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fdb%2Fdriver%2FDbDriver.java;h=a756ab2d39f673b225eee46a4adcfef17bd2b219;hp=eea3e22c44c8d89f8fa79d21a52089b87e05555b;hb=8e5bdf0294e85b4419ee1e582d5677cccd3f736e;hpb=71a1166c90a757e1faec9756563d35dbc367665b diff --git a/prod/net/jaekl/cfb/db/driver/DbDriver.java b/prod/net/jaekl/cfb/db/driver/DbDriver.java index eea3e22..a756ab2 100644 --- a/prod/net/jaekl/cfb/db/driver/DbDriver.java +++ b/prod/net/jaekl/cfb/db/driver/DbDriver.java @@ -80,6 +80,22 @@ public abstract class DbDriver { } } + public Row selectExactlyOne(Connection con, Column[] columns, Table[] tables, Condition[] conditions) + throws SQLException + { + Sort[] sorts = new Sort[0]; + int limit = 2; + List rows = select(con, columns, tables, conditions, sorts, limit); + if (rows.size() < 1) { + throw new SQLException("Expected one result, but found none: ", selectSql(columns, tables, conditions, sorts, limit)); + } + if (rows.size() > 1) { + throw new SQLException("Expected one result, but found more than one: " + selectSql(columns, tables, conditions, sorts, limit)); + } + + return rows.get(0); + } + public List select(Connection con, Column[] columns, Table[] tables, Condition[] conditions) throws SQLException { @@ -131,6 +147,8 @@ public abstract class DbDriver { int count = 0; int pendingValues = 0; + assert( isValidInsert(table, values)); + String sql = insertSql(table); try (PreparedStatement ps = con.prepareStatement(sql)) @@ -372,4 +390,21 @@ public abstract class DbDriver { } abstract protected String nextValSql(Sequence seq); + + boolean isValidInsert(Table table, Object[][] values) + { + if (null == table) return false; + if (null == values) return false; + + for (Object[] rowValues : values) { + if (rowValues.length != table.getNumColumns()) { + return false; + } + for (int idx = 0; idx < rowValues.length; ++idx) { + + } + } + + return true; + } }