-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Zend\Paginator\Adapter\DbSelect additional for mistake elimination #4673
Conversation
Eliminates an error: "PDOException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column..." when original_select contains columns called in selection by the same name ( e.g. TRIM(str_column) as str_column ).
Unit tests, please. |
@Latch do you still work on this? |
@Latch There's a test failure -- DbSelectTest::testCount fails. |
I had the same problem when using DbSelect->count() in a joined table, so I created a class named MyDbSelect as follow: class MyDbSelect extends DbSelect
} |
Is this a valid SELECT? SELECT *, TRIM(str_column) as str_column FROM table on what platform, mysql? |
Yes it is valid (in MYSQL) a new column will be created with data without prefixes and / or suffixes, Read about in: |
I'm not asking about the trim(), I'm asking about the portion that does |
Right. |
I just don't think we can reset the columns carte blanche like that. Think of situations where someone has utilized the DISTINCT modifier. Ideally, a query would not produce duplicate named columns (btw, so far in my test, this only appears to affect MySQL, still going to test SQL Server, Db2 and Oracle yet). What do you think about adding an option to the constructor to allow resetting of the columns to make it opt-in? |
Closing due to inactivity. |
This is a fix for issue #4641
Eliminates an error: "PDOException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column..." when original_select contains columns called in selection by the same name ( e.g. TRIM(str_column) as str_column ).
In issue did not reset columns in select query to determine the count of rows in the grouped queries. Here there was a problem in my opinion. The count() method throws an error when original_select will be such:
SELECT *, TRIM(str_column) as str_column FROM table
PDOException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'str_column'
Query is good work: SELECT *, TRIM(str_column) as str_column FROM table
But query determine the count of rows throws an error:
SELECT COUNT(1) AS "c" FROM ( SELECT *, TRIM(str_column) as str_column FROM table ) AS "original_select"
The error resulted in higher.
I think need to reset columns original_select on '*'.
$select->reset(Select::COLUMNS);
$select->columns(array(Select::SQL_STAR));
So everything will work correctly.
If in join uses the same technique ( e.g. TRIM(str_column) as str_column ) appears the same error. For this need to reset the column in join. Since it was originally.