Skip to content

ext/pdo: Rearrange struct to pack and group related fields together #17651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions ext/pdo/php_pdo_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,28 +560,21 @@ struct _pdo_stmt_t {
const struct pdo_stmt_methods *methods;
void *driver_data;

/* the cursor specific error code. */
pdo_error_type error_code;

/* if true, we've already successfully executed this statement at least
* once */
unsigned executed:1;
/* if true, the statement supports placeholders and can implement
* bindParam() for its prepared statements, if false, PDO should
* emulate prepare and bind on its behalf */
unsigned supports_placeholders:2;
uint16_t executed:1;

/* If true we are in a do_fetch() call, and modification to the statement must be prevented */
unsigned in_fetch:1;
unsigned _reserved:28;
uint16_t in_fetch:1;

/* the number of columns in the result set; not valid until after
* the statement has been executed at least once. In some cases, might
* not be valid until fetch (at the driver level) has been called at least once.
* */
int column_count;
struct pdo_column_data *columns;

/* we want to keep the dbh alive while we live, so we own a reference */
zend_object *database_object_handle;
pdo_dbh_t *dbh;
/* if true, the statement supports placeholders and can implement
* bindParam() for its prepared statements, if false, PDO should
* emulate prepare and bind on its behalf */
uint16_t supports_placeholders:2;
uint16_t reserved: 12;

/* keep track of bound input parameters. Some drivers support
* input/output parameters, but you can't rely on that working */
Expand All @@ -592,24 +585,16 @@ struct _pdo_stmt_t {
* in the result set */
HashTable *bound_columns;

/* not always meaningful */
zend_long row_count;

/* used to hold the statement's current query */
zend_string *query_string;

/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
zend_string *active_query_string;

/* the cursor specific error code. */
pdo_error_type error_code;

/* for lazy fetches, we always return the same lazy object handle.
* Let's keep it here. */
zval lazy_object_ref;
struct pdo_column_data *columns;
/* the number of columns in the result set; not valid until after
* the statement has been executed at least once. In some cases, might
* not be valid until fetch (at the driver level) has been called at least once.
* */
int32_t column_count;

/* defaults for fetches */
enum pdo_fetch_type default_fetch_type;

union {
int column;
struct {
Expand All @@ -622,6 +607,23 @@ struct _pdo_stmt_t {
zend_object *into;
} fetch;

/* for lazy fetches, we always return the same lazy object handle.
* Let's keep it here. */
zval lazy_object_ref;

pdo_dbh_t *dbh;
/* we want to keep the dbh alive while we live, so we own a reference */
zend_object *database_object_handle;

/* not always meaningful */
zend_long row_count;

/* used to hold the statement's current query */
zend_string *query_string;

/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
zend_string *active_query_string;

/* used by the query parser for driver specific
* parameter naming (see pgsql driver for example) */
const char *named_rewrite_template;
Expand All @@ -634,6 +636,8 @@ struct _pdo_stmt_t {
zend_object std;
};



static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
return (pdo_stmt_t *)((char*)(obj) - XtOffsetOf(pdo_stmt_t, std));
}
Expand Down