PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
setDefaultSort problem with two identical column names, MDB2

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
jannie00



Joined: 07 Apr 2008
Posts: 6

PostPosted: Mon Apr 07, 2008 5:43 pm    Post subject: setDefaultSort problem with two identical column names, MDB2 Reply with quote

Hello,

I use the MDB2 datasource in combination with DataGrid and have the following problem:

If have a query with two identical column names like:

SELECT
a.name AS aname,
b.name AS bname
FROM
a,
b
WHERE
a.id = b.id

When I do in my PHP code:

...
$DataGrid->setDefaultSort(array(
'name' => 'DESC'
));
$DataGrid->bind($query, $options);
...

I get the MDB2 error:

Column 'name' in order clause is ambiguous

Even when I remove 'b.name AS bname' from the query I get the error message. Also tried to use the alias ('aname') as default sort, same error. Has anyone a solution? Is it a bug? Do I have to change one of the column names in the database (rather not, it is used a lot)?

Regards, Chris
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Mon Apr 07, 2008 10:44 pm    Post subject: Re: setDefaultSort problem with two identical column names, Reply with quote

jannie00 wrote:
[...]I get the MDB2 error:

Column 'name' in order clause is ambiguous

Even when I remove 'b.name AS bname' from the query I get the error message.


That is expected behaviour so far. Both tables have a column with this name, and you're selecting from both tables ("FROM a, b").

jannie00 wrote:
Also tried to use the alias ('aname') as default sort, same error. Has anyone a solution? Is it a bug?


Using the alias in the setDefaultSort() call would have been my advise. Are you really sure that you get the same error? Could it maybe be caused by another part of your query?

Using $error->getDebugInfo() in addition to $error->getMessage() will give you more details, and should also give you the "broken" query. Can also please paste the reported query here?
($error needs to be replaced, of course, it's just an example)
Back to top
View user's profile Send private message
jannie00



Joined: 07 Apr 2008
Posts: 6

PostPosted: Wed Apr 09, 2008 10:41 am    Post subject: Reply with quote

You are right. It does work now when using the alias. Something else in the query was causing the error.

Sometimes you just need a good nights sleep...

Regards, Chris
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software