Skip to content

ext/pdo: Fix various bugs related to PDORow #13512

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 8 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Feb 26, 2024

Easier to review commits in order.

@SakiTakamachi
Copy link
Member

Thank you, the commits were separate and easy to read. Looks good to me as a change to this problem.

However, I discovered a use case like this:

$pdo = new PDO();

$stmt = $pdo->prepare('SELECT 1 as "3", 2');
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_LAZY);

var_dump($result, $result->{3}, $result[3]);

result:

object(PDORow)#3 (3) {
  ["queryString"]=>
  string(18) "SELECT 1 as "3", 2"
  ["3"]=>
  int(1)
  ["2"]=>
  int(2)
}
NULL
NULL

The solution is to fallback from row_read_column_number to row_read_column_name, but I'm not sure if I should support such behavior...
(Typically, no user would be bothered by not supporting this.)

notes: If nothing is specified for $stmt->fetch(), overwriting will occur due to duplicate keys in the array. However, this is not a big problem as we can use PDO::FETCH_ASSOC.

@SakiTakamachi
Copy link
Member

SakiTakamachi commented Feb 26, 2024

There are cases like this.

$stmt = $pdo->prepare('SELECT 1, 2');
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_LAZY);

var_dump($result, $result->{1}, $result[1]);
object(PDORow)#3 (3) {
  ["queryString"]=>
  string(11) "SELECT 1, 2"
  ["1"]=>
  int(1)
  ["2"]=>
  int(2)
}
int(2)
int(2)

So there may be no point in fallback...

@SakiTakamachi
Copy link
Member

Maybe we should consider this as a separate issue for now.

If it passes the test, I think it looks good.

@@ -2257,74 +2257,84 @@ zend_object_iterator *pdo_stmt_iter_get(zend_class_entry *ce, zval *object, int
/* }}} */

/* {{{ overloaded handlers for PDORow class (used by PDO_FETCH_LAZY) */
static zval *row_read_column_name(pdo_stmt_t *stmt, zend_string *name, zval *rv)
Copy link
Member

Choose a reason for hiding this comment

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

It's probably from the beginning, the tag one line above doesn't seem to be closed.

@Girgias
Copy link
Member Author

Girgias commented Feb 27, 2024

Merged as b4e272c

@Girgias Girgias closed this Feb 27, 2024
@Girgias Girgias deleted the 82-pdo-row-bugs branch February 27, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants