Permalink
Browse files

GH-40 SQLBuilder should prepend table name to fields in apply_where_c…

…onditions if any joins have been specified
  • Loading branch information...
jpfuentes2 committed May 19, 2010
1 parent b782557 commit 53ad5ec0def5df1ddc8d4ffec3b16fcb007974ca
Showing with 24 additions and 2 deletions.
  1. +24 −2 lib/SQLBuilder.php
View
@@ -271,14 +271,36 @@ public static function create_hash_from_underscored_string($name, &$values=array
return $hash;
}
/**
* prepends table name to hash of field names to get around ambiguous fields when SQL builder
* has joins
*
* @param array $hash
* @return array $new
*/
private function prepend_table_name_to_fields($hash=array())
{
$new = array();
$table = $this->connection->quote_name($this->table);
foreach ($hash as $key => $value)
{
$k = $this->connection->quote_name($key);
$new[$table.'.'.$k] = $value;
}
return $new;
}
private function apply_where_conditions($args)
{
require_once 'Expressions.php';
$num_args = count($args);
if ($num_args == 1 && is_hash($args[0]))
{
$e = new Expressions($this->connection,$args[0]);
$hash = is_null($this->joins) ? $args[0] : $this->prepend_table_name_to_fields($args[0]);
$e = new Expressions($this->connection,$hash);
$this->where = $e->to_s();
$this->where_values = array_flatten($e->values());
}
@@ -323,7 +345,7 @@ private function build_insert()
if ($this->sequence)
{
$sql =
"INSERT INTO $this->table($keys," . $this->connection->quote_name($this->sequence[0]) .
"INSERT INTO $this->table($keys," . $this->connection->quote_name($this->sequence[0]) .
") VALUES(?," . $this->connection->next_sequence_value($this->sequence[1]) . ")";
}
else

0 comments on commit 53ad5ec

Please sign in to comment.