Permalink
Browse files

- better handling of quoting identifiers (detection of dots; no new o…

…ption required anymore; c.p. Bug #13025

- fix my fix for Bug #13339 (ORDER BY detection)


git-svn-id: http://svn.php.net/repository/pear/packages/Structures_DataGrid/trunk@256849 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 6d2167a commit d21c9b2f6b0801eb86d1076dbe5db90861cf7ef8 Mark Wiesemann committed Apr 6, 2008
Showing with 9 additions and 12 deletions.
  1. +8 −10 DataGrid/DataSource.php
  2. +1 −2 package2.xml
View
@@ -473,10 +473,6 @@ function dump($offset=0, $len=null, $sortField=null, $sortDir='ASC')
* - count_query: (string) Query that calculates the number of rows. See below
* for more information about when such a count query
* is needed.
- * - quote_identifiers: (bool) Whether identifiers should be quoted or not. If
- * you have field names in the form "table.field",
- * set this option to boolean false; otherwise the
- * automatic quoting might lead to syntax errors.
*
* @author Olivier Guilyardi <olivier@samalyse.com>
* @author Mark Wiesemann <wiesemann@php.net>
@@ -529,8 +525,7 @@ function Structures_DataGrid_DataSource_SQLQuery()
$this->_addDefaultOptions(array('dbc' => null,
'dsn' => null,
'db_options' => array(),
- 'count_query' => '',
- 'quote_identifiers' => true));
+ 'count_query' => ''));
$this->_setFeatures(array('multiSort' => true));
}
@@ -589,10 +584,9 @@ function &fetch($offset = 0, $limit = null)
{
if (!empty($this->_sortSpec)) {
foreach ($this->_sortSpec as $field => $direction) {
- if ($this->_options['quote_identifiers'] === true) {
- $field = $this->_quoteIdentifier($field);
- }
- $sortArray[] = $field . ' ' . $direction;
+ $fields = preg_split('#\.#', $field);
+ $fields = array_map(array($this, '_quoteIdentifier'), $fields);
+ $sortArray[] = join('.', $fields) . ' ' . $direction;
}
$sortString = join(', ', $sortArray);
} else {
@@ -616,6 +610,10 @@ function &fetch($offset = 0, $limit = null)
// yes => new ORDER BY statement needs to be appended
$appendOrderBy = true;
}
+ // if no ORDER BY statement exists, a new one needs to be appended
+ if ($orderByPos === false) {
+ $appendOrderBy = true;
+ }
if ($appendOrderBy === true) {
$query .= ' ORDER BY ' . $sortString;
} else {
View
@@ -47,8 +47,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="http://opensource.org/licenses/bsd-license.php">New BSD</license>
<notes>
- Bug #13025: field names in the form "table.field" could lead to syntax errors
- in the SQL queries of the DBQuery, MDB2, and PDO DataSource drivers; new
- option 'quote_identifiers' allows to disable the automatic quoting
+ in the SQL queries of the DBQuery, MDB2, and PDO DataSource drivers
(thanks to Matt Rosenquist)
- Bug #13339: Automatic ORDER BY sort string addition can fail if subqueries
are used in the the DBQuery, MDB2, and PDO DataSource drivers

0 comments on commit d21c9b2

Please sign in to comment.