Skip to content

ext/pgsql: Use zval_try_get_string() instead of converting zval #15265

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 6 additions & 3 deletions ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,12 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
S->param_lengths[param->paramno] = 1;
S->param_formats[param->paramno] = 0;
} else {
convert_to_string(parameter);
S->param_values[param->paramno] = Z_STRVAL_P(parameter);
S->param_lengths[param->paramno] = Z_STRLEN_P(parameter);
zend_string *param_value = zval_try_get_string(parameter);
Copy link
Member

@devnexen devnexen Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemed a good idea, but you need to release it at some point. would need some bookeeping.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thought deeply about it yet, as I haven't really figured out how this works, and it seems to delegate to PDO... which might be an issue.

But I discovered we have a try_convert_to_string() function which might be better

if (UNEXPECTED(param_value == NULL)) {
return 0;
}
S->param_values[param->paramno] = ZSTR_VAL(param_value);
S->param_lengths[param->paramno] = ZSTR_LEN(param_value);
S->param_formats[param->paramno] = 0;
}

Expand Down
Loading