Source for file EasyJoin.php
Documentation is available at EasyJoin.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Wolfram Kriesing, Paolo Panto, vision:produktion <wk@visionp.de>
// +----------------------------------------------------------------------+
// $Id: EasyJoin.php,v 1.7 2004/10/13 16:24:47 quipo Exp $
* Load DB_QueryTool_Query class
require_once 'DB/QueryTool/Query.php';
* @author Wolfram Kriesing <wolfram@kriesing.de>
* this is the regular expression that shall be used to find a table's shortName
* in a column name, the string found by using this regular expression will be removed
* from the column name and it will be checked if it is a table name
* i.e. the default '/_id$/' would find the table name 'user' from the column name 'user_id'
var $_tableNamePreg = '/_id$/';
* this is to find the column name that is refered by it, so the default find
* from 'user_id' the column 'id' which will be used to refer to the 'user' table
var $_columnNamePreg = '/^.*_/';
* call parent constructor
* @param mixed $dsn DSN string, DSN array or DB object
* join the tables given, using the column names, to find out how to join the tables
* this is, if table1 has a column names table2_id this method will join
* WHERE table1.table2_id=table2.id
* all joins made here are only concatenated via AND
// FIXXME if $tables is empty autoJoin all available tables that have a relation to $this->table, starting to search in $this->table
// add this->table to the tables array, so we go thru the current table first
//print_r($shortNameIndexed);
//print_r($tables); print '<br><br>';
$this->_errorLog("autoJoin-ERROR: not all the tables are in the tableSpec!<br />");
$joinConditions = array ();
foreach ($tables as $aTable) { // go through $this->table and all the given tables
if ($metadata = $this->metadata($aTable))
foreach ($metadata as $aCol => $x) { // go through each row to check which might be related to $aTable
$possibleTableShortName = preg_replace($this->_tableNamePreg, '' , $aCol);
$possibleColumnName = preg_replace($this->_columnNamePreg, '' , $aCol);
//print "$aTable.$aCol .... possibleTableShortName=$possibleTableShortName .... possibleColumnName=$possibleColumnName<br>";
if (isset ($shortNameIndexed[$possibleTableShortName])) {
// are the tables given in the tableSpec?
if (!$shortNameIndexed[$possibleTableShortName]['name'] ||
!$nameIndexed[$aTable]['name']) {
// its an error of the developer, so log the error, dont show it to the end user
$this->_errorLog(" autoJoin-ERROR: '$aTable' is not given in the tableSpec!<br />" );
// do only join different table.col combination,
// we should not join stuff like 'question.question=question.question' this would be quite stupid, but it used to be :-(
if ($shortNameIndexed[$possibleTableShortName]['name'] != $aTable ||
$possibleColumnName != $aCol
$where = $shortNameIndexed[$possibleTableShortName]['name']." .$possibleColumnName=$aTable.$aCol";
$this->addJoin($nameIndexed[$aTable]['name'], $where);
$this->addJoin($shortNameIndexed[$possibleTableShortName]['name'], $where);
Documentation generated on Mon, 11 Mar 2019 13:57:12 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|