[Solar-svn] Revision 2749
pmjones at solarphp.com
pmjones at solarphp.com
Sat Sep 8 14:49:16 CDT 2007
branch: Solar_Sql_Select:
* [BRK] Public method fetch() is now protected _fetch()
* [CHG] In queries with only one source (e.g., FROM a single table) column names are no longer prefixed. This helps soothe SQLite when using a SELECT as the source for a JOIN (it has problems with the ORDER BY clause in some cases).
Modified: branches/orm/Solar/Sql/Select.php
===================================================================
--- branches/orm/Solar/Sql/Select.php 2007-09-08 18:55:43 UTC (rev 2748)
+++ branches/orm/Solar/Sql/Select.php 2007-09-08 19:49:16 UTC (rev 2749)
@@ -182,7 +182,7 @@
public function __toString()
{
- return $this->fetch('sql');
+ return $this->_fetch('sql');
}
/**
@@ -889,7 +889,7 @@
* @return mixed The query results.
*
*/
- public function fetch($type = 'pdo', $class = null)
+ protected function _fetch($type = 'pdo', $class = null)
{
// does the fetch-method exist? (this allows for extended
// adapters to define their own fetch methods)
@@ -905,6 +905,11 @@
$this->_parts['from'] = array();
$this->_parts['join'] = array();
+ // get a count of how many sources there are. if there's only 1, we
+ // won't use column-name prefixes below. this will help soothe SQLite
+ // on JOINs of sub-selects; e.g., `JOIN (SELECT ...) AS ...`.
+ $count_sources = count($this->_sources);
+
// build from sources.
foreach ($this->_sources as $source) {
@@ -941,10 +946,10 @@
$parens = strpos($col, '(');
// choose our column-name deconfliction strategy
- if ($prefix == '' || $parens) {
- // no prefix (generally because of countPages()).
- // if there are parens in the name, it's a function,
- // so don't prefix it.
+ if ($prefix == '' || $parens || $count_sources == 1) {
+ // - if no prefix, that's a no-brainer.
+ // - if there are parens in the name, it's a function.
+ // - if there's only one source, deconfliction not needed.
$this->_parts['cols'][] = $col;
} else {
// auto deconfliction
@@ -960,52 +965,52 @@
public function fetchAll()
{
- return $this->fetch('all');
+ return $this->_fetch('all');
}
public function fetchAssoc()
{
- return $this->fetch('assoc');
+ return $this->_fetch('assoc');
}
public function fetchCol()
{
- return $this->fetch('col');
+ return $this->_fetch('col');
}
public function fetchValue()
{
- return $this->fetch('value');
+ return $this->_fetch('value');
}
public function fetchPairs()
{
- return $this->fetch('pairs');
+ return $this->_fetch('pairs');
}
public function fetchPdo()
{
- return $this->fetch('pdo');
+ return $this->_fetch('pdo');
}
public function fetchOne()
{
- return $this->fetch('one');
+ return $this->_fetch('one');
}
public function fetchRow($class = null)
{
- return $this->fetch('row', $class);
+ return $this->_fetch('row', $class);
}
public function fetchRowset($class = null)
{
- return $this->fetch('rowset', $class);
+ return $this->_fetch('rowset', $class);
}
public function fetchSql()
{
- return $this->fetch('sql');
+ return $this->_fetch('sql');
}
/**
More information about the Solar-svn
mailing list