php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42756 getColumnMeta() flag primary_key disappears when combining JOIN and ORDER BY
Submitted: 2007-09-25 10:57 UTC Modified: 2007-10-20 01:00 UTC
From: jens dot ljungblad at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.4 OS: Win XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jens dot ljungblad at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-25 10:57 UTC] jens dot ljungblad at gmail dot com
Description:
------------
When doing a joined query with ORDER BY, the flag 'primary_key' disappears from the getColumnMeta() data. It is available when doing a JOIN and when doing an ORDER BY, but not when you combine the two.

Reproduce code:
---------------
<?php
$pdo = new PDO();
$pdo->query('SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id ORDER BY table1.id');

foreach ($pdo as $row)
{
  for ($i=0; $meta = $pdo->getColumnMeta($i); $i++)
  {
    print_r($meta);
  }
}
?>

Expected result:
----------------
I expect columns that are primary keys to have the 'primary_key' flag:
[flags] => Array
(
   [0] => not_null
   [1] => primary_key
)

Actual result:
--------------
The primary_key flag is missing

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-12 19:11 UTC] mj@php.net
The script below gives me the primary_key for both fields.  Can you please try it on your installation?  Thanks!

mysql> describe test;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| dummy | varchar(255) | NO   | PRI |         |       | 
+-------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> 

<?php
$dbh = new PDO("mysql:host=localhost;dbname=database",
              $user, $password);  

$result = $dbh->query("SELECT * FROM test t1 
  LEFT JOIN test t2 
  ON t1.dummy = t2.dummy 
  ORDER BY t1.dummy");

print_r($result->getColumnMeta(0));
print_r($result->getColumnMeta(1));
 [2007-10-20 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 16:01:34 2024 UTC