Skip to content

Avoid database query in getColumnMeta for pdo_pgsql connector #1534

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

Closed
wants to merge 6 commits into from
Closed

Avoid database query in getColumnMeta for pdo_pgsql connector #1534

wants to merge 6 commits into from

Conversation

jbylund
Copy link
Contributor

@jbylund jbylund commented Sep 22, 2015

I think there are a handful of bugs related to this issue. Essentially the current behavior is to run a query per column of the result set, even though we usually know the data type in most instances. This avoids the roundtrips for common types, but still does a roundtrip for user types.

Should close: https://bugs.php.net/bug.php?id=62498 (possibly related duplicates)

status = PQresultStatus(res);
if (status == PGRES_TUPLES_OK && 1 == PQntuples(res)) {
add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0));
PQclear(res);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't PQclear go outside the if?

@weltling
Copy link
Contributor

weltling commented Dec 9, 2015

@jbylund thanks for the patch, especially with regard to bug #62498 the fix seems useful. Not a complete meta info cache solution, but simple and straight forward enough improvement. A test for this would make sense, could you please add one? Basically a test that could be run with and without your patch, to see it brings same results.

Thanks.

$select = $db->query('SELECT intcol, stringcol, boolcol, datecol FROM bugtest_62498');
$meta = [];
for ($i=0; $i < 4; $i++) {
$meta[] = $select->getColumnMeta(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be getColumnMeta($i)?

@php-pulls
Copy link

Comment on behalf of ab at php.net:

Applied to 7.0 in e10257b, also i've fixed and extended the test in the follow up commit.

Thanks!

@php-pulls php-pulls closed this Apr 5, 2016
@outtersg
Copy link
Contributor

outtersg commented Oct 5, 2024

Funny that your test failing on my (admitedly bad) first implementation of #16249,
made me link another inefficiency in getColumnMeta() to yours, 8 years later
(in pdo_pgsql_translate_oid_to_table() use).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants