Welcome Guest, Not a member yet? Register   Sign In
A patch for JOINs
#1

[eluser]Sunjith[/eluser]
Hi,

I encountered a problem when selecting from joins. Different tables in the join had columns with same name. Hence selecting those fields from different tables in the select was not possible without specifying dbprefix and table name for each field. Here's a patch (against CI v1.5.3) that would help avoid including of dbprefix with table names everywhere in the select query.

=============================================================
--- DB_active_rec.php 2007-04-15 13:12:38.000000000 +0530
+++ DB_active_rec.php.new 2007-07-01 14:42:09.000000000 +0530
@@ -101,7 +101,7 @@
{
foreach ((array)$from as $val)
{
- $this->ar_from[] = $this->dbprefix.$val;
+ $this->ar_from[] = $this->dbprefix.$val.' AS '.$val;
}
return $this;
}
@@ -135,22 +135,7 @@
}
}

- if ($this->dbprefix)
- {
- $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond);
- }
-
- // If a DB prefix is used we might need to add it to the column names
- if ($this->dbprefix)
- {
- // First we remove any existing prefixes in the condition to avoid duplicates
- $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond);
-
- // Next we add the prefixes to the condition
- $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond);
- }
-
- $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond;
+ $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' AS '.$table.' ON '.$cond;
return $this;
}

=============================================================

Also, with this dbprefix won't be needed in condition.

Thoughts?


Messages In This Thread
A patch for JOINs - by El Forum - 07-01-2007, 04:27 AM
A patch for JOINs - by El Forum - 07-01-2007, 08:52 AM
A patch for JOINs - by El Forum - 07-01-2007, 11:28 PM
A patch for JOINs - by El Forum - 07-02-2007, 12:03 AM
A patch for JOINs - by El Forum - 07-02-2007, 12:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB