[Solar-svn] Revision 2953

pmjones at solarphp.com pmjones at solarphp.com
Tue Nov 20 08:57:05 CST 2007


Solar_Sql_(Select | Adapter | Adapter_Sqlite | Model_Related | Model_Related_HasMany)

* [DEL] Remove the adapter method disambiguate(); instead, use an "AS" on sub-select columns to soothe SQLite.  C.f. <http://osdir.com/ml/db.sqlite.general/2003-05/msg00228.html>.  Remove calls to disambiguate() in Select and Model_Related classes.




Modified: trunk/Solar/Sql/Adapter/Sqlite.php
===================================================================
--- trunk/Solar/Sql/Adapter/Sqlite.php	2007-11-16 16:47:12 UTC (rev 2952)
+++ trunk/Solar/Sql/Adapter/Sqlite.php	2007-11-20 14:57:04 UTC (rev 2953)
@@ -80,26 +80,6 @@
     
     /**
      * 
-     * Disambiguates columns in certain situations.
-     * 
-     * SQLite doesn't like fully-qualified column names sometimes (e.g., in
-     * a `JOIN (SELECT ...) ON ...` clause).  This helps with proper
-     * disambiguation in those circumstances.
-     * 
-     * @param string $table The table name.
-     * 
-     * @param string $col The column name.
-     * 
-     * @return string Just the column name.
-     * 
-     */
-    public function disambiguate($table, $col)
-    {
-        return $col;
-    }
-    
-    /**
-     * 
      * Creates a PDO-style DSN.
      * 
      * For example, "mysql:host=127.0.0.1;dbname=test"

Modified: trunk/Solar/Sql/Adapter.php
===================================================================
--- trunk/Solar/Sql/Adapter.php	2007-11-16 16:47:12 UTC (rev 2952)
+++ trunk/Solar/Sql/Adapter.php	2007-11-20 14:57:04 UTC (rev 2953)
@@ -1003,26 +1003,6 @@
     
     /**
      * 
-     * Disambiguates columns in certain situations.
-     * 
-     * We need this because sometimes we need to put a single column in place,
-     * but some adapters need it fully-qualified, and others fail when it it
-     * fully qualified.  This lets the adapter specify the correct behavior.
-     * 
-     * @param string $table The table name.
-     * 
-     * @param string $col The column name.
-     * 
-     * @return string The fully-qualified column name, "table.col".
-     * 
-     */
-    public function disambiguate($table, $col)
-    {
-        return "$table.$col";
-    }
-    
-    /**
-     * 
      * Returns a SELECT statement built from its component parts.
      * 
      * @param array $parts The component parts of the SELECT.

Modified: trunk/Solar/Sql/Model/Related/HasMany.php
===================================================================
--- trunk/Solar/Sql/Model/Related/HasMany.php	2007-11-16 16:47:12 UTC (rev 2952)
+++ trunk/Solar/Sql/Model/Related/HasMany.php	2007-11-20 14:57:04 UTC (rev 2953)
@@ -212,11 +212,11 @@
             
             // sub-select **only** the native column, so that we're not
             // pulling back everything, just the part we need to join on.
-            // this also helps SQLite, which is picky about fully-qualified
-            // names in sub-selects.
+            // SQLite needs the explicit "AS" here.
+            // <http://osdir.com/ml/db.sqlite.general/2003-05/msg00228.html>
             $clone->clear('cols');
-            $disambig_col = $clone->disambiguate($this->native_alias, $this->native_col);
-            $clone->cols($disambig_col);
+            $primary_col = "{$this->native_alias}.{$this->native_col} AS {$this->native_col}";
+            $clone->cols($primary_col);
             
             $inner = str_replace("\n", "\n\t\t", $clone->fetchSql());
             

Modified: trunk/Solar/Sql/Model/Related.php
===================================================================
--- trunk/Solar/Sql/Model/Related.php	2007-11-16 16:47:12 UTC (rev 2952)
+++ trunk/Solar/Sql/Model/Related.php	2007-11-20 14:57:04 UTC (rev 2953)
@@ -474,9 +474,11 @@
             
             // sub-select **only** the native column, so that we're not
             // pulling back everything, just the part we need to join on.
+            // SQLite needs the explicit "AS" here.
+            // <http://osdir.com/ml/db.sqlite.general/2003-05/msg00228.html>
             $clone->clear('cols');
-            $disambig_col = $clone->disambiguate($this->native_alias, $this->native_col);
-            $clone->cols($disambig_col);
+            $primary_col = "{$this->native_alias}.{$this->native_col} AS {$this->native_col}";
+            $clone->cols($primary_col);
             
             $inner = str_replace("\n", "\n\t\t", $clone->fetchSql());
             

Modified: trunk/Solar/Sql/Select.php
===================================================================
--- trunk/Solar/Sql/Select.php	2007-11-16 16:47:12 UTC (rev 2952)
+++ trunk/Solar/Sql/Select.php	2007-11-20 14:57:04 UTC (rev 2953)
@@ -944,7 +944,7 @@
         // on JOINs of sub-selects.
         // 
         // e.g., `JOIN (SELECT alias.col FROM tbl AS alias) ...`  won't work
-        // right, SQLite needs `JOIN (SELECT col FROM tbl AS alias)`.
+        // right, SQLite needs `JOIN (SELECT col AS col FROM tbl AS alias)`.
         // 
         // @todo Use $this->disambiguate() instead?
         // 




More information about the Solar-svn mailing list