Don't issue a BEGIN when running VACUUM in auto-commit mode.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Sep 2013 10:20:02 +0000 (13:20 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Sep 2013 11:17:05 +0000 (14:17 +0300)
commitd92b7404b77df43b993e28986798bc97c7faa867
tree410d98783bef4287f5c3dbcb341145f4f2d307e0
parent764586c5f1740bbe83d41eb8f12f7641f2409cc9
Don't issue a BEGIN when running VACUUM in auto-commit mode.

Normally in auto-commit mode the driver begins a new transaction
implicitly at the first statement, by sending a BEGIN statement. However,
some commands, like VACUUM, cannot be run in a transaction block, and you
will get an error like "VACUUM cannot run inside a transaction block" from
the server. In UseServerSidePrepare=0 mode, the code looks at the first word
of the query to determine if the statement is one of the special ones, and
if so, didn't begin a new transaction even when auto-commit mode is
disabled. However, in UseServerSidePrepare=1 mode, when using SQLPrepare/
SQLExecute to run the VACUUM, that check was not made. Fix that.

There was one more related inconsistency between UseServerSidePrepare modes.
Without server-side-prepares, if you issued an explicit BEGIN in auto-commit
mode, the implicit BEGIN was ont sent. But without server-side prepares, it
was. It seems best to send the implicit BEGIN in both cases, because then
you get a warning from the backend about the second BEGIN. That's a good
thing, because a sane ODBC application should be using the ODBC function
SQLEndTran() for transaction control, not explicit BEGIN/COMMIT.

Also add a test case for executing VACUUM, with and without autocommit.
statement.c
test/Makefile
test/expected/commands.out [new file with mode: 0644]
test/src/commands-test.c [new file with mode: 0644]