Fixed issue with multiple fields in order_by, removed extranious spaces in SQL generation
This commit is contained in:
parent
90c6760196
commit
a4f730b081
14
autoload.php
14
autoload.php
@ -42,6 +42,20 @@ if ( ! function_exists('do_include'))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists('mb_trim'))
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Multibyte-safe trim function
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function mb_trim($string)
|
||||||
|
{
|
||||||
|
return preg_replace("/(^\s+)|(\s+$)/us", "", $string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Query class
|
* Load a Query class
|
||||||
*
|
*
|
||||||
|
@ -211,14 +211,19 @@ abstract class DB_PDO extends PDO {
|
|||||||
return array_map(array($this, 'quote_ident'), $ident);
|
return array_map(array($this, 'quote_ident'), $ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the string is already quoted, return the string
|
// Handle comma-separated identifiers
|
||||||
if (($pos = strpos($ident, $this->escape_char)) !== FALSE && $pos === 0)
|
if (strpos($ident, ',') !== FALSE)
|
||||||
{
|
{
|
||||||
return $ident;
|
$parts = explode(',', $ident);
|
||||||
|
$parts = array_map('mb_trim', $parts);
|
||||||
|
$parts = array_map(array($this, 'quote_ident'), $parts);
|
||||||
|
$ident = implode(',', $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Split each identifier by the period
|
// Split each identifier by the period
|
||||||
$hiers = explode('.', $ident);
|
$hiers = explode('.', $ident);
|
||||||
|
$hiers = array_map('mb_trim', $hiers);
|
||||||
|
|
||||||
// Return the re-compiled string
|
// Return the re-compiled string
|
||||||
return implode('.', array_map(array($this, '_quote'), $hiers));
|
return implode('.', array_map(array($this, '_quote'), $hiers));
|
||||||
@ -234,11 +239,18 @@ abstract class DB_PDO extends PDO {
|
|||||||
*/
|
*/
|
||||||
protected function _quote($str)
|
protected function _quote($str)
|
||||||
{
|
{
|
||||||
|
// Don't quote numbers
|
||||||
if ( ! is_string($str) && is_numeric($str))
|
if ( ! is_string($str) && is_numeric($str))
|
||||||
{
|
{
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't add additional quotes
|
||||||
|
if (strpos($str, $this->escape_char) === 0 || strrpos($str, $this->escape_char) === 0)
|
||||||
|
{
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
return "{$this->escape_char}{$str}{$this->escape_char}";
|
return "{$this->escape_char}{$str}{$this->escape_char}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,13 +161,6 @@ class Query_Builder {
|
|||||||
*/
|
*/
|
||||||
private $having_map;
|
private $having_map;
|
||||||
|
|
||||||
/**
|
|
||||||
* Query parser to safely escape conditions
|
|
||||||
*
|
|
||||||
* @var object
|
|
||||||
*/
|
|
||||||
private $parser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience property for connection management
|
* Convenience property for connection management
|
||||||
*
|
*
|
||||||
@ -859,7 +852,7 @@ class Query_Builder {
|
|||||||
*/
|
*/
|
||||||
public function join($table, $condition, $type='')
|
public function join($table, $condition, $type='')
|
||||||
{
|
{
|
||||||
$table = implode(" ", array_map(array($this->db, 'quote_ident'), explode(' ', trim($table))));
|
$table = implode(' ', array_map(array($this->db, 'quote_ident'), explode(' ', trim($table))));
|
||||||
|
|
||||||
$parser = new query_parser();
|
$parser = new query_parser();
|
||||||
|
|
||||||
|
@ -160,6 +160,19 @@ abstract class QBTest extends UnitTestCase {
|
|||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function TestMultiOrderBy()
|
||||||
|
{
|
||||||
|
if (empty($this->db)) return;
|
||||||
|
|
||||||
|
$query = $this->db->from('create_test')
|
||||||
|
->order_by('id, key')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->assertIsA($query, 'PDOStatement');
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
public function TestSelectAvg()
|
public function TestSelectAvg()
|
||||||
{
|
{
|
||||||
if (empty($this->db)) return;
|
if (empty($this->db)) return;
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user