[Solar-svn] Revision 2946
pmjones at solarphp.com
pmjones at solarphp.com
Thu Nov 15 07:21:29 CST 2007
Solar_Sql_Adapter, Adapter_Sqlite, and Select: [ADD] Added method disambiguate() to help support adapter-specific disambiguation of fully-qualified column names in certain situations (e.g., `JOIN (SELECT ...) ON ...` and single-column additions to SELECT statements).
Modified: trunk/Solar/Sql/Adapter/Sqlite.php
===================================================================
--- trunk/Solar/Sql/Adapter/Sqlite.php 2007-11-14 22:28:33 UTC (rev 2945)
+++ trunk/Solar/Sql/Adapter/Sqlite.php 2007-11-15 13:21:26 UTC (rev 2946)
@@ -80,6 +80,26 @@
/**
*
+ * 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-14 22:28:33 UTC (rev 2945)
+++ trunk/Solar/Sql/Adapter.php 2007-11-15 13:21:26 UTC (rev 2946)
@@ -1003,6 +1003,26 @@
/**
*
+ * 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/Select.php
===================================================================
--- trunk/Solar/Sql/Select.php 2007-11-14 22:28:33 UTC (rev 2945)
+++ trunk/Solar/Sql/Select.php 2007-11-15 13:21:26 UTC (rev 2946)
@@ -941,8 +941,13 @@
// 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 alias.col FROM tbl AS alias) ...`
- // won't work right, it needs `JOIN (SELECT col FROM tbl AS alias)`.
+ // 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)`.
+ //
+ // @todo Use $this->disambiguate() instead?
+ //
$count_sources = count($this->_sources);
// build from sources.
@@ -1204,6 +1209,27 @@
return $this->_sql->quoteMulti($list, $sep);
}
+ /**
+ *
+ * Disambiguates columns in certain situations, per the adapter.
+ *
+ * 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 Some adapters (SQLite) return only the column name,
+ * others return "table.col".
+ *
+ */
+ public function disambiguate($table, $col)
+ {
+ return $this->_sql->disambiguate($table, $col);
+ }
+
// -----------------------------------------------------------------
//
// Protected support functions
More information about the Solar-svn
mailing list