Commit graph

189 commits

Author SHA1 Message Date
Gina Peter Banyard
fe8d39afc4
ext/pdo: Pack _pdo_dbh_t struct (#17741)
This reduces the size from 176 to 152 bytes
2025-03-04 22:10:16 +00:00
Gina Peter Banyard
4e55889dca
ext/pdo: Refactor validation of fetch mode in PDO statement (#17699)
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2025-02-09 00:35:33 +00:00
Gina Peter Banyard
5333afa607
ext/pdo: Convert _pdo_dbh_t query_stmt_zval to a zend_object pointer (#17742)
This saves 8 bytes
2025-02-08 19:27:51 +00:00
Gina Peter Banyard
598f982a6b
ext/pdo: Add const modifiers to pdo_get_TYPE_param() functions 2025-02-04 18:13:33 +00:00
Gina Peter Banyard
4fcbdea974 ext/pdo: Turn lazy_object_ref into a zend_object* from a zval
This saves 8 bytes
2025-02-04 11:23:08 +00:00
Gina Peter Banyard
6ae12093ce
ext/pdo: Rearrange struct to pack and group related fields together (#17651)
All bound related fields are now part of the same cache line
2025-02-02 21:25:29 +00:00
Gina Peter Banyard
3ff7758bcf ext/pdo: Refactor PDO::FETCH_CLASS to not rely on a FCI and use a HashTable for ctor_arg
To call the constructor we now only store the CE and a HashTable for the arguments.
This reduces the size of the _pdo_stmt_t struct from 320 bytes to 232 bytes.
Moreover, this now means that the constructor argument array follows the usual CUFA semantics.
This change is a BC break, as string keys now act like named arguments.
Moreover, the automatic wrapping of by-value arguments for by-ref parameters has been dropped, and the usual E_WARNING is now emitted in those cases.

The do_fetch() is heavily refactored to simplify the execution flow, which also makes it easier to understand.
Additionally we add a new bitflag in_fetch to prevent modification of the fetch flags by userland when PDO is fetching from the DB.
2025-01-30 18:48:54 +00:00
Gina Peter Banyard
09791ed1d1
ext/pdo: Convert database_object_handle zval to zend_object* (#17629)
This saves 8 bytes on the PDO statement struct.

We change the PGSQL PDO driver API to take a zend_object* instead of a zval* at the same time.
2025-01-30 18:34:03 +00:00
Gina Peter Banyard
8d95b3da89
ext/pdo: Remove refcount field from _pdo_stmt_t (#17622)
It is unused, and removing it saves 8 bytes on 64 bits systems.
2025-01-29 19:33:06 +00:00
Gina Peter Banyard
b667939b57
ext/pdo: Fix zend_object std layout for _pdo_row_t (#17606)
As of PHP 7 [1] the `std` should be at the end of the struct instead of at the beginning.

See GH-17598 for more UB related details.

[1] https://www.npopov.com/2015/06/19/Internal-value-representation-in-PHP-7-part-2.html#objects-in-php-7
2025-01-29 12:50:01 +00:00
Niels Dossche
6f4579af85
Introduce php_pdo_stmt_valid_db_obj_handle() (#17567) 2025-01-28 21:54:11 +01:00
Gina Peter Banyard
6fc49ab518
ext/pdo: Convert FETCH_INTO zval to a zend_object pointer (#17525) 2025-01-24 22:59:56 +00:00
Gina Peter Banyard
8d79ed6b3e
ext/pdo: Refactor PDO::FETCH_FUNC to not rely on an FCI on the struct (#17420) 2025-01-09 22:22:52 +00:00
Gina Peter Banyard
fba0b18d35 ext/pdo: Remove mostly useless retval field in statement struct 2025-01-09 10:30:10 +00:00
Gina Peter Banyard
bd83f866d1 ext/pdo: Refactor FETCH_FUNCTION mode
Most of the fields on the struct are useless or can be handled differently
2025-01-09 10:30:10 +00:00
Gina Peter Banyard
19dd79bdee ext/pdo: Refactor PDOStatement::fetchAll()
This also refactors the internal do_fetch() function to stop doing wonky stuff to handle grouping, which is a feature of fetchAll

Handle PDO_FETCH_KEY_PAIR on its own as GROUP and UNIQUE flags can interfere with it
2025-01-07 09:10:05 +00:00
Máté Kocsis
5892991941
Fix GH-16131: Prevent mixing PDO sub-classes with different DSN 2024-10-22 22:51:29 +02:00
Matteo Beccati
715b9aaa09
Implemented PDO Driver specific SQL parsers
RFC: http://wiki.php.net/rfc/pdo_driver_specific_parsers
2024-06-17 23:31:24 +02:00
Máté Kocsis
d6a0b3af68
Implement PDO driver-specific subclasses
RFC: https://wiki.php.net/rfc/pdo_driver_specific_subclasses
Closes GH-12804

Co-Authored-By: Danack <Danack@basereality.com>
2024-01-11 23:22:41 +01:00
Levi Morrison
282655083e
Fix some minor warnings (#8568)
* Fix php_apache_get_version prototype

Avoids an error with -Werror=strict-prototypes when building the
Apache SAPI.

* Fix -Werror=stringop-truncation in pdo_raise_impl_error

* Note pdo_error_type BC break
2022-05-18 08:30:59 -06:00
Nikita Popov
1e012ecb3f Fix bug #81405: Restore old PDO::PARAM_* values
Doctrine hardcodes the values of these constants, avoid changing
them.

Closes GH-7445.
2021-09-01 13:54:41 +02:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Nikita Popov
65a5c184d7 Add functions to convert i64/u64 to string
PDO implement half of this, but this functionality is generally
useful. Provide these as zend_u64_to_str and zend_i64_to_str to
complement zend_long_to_str.
2021-04-13 15:43:23 +02:00
George Peter Banyard
ebaeb93c3f Add API to fetch bool value for PDO attribute values
Closes GH-6766
2021-03-17 00:58:01 +00:00
George Peter Banyard
32fb9b6fd1 Validate string is numeric for integer PDO attribute value 2021-03-17 00:58:00 +00:00
George Peter Banyard
a6e8ebf99a Use standard C99 64bits int types
Closes GH-6622
2021-01-19 13:44:36 +00:00
George Peter Banyard
b44e29f843 php_pdo_register_driver() might fail
Therefore correctly report failure in MINIT for the drivers which didn't.
2021-01-19 12:55:07 +00:00
George Peter Banyard
a78aea8948 Refactor PDO's last inserted ID handler to use and return zend_string
Closes GH-6617
2021-01-19 11:54:25 +00:00
George Peter Banyard
94ea8e247b Refactor PDO doer handler to use zend_string 2021-01-19 11:42:39 +00:00
George Peter Banyard
63cda0fea8 Refactor PDO's quoter handler to return a zend_string
Closes GH-6547
2021-01-07 15:53:48 +00:00
George Peter Banyard
1a58611ae5 Voidify PDO's fetch_error handler 2021-01-06 10:20:57 +00:00
George Peter Banyard
60a61afd3c Boolify PDO's preparer handler 2021-01-06 10:20:57 +00:00
George Peter Banyard
53ba72ec03 Voidify PDO's closer handler 2021-01-06 10:20:57 +00:00
George Peter Banyard
954d3743cc Boolify PDO's quoter handler 2021-01-06 10:21:06 +00:00
George Peter Banyard
43f69160cf Boolify PDO's set_attribute driver function 2021-01-06 10:20:59 +00:00
George Peter Banyard
d04adf60be Boolify PDO's transaction handlers
This includes begin(), commit(), rollBack(), and inTransaction()
2021-01-06 10:20:57 +00:00
George Peter Banyard
6728c1bd72 Formalize pdo_dbh_check_liveness_func() return type to zend_result 2021-01-06 10:20:57 +00:00
George Peter Banyard
ca5fcb83bf Add/expand comments for PDO handlers 2021-01-06 10:20:57 +00:00
Nikita Popov
caa710037e Rewrite PDO result binding
Instead of requiring the type to be determined in advance by the
describer function and then requiring get_col to return a buffer
of appropriate type, allow get_col to return an arbitrary zval.
See UPGRADING.INTERNALS for a more detailed description of the
change.

This makes the result fetching simpler, more efficient and more
flexible. The general possibility already existed via the special
PDO_PARAM_ZVAL type, but the usage was very inconvenient and/or
inefficient. Now it's possible to easily implement behavior like
"return int if it fits, otherwise string" and to avoid any kind
of complex management of temporary buffers.

This also fixes bug #40913 (our second highest voted bug of all
time, for some reason). PARAM_LOB result bindings will now
consistently return a stream resource, independently of the used
database driver.

I've tried my best to update all PDO drivers for this change, but
some of the changes may be broken, as I cannot test or even build
some of these drivers (in particular PDO dblib and PDO oci).
Fixes are appreciated -- a working CI setup would be even more
appreciated ;)
2020-12-22 15:56:34 +01:00
Nikita Popov
2d51c203f0 PDO: Store/pass query_string as zend_string
Rather than storing char* + size_t, use a zend_string*. Also
avoid various copies of the query string.
2020-12-14 10:43:28 +01:00
Nikita Popov
0ac8518d76 Merge branch 'PHP-8.0'
* PHP-8.0:
  Handle column count change in PDO MySQL
2020-12-08 16:42:54 +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
Nikita Popov
e735de6eae Add GC support for PDO driver data
Add a get_gc method that can be implemented by drivers, which can
be used to add additional zvals to the GC buffer.

Implement GC support for PDO SQLite callbacks in particular.

Closes GH-6262.
2020-10-12 13:00:41 +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
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
Nikita Popov
5febd633b9 Accept unsigned instead of enum pdo_attribute_type
Driver-specific options get passed to these functions, which are
not part of the pdo_attribute_type enum. Newer GCC versions don't
like that. Accept a simple integr type instead.
2020-07-22 18:28:22 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00