Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:pdo_float_type [2017/05/01 21:04] – move fixed precision types to future scope, simplify examples, add PR adambaratz | rfc:pdo_float_type [2019/05/07 15:03] (current) – withdrawn adambaratz |
---|
====== PHP RFC: PDO Float Type ====== | ====== PHP RFC: PDO Float Type ====== |
* Version: 0.4 | * Version: 0.5 |
* Date: 2017-04-05 | * Date: 2017-04-05 |
* Author: Adam Baratz adambaratz@php.net | * Author: Adam Baratz adambaratz@php.net |
* Status: Under Discussion | * Status: Withdrawn |
* First Published at: http://wiki.php.net/rfc/pdo_float_type | * First Published at: http://wiki.php.net/rfc/pdo_float_type |
| |
| |
===== Proposal ===== | ===== Proposal ===== |
A new type, ''PDO::PARAM_FLT'', will be added. It will indicate that a parameter can be interpreted as and presented to the database server as a floating point value. The name was selected to correspond to the PHP type system. | A new type, ''PDO::PARAM_FLOAT'', will be added. It will indicate that a parameter can be interpreted as and presented to the database server as a floating point value. The name was selected to correspond to the PHP type system. |
| |
As indicated by the comments on [[https://github.com/php/php-src/blob/master/ext/pdo/php_pdo_driver.h#L51|pdo_param_type]], each type should correspond to a C type. PHP floats are represented as doubles and the APIs used by each supported PDO driver represent floating point values as doubles, so ''PDO::PARAM_FLT'' will correspond to double. This is mainly relevant for fetching column data, which is otherwise considered out of scope for this RFC (see Future Scope). | As indicated by the comments on [[https://github.com/php/php-src/blob/master/ext/pdo/php_pdo_driver.h#L51|pdo_param_type]], each type should correspond to a C type. PHP floats are represented as doubles and the APIs used by each supported PDO driver represent floating point values as doubles, so ''PDO::PARAM_FLOAT'' will correspond to double. This is mainly relevant for fetching column data, which is otherwise considered out of scope for this RFC (see Future Scope). |
| |
The supported PDO drivers will be modified as little as possible for this type to be supported. In fact, only pdo_sqlite will require modifications. When emulated prepared statements are enabled, these values will be interpolated in decimal form. | The supported PDO drivers will be modified as little as possible for this type to be supported. In fact, only pdo_sqlite will require modifications. When emulated prepared statements are enabled, these values will be interpolated in decimal form. |
| |
==== pdo_firebird ==== | ==== pdo_firebird ==== |
This driver will require no modifications. The addition of ''PDO::PARAM_FLT'' will prevent floats from being cast to strings before binding them. Other values won't be cast. | This driver will require no modifications. The addition of ''PDO::PARAM_FLOAT'' will prevent floats from being cast to strings before binding them. Other values won't be cast. |
| |
The ''PDO_PARAM_EVT_EXEC_PRE'' hook (see ''ext/pdo_firebird/firebird_statement.c:firebird_stmt_param_hook'') checks for double zvals. This code isn't reached because any zval doubles will be cast to other types before they reach this hook (see ''ext/pdo/pdo_stmt.c:really_register_bound_param''). | The ''PDO_PARAM_EVT_EXEC_PRE'' hook (see ''ext/pdo_firebird/firebird_statement.c:firebird_stmt_param_hook'') checks for double zvals. This code isn't reached because any zval doubles will be cast to other types before they reach this hook (see ''ext/pdo/pdo_stmt.c:really_register_bound_param''). |
| |
==== pdo_mysql ==== | ==== pdo_mysql ==== |
This driver will require no modifications. The addition of ''PDO::PARAM_FLT'' will prevent floats from being cast to strings before binding them. Other values won't be cast. | This driver will require no modifications. The addition of ''PDO::PARAM_FLOAT'' will prevent floats from being cast to strings before binding them. Other values won't be cast. |
| |
The ''PDO_PARAM_EVT_EXEC_PRE'' hook (see ''ext/pdo_mysql/mysql_statement.c:pdo_mysql_stmt_param_hook'') will check for double zvals. This code isn't reached because any zval doubles will be cast to other types before they reach this hook (see ''ext/pdo/pdo_stmt.c:really_register_bound_param''). | The ''PDO_PARAM_EVT_EXEC_PRE'' hook (see ''ext/pdo_mysql/mysql_statement.c:pdo_mysql_stmt_param_hook'') will check for double zvals. This code isn't reached because any zval doubles will be cast to other types before they reach this hook (see ''ext/pdo/pdo_stmt.c:really_register_bound_param''). |
This driver will require a small modification. | This driver will require a small modification. |
| |
It currently casts values to the type implied by the PDO type so they can be bound with the most appropriate [[https://www.sqlite.org/c3ref/bind_blob.html|API]]. This behavior would be replicated for ''PDO::PARAM_FLT''. | It currently casts values to the type implied by the PDO type so they can be bound with the most appropriate [[https://www.sqlite.org/c3ref/bind_blob.html|API]]. This behavior would be replicated for ''PDO::PARAM_FLOAT''. |
| |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== |
| |
==== Fixed Precision Types ==== | ==== Fixed Precision Types ==== |
These types have different storage requirements from floats. They often vary a bit between the APIs used by supported drivers. It would be valuable for PDO to support these types, but this can be handled by a separate RFC. The documentation for ''PDO::PARAM_FLT'' should state clearly that it's not intended to be used for fixed precision values. Since these values are currently bound as ''PDO::PARAM_STR'', the introduction of ''PDO::PARAM_FLT'' shouldn't harm how they're presented to DBs. | These types have different storage requirements from floats. They often vary a bit between the APIs used by supported drivers. It would be valuable for PDO to support these types, but this can be handled by a separate RFC. The documentation for ''PDO::PARAM_FLOAT'' should state clearly that it's not intended to be used for fixed precision values. Since these values are currently bound as ''PDO::PARAM_STR'', the introduction of ''PDO::PARAM_FLOAT'' shouldn't harm how they're presented to DBs. |
| |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== |