Oliver Jowett <oliver@opencloud.com> wrote:
> (b) the current behavior is consistent with how multiple statement
> execution works elsewhere in the driver, where if you execute
> "SELECT a; SELECT b" as a statement with autocommit=true then the
> two queries run in a single transaction;
I did not know that. Is that required by spec?
It definitely doesn't happen in psql:
test=# select now(); select now();
now
-------------------------------
2011-03-31 17:38:41.345244-05
(1 row)
now
-------------------------------
2011-03-31 17:38:41.410403-05
(1 row)
test=# begin; select now(); select now(); commit;
BEGIN
now
-------------------------------
2011-03-31 17:38:58.593238-05
(1 row)
now
-------------------------------
2011-03-31 17:38:58.593238-05
(1 row)
COMMIT
I would have expected more or less the same from this:
import java.sql.*;
public class MultiStmt
{
public static void main(String[] args) throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql:test", "kgrittn", "");
Statement stmt = con.createStatement();
for (boolean rsfound = stmt.execute
("select now(); select now();");
rsfound || stmt.getUpdateCount() != -1;
rsfound = stmt.getMoreResults())
{
ResultSet rs = stmt.getResultSet();
while (rs.next())
System.out.println
(rs.getTimestamp(1));
rs.close();
}
stmt.close();
con.close();
}
}
When I run that, I see that it behaves as you say.
-Kevin