Commit graph

1308 commits

Author SHA1 Message Date
Michael Voříšek
305892580e
Fix pdo_oci tests for PHP 8.0 2022-08-22 09:25:43 +02:00
Yurun
bfe63f565f Fix dblib ghtest8626 test.
Follow-up of GH-8628.
Closes GH-9694.
2022-06-03 15:12:09 +01:00
Yurun
df52903ee0 Closes GH-8626: Fix PDOStatement->execute() failed.
Then execute successfully, errorInfo() information is incorrect
2022-06-02 17:32:43 +01:00
Christoph M. Becker
efb901ebed
Skip bug_36798.phpt for PDO_DBLIB
For some reason, this test fails now with "Incorrect syntax near ''.
[SELECT '�' as test FROM test WHERE id = '1']", so we skip it.
2021-12-07 20:24:15 +01:00
Nikita Popov
2e343fcb42 Mark PDO::setAttribute() $value as mixed
For consistency with PDOStatement::setAttribute(). Attribute values
can for example also be bool.

This is backwards-compatible, as mixed is the same as no type for
parameter variance.
2021-08-20 16:51:52 +02:00
Máté Kocsis
068c8db276
Fix the signature of PDOStatement::fetchObject()
The ?array $ctorArgs = null parameter is changed to array $constructorArgs = [], and an additional memory leak revealed by the new test case is fixed.

Closes GH-6937

Co-Authored-By: Nikita Popov <nikita.ppv@gmail.com>
2021-05-05 16:48:22 +02:00
Máté Kocsis
30d3062c9b
Fix the default value of $mode in PDOStatement::fetch*()
Closes GH-6933
2021-05-03 13:06:38 +02:00
Nikita Popov
8effbd1cb0 PDO: Respect connection transaction state for dtor rollback
As mentioned in bug #80949, if a transaction is implicitly
committed, then PDO may still issue a ROLLBACK when the PDO
object is destroyed, as the transaction is still marked as active
in PDO's (inaccurate) transaction emulation.

Make sure we use the connection transaction state also for that
final ROLLBACK. A caveat here is that the connection might have
been dropped already, which may be the case for some drivers if
construction fails. Make sure we don't crash in that case.
2021-04-12 12:39:44 +02:00
Máté Kocsis
d7ae64627f
Fix PDOStatement::bindColumn() parameter default value 2021-03-25 19:31:04 +01:00
Máté Kocsis
45fa7596dc
Add missing classes to stubs 2021-02-09 22:38:06 +01:00
Nikita Popov
205d209de9 PDO MySQL: Use mysqlnd column names
mysqlnd already creates interned zend_strings for us, so let's
make use of them.

This also required updating the PDO case changing code to work
with potentially shared strings. For the lowercasing, use the
optimized zend_string_tolower() implementation.
2020-12-16 15:17:13 +01:00
Nikita Popov
9e3ba775b7 Fixed bug #72368
Generate a param count mismatch error even if the query contains
no placeholders.

Additionally we shouldn't HANDLE errors from pdo_parse_params,
which are always reported via raise_impl_error. Doing so results
in duplicate error messages.
2020-12-10 16:53:08 +01:00
Nikita Popov
a5527577e7 Allow drivers to omit error code
And thus generate error messages that match what PDO emulation
would generate.

This fixes the error message regression from the previous commit.
2020-12-10 16:04:33 +01:00
Nikita Popov
15b51a215a Fixed bug #79131
When a driver reports an error during EVT_ALLOC (and some over EVTs),
make sure we handle it as usual, i.e. warn or throw.

This requires some adjustments in PDO PgSQL to stop manually doing
this through an impl error.

Unfortunately the PDO PgSQL error messages regress because of this,
as they now include a completely arbitrary error code. There doesn't
seem to be an ability to skip it right now.
2020-12-10 15:53:23 +01:00
Nikita Popov
9c0712d2cd Make XFAILED test less broken
At least allow it to print some output rather than throw right
away...
2020-12-09 10:42:44 +01:00
Nikita Popov
bfa69d27bc Handle column count change in PDO MySQL
This has been fixed for PDO SQlite by GH-4313, however the same
issue also applied to PDO MySQL.

Move the column count setting function into the main PDO layer
(and export it) and then use it in both PDO SQLite and PDO MySQL.
2020-12-08 16:41:35 +01:00
Dharman
53f7bddbeb Fix typos in mysql tests
%d because of line endings on Windows
2020-12-03 10:42:39 +01:00
Benjamin Morel
4bbb98c24f Fix PDOStatement::fetchObject() stub
Closes GH-6449.
2020-11-24 09:49:30 +01:00
Nikita Popov
39be0df2ed Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #66528
2020-10-28 12:18:17 +01:00
Nikita Popov
68dcaa29d8 Fixed bug #66528
Report errors in commit, rollback and autocommit handlers.
2020-10-28 12:18:02 +01:00
Nikita Popov
7b9519a792 Fix inconsistency in PDO transaction state
This addresses an issue introduced by #4996 and reported in
https://bugs.php.net/bug.php?id=80260.

Now that PDO::inTransaction() reports the real transaction state
of the connection, there may be a mismatch with PDOs internal
transaction state (in_tcx). This is compounded by the fact that
MySQL performs implicit commits for DDL queries.

This patch fixes the issue by making beginTransaction/commit/rollBack
work on the real transaction state provided by the driver as well
(or falling back to in_tcx if the driver does not support it).

This does mean that writing something like

    $pdo->beginTransaction();
    $pdo->exec('CREATE DATABASE ...');
    $pdo->rollBack(); // <- illegal

will now result in an error, because the CREATE DATABASE already
committed the transaction. I believe this behavior is both correct
and desired -- otherwise, there is no indication that the code did
not behave correctly and the rollBack() was effectively ignored.
However, this is also a BC break.

Closes GH-6355.
2020-10-26 17:01:18 +01:00
Máté Kocsis
d5f92baad0 Fix default value handling of mysqli_fetch_object()
Make [] acceptable both for classes without constructors and
classes with a constructor that takes no arguments.

Closes GH-6336.
2020-10-20 16:48:12 +02:00
Nikita Popov
74fe9170b6 Check PDOStatement initialization during iteration 2020-10-19 10:22:56 +02:00
Nikita Popov
0f3698173e Update PDO parameter names
Followup to previous changes:
 * Use camel case, as PDO uses a camel case OO API.
 * Use &$var instead of &$bind_var or &$param.
 * Use $column instead of $index. We have cases (both inside PDO
   and in other DB exts) where columns can also be represented as
   strings, so $column is the safer generic name.

Closes GH-6272.
2020-10-05 15:51:36 +02:00
Larry Garfield
ea03cbebbc Update PDO parameters for named arguments.
Closes GH-6220
2020-09-28 23:02:05 +01:00
George Peter Banyard
7553c696c3 Another pass making some failure states unconditional erros in PDO
Also make internal function return type more accurate to inform usage
2020-09-28 19:35:31 +01:00
George Peter Banyard
a5cf82802d Make various failure conditions in PDO unconditional errors
This includes TypeErrors, ValueErrors, Error for uninitialized objects
and invalid user classes/callable instanciation

Closes GH-6212
2020-09-28 18:51:36 +01:00
George Peter Banyard
3c10d4d9a9 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix logic error in PDO
2020-09-25 16:35:50 +01:00
George Peter Banyard
ef385e806f Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix logic error in PDO
2020-09-25 16:32:41 +01:00
George Peter Banyard
4dfbf07644 Fix logic error in PDO 2020-09-25 16:28:48 +01:00
George Peter Banyard
0cc7267980 Inverse logic in do_fetch() to reduce a level of indentation 2020-09-25 14:19:49 +01:00
George Peter Banyard
411610892a Drop do_bind argument in do_fetch(_common)() in PDO
It is always set to true by callers and therefore irrelevant.
2020-09-25 14:19:26 +01:00
Nikita Popov
5bb41fa63c Promote PDORow property write to Error 2020-09-21 15:33:39 +02:00
Nikita Popov
6f76817f02 Remove dead code
The "if ever" here is the relevant bit...
2020-09-21 15:33:39 +02:00
Nikita Popov
c5401854fc Run tidy
This should fix most of the remaining issues with tabs and spaces
being mixed in tests.
2020-09-18 14:28:32 +02:00
Máté Kocsis
c76910cd96
Display types in stubs more uniformly
In preparation for generating method signatures for the manual.

This change gets rid of bogus false|null return types, a few unnecessary trailing backslashes, and settles on using ? when possible for nullable types.
2020-09-16 21:19:36 +02:00
Christopher Jones
bc508b0b88 Skip PDO test for Oracle 2020-09-10 17:32:44 +10:00
Máté Kocsis
f7fbc6333f
Add more precise type info for stubs
Closes GH-6005
2020-09-01 16:35:56 +02:00
Matteo Beccati
42b6b8a3ae Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #80027 Terrible performance using $query->fetch on queries with many bind parameters
2020-08-31 11:08:26 +02:00
Matteo Beccati
44ade0e875 Fix #80027 Terrible performance using $query->fetch on queries with many bind parameters
Added new flags that allow skipping param_evt(s) that are not used by drivers,
in a backwards and forward compatible manner. Updated the pgsql, mysql, sqlite
and oci drivers to properly use the new flags. I've left out pdo_dblib, which
doesn't have a param_hook, and pdo_firebird, which seems to be using
PARAM_EVT_NORMALIZE in a wrong context (param type vs event type).
2020-08-31 11:03:03 +02:00
Matteo Beccati
ee2506cc02 Fix #80027 Terrible performance using $query->fetch on queries with many bind parameters
Added new flags that allow skipping param_evt(s) that are not used by drivers,
in a backwards and forward compatible manner. Updated the pgsql, mysql, sqlite
and oci drivers to properly use the new flags. I've left out pdo_dblib, which
doesn't have a param_hook, and pdo_firebird, which seems to be using
PARAM_EVT_NORMALIZE in a wrong context (param type vs event type).
2020-08-31 11:02:34 +02:00
George Peter Banyard
1b2ec73c1d Drop various unused macros/APIs
Also convert_libmagic_pattern() to return a zend_string*

Closes GH-6029
2020-08-26 12:59:43 +02:00
Nikita Popov
cfaa270da5 Use variadic signature for PDOStatement::fetchAll()
The current signature is incorrect, because the $ctor_args parameter
is not required to be an array (it can at least also be null, and
isn't enforced by an exception anyway).

I'm going for the variadic signature here, because we already use
the same variadic signature in PDO::query() and
PDOStatement::setFetchMode(), all of them accepting essentially the
same arguments.
2020-08-14 15:19:18 +02:00
Nikita Popov
670036e2a9 Use Z_PARAM_CLASS in PDOStatement::fetchObject()
Instead of implementing custom logic.
2020-08-13 16:20:29 +02:00
Máté Kocsis
2803c8fb8d
Add all the missing parameter types to stubs
Closes GH-5955
2020-08-13 14:47:18 +02:00
Nikita Popov
898bb97706 Drop php_pdo_get_exception_base() function
This API is more confusing than helpful.
2020-08-11 17:40:39 +02:00
Nikita Popov
33028bf014 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #64705 errorInfo property of PDOException is null when PDO::__construct() fails
2020-08-11 17:16:38 +02:00
Nikita Popov
981af26d7b Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #64705 errorInfo property of PDOException is null when PDO::__construct() fails
2020-08-11 17:13:28 +02:00
Ahmed Abdou
2fe2e5b48f Fix #64705 errorInfo property of PDOException is null when PDO::__construct() fails
PDO driver constructors are throwing PdoException without setting
errorInfo, so create a new reusable function that throws exceptions
for PDO and will also set the errorInfo. Use this function in
pdo_mysql, pdo_sqlite, and pdo_pgsql.
2020-08-11 17:12:48 +02:00
Máté Kocsis
7aacc705d0
Add many missing closing PHP tags to tests
Closes GH-5958
2020-08-09 22:03:36 +02:00