accept SQL commands returning more ResultSets v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 22 Dec 2013 23:55:07 +0100
branchv_0
changeset 35b2ff3b2d58b2
parent 34 9335cf31c0f2
child 36 025fbe816bbf
accept SQL commands returning more ResultSets
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
java/sql-dk/src/info/globalcode/sql/dk/SQLCommand.java
java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java
java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNumbered.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Sun Dec 22 23:31:55 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Sun Dec 22 23:55:07 2013 +0100
     1.3 @@ -76,8 +76,22 @@
     1.4  		formatter.writeParameters(sqlCommand.getParameters());
     1.5  		try (PreparedStatement ps = sqlCommand.prepareStatement(connection)) {
     1.6  			sqlCommand.parametrize(ps);
     1.7 -			try (ResultSet rs = ps.executeQuery()) {
     1.8 -				processResultSet(rs, formatter);
     1.9 +
    1.10 +			boolean isRS = ps.execute();
    1.11 +			if (isRS) {
    1.12 +				try (ResultSet rs = ps.getResultSet()) {
    1.13 +					processResultSet(rs, formatter);
    1.14 +				}
    1.15 +			} else {
    1.16 +				/**
    1.17 +				 * TODO: process UPDATE command
    1.18 +				 */
    1.19 +			}
    1.20 +
    1.21 +			while (ps.getMoreResults() || ps.getUpdateCount() > -1) {
    1.22 +				/**
    1.23 +				 * TODO: process more RS or UPDATEs
    1.24 +				 */
    1.25  			}
    1.26  		}
    1.27  
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/SQLCommand.java	Sun Dec 22 23:31:55 2013 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/SQLCommand.java	Sun Dec 22 23:55:07 2013 +0100
     2.3 @@ -36,7 +36,9 @@
     2.4  		this.query = query;
     2.5  	}
     2.6  
     2.7 -	public abstract PreparedStatement prepareStatement(Connection c) throws SQLException;
     2.8 +	public PreparedStatement prepareStatement(Connection c) throws SQLException {
     2.9 +		return c.prepareStatement(query);
    2.10 +	}
    2.11  
    2.12  	public abstract void parametrize(PreparedStatement ps) throws SQLException;
    2.13  
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java	Sun Dec 22 23:31:55 2013 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java	Sun Dec 22 23:55:07 2013 +0100
     3.3 @@ -36,11 +36,6 @@
     3.4  	}
     3.5  
     3.6  	@Override
     3.7 -	public PreparedStatement prepareStatement(Connection c) throws SQLException {
     3.8 -		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     3.9 -	}
    3.10 -
    3.11 -	@Override
    3.12  	public void parametrize(PreparedStatement ps) throws SQLException {
    3.13  		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    3.14  	}
     4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNumbered.java	Sun Dec 22 23:31:55 2013 +0100
     4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNumbered.java	Sun Dec 22 23:55:07 2013 +0100
     4.3 @@ -37,11 +37,6 @@
     4.4  	}
     4.5  
     4.6  	@Override
     4.7 -	public PreparedStatement prepareStatement(Connection c) throws SQLException {
     4.8 -		return c.prepareStatement(getQuery());
     4.9 -	}
    4.10 -
    4.11 -	@Override
    4.12  	public void parametrize(PreparedStatement ps) throws SQLException {
    4.13  		int i = 1;
    4.14  		for (Parameter p : notNull(parameters)) {