Faster than prepared statements when queries are run once. Slightly
slower than PDO::ATTR_EMULATE_PREPARES but without the potential
security implications of embedding parameters in the query itself.
BC Break: the custom methods were previously just return false on
failure. Now they throw an exception with a proper error message.
An hopefully welcome improvement, but some application might be
depending on the old behaviour. FWIW the PDO::pgsqlCopy* methods
are not documented, even though they are available since 5.3.x.
- Changed PDO_PGSQL configure script to require libpq 7.4
- Cleaned up usage of HAVE_PQ* defines
- Fixed compiler warnings
- Removed custom implementation of PQunescapeByte
# Rationale:
# - PDO_PGSQL couldn't even compile when using libpq 7.3
# - PostgreSQL 7.3 is unsupported since a long time
# - Got consensus from pgsql devs on freenode
Postgres client API is pretty poor, so we have zero idea about the actual
parameter types in a statement.
We now defer the preparation of a statement until the first call to execute is
made. At that point, we have the parameters defined by the calling script, so
we can use the typing specified there when we perform the prepare.
For PDO_PARAM_LOB parameters, we set the binary formatting flag.
We can't just set this flag for all parameters, because its meaning is not
"string data, counted length" but "data is in native format". If this flag is
set for a numeric column and we send the number 1 formatted as a string, then
we will get an "insufficient data left in message" error message, because the
library was expecting sizeof(int4) bytes but only saw 1 byte for "1".
This is infuriating because we have no way to determine the datatypes for
parameters, and the type we explicitly set has to match the type in the
database. The only choice we're left with is telling postgres to deduce the
type; we still have no idea what type was deduced.
to true, forces the driver to use PDO's own emulated prepared statement
support.
Why would you want that, considering that native prepared statements are
supposed to be the best thing ever?
"Often postgresql will have to plan the query without knowing the parameters -
and it will choose a bad plan. In some cases it will plan based on the first
parameters you send. "
Ugh. So now we have a way to let you decide that you know better than the
pgsql query planner.
Note that some tests now fail; if we can't resolve this in time for the beta,
the prepare code should be disabled (I'll add a flag for this later today).
We allocate a unique cursor name for each statement, so that we
don't interfere with other open statement handles on the same dbh.
Note, however, that we force a new transaction for each open scrollable cursor
(postgres requires cursors to be used inside a transaction). This is okay,
except for the case where a scrollable cursor is opened, an update is made and
the cursor is closed; closing the cursor commits the transaction that was begun
when it was opened.
It might well be better to avoid the transaction in PDO and force the user to
be aware of the requirements of cursors and explicitly initiate the transaction
themselves.
This is all untested code; it compiles and looks like it will work, but I
encourage someone with a real postgres setup to actually sit down and try to
use it.