* libraries/common.lib.php3, line 70: "invalid" path.
* tbl_printview.php3; tbl_qbe.php3: coding standards and warnings.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -6,11 +6,13 @@ $Id$
|
|||||||
$Source$
|
$Source$
|
||||||
|
|
||||||
2002-04-26 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
2002-04-26 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
||||||
* ## created 2.2.7 branch into the CVS tree ##
|
* ## created 2.2.7 branch into the CVS tree ##
|
||||||
* lang/nowegian.inc.php: updated thanks to Sven-Erik Andersen.
|
* lang/nowegian.inc.php: updated thanks to Sven-Erik Andersen.
|
||||||
* lang/brazilian_portuguese.inc.php3: updated thanks to Renato Lins.
|
* lang/brazilian_portuguese.inc.php3: updated thanks to Renato Lins.
|
||||||
* sql.php3; tbl_replace.php3: patch #547030 - file_exists $goto thanks to
|
* sql.php3; tbl_replace.php3: patch #547030 - file_exists $goto thanks to
|
||||||
Melvyn Sopacua <nyvlem at users.sourceforge.net>.
|
Melvyn Sopacua <nyvlem at users.sourceforge.net>.
|
||||||
|
* libraries/common.lib.php3, line 70: "invalid" path.
|
||||||
|
* tbl_printview.php3; tbl_qbe.php3: coding standards and warnings.
|
||||||
|
|
||||||
2002-04-26 Marc Delisle <lem9@users.sourceforge.net>
|
2002-04-26 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* tbl_qbe.php3: automatic joints from Relation table, thanks
|
* tbl_qbe.php3: automatic joints from Relation table, thanks
|
||||||
|
@@ -72,7 +72,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
|
|||||||
|
|
||||||
// For compatibility with old config.inc.php3
|
// For compatibility with old config.inc.php3
|
||||||
if (!isset($cfg)) {
|
if (!isset($cfg)) {
|
||||||
include('config_import.inc.php3');
|
include('./config_import.inc.php3');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -134,36 +134,36 @@ while (list($key, $table) = each($the_tables)) {
|
|||||||
$result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
$result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
||||||
$fields_cnt = mysql_num_rows($result);
|
$fields_cnt = mysql_num_rows($result);
|
||||||
|
|
||||||
// check if we can use Relations (Mike Beck)
|
// check if we can use Relations (Mike Beck)
|
||||||
$rel_work=FALSE;
|
$rel_work = FALSE;
|
||||||
$rel_query = 'SHOW TABLES';
|
$rel_query = 'SHOW TABLES';
|
||||||
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
while($ctable = @mysql_fetch_array($tables)){
|
while ($ctable = @mysql_fetch_array($tables)) {
|
||||||
if($ctable[0] == $cfg['Server']['relation']){
|
if ($ctable[0] == $cfg['Server']['relation']) {
|
||||||
$rel_work=TRUE;
|
$rel_work = TRUE;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
if($rel_work){
|
if ($rel_work) {
|
||||||
unset($res_rel);
|
unset($res_rel);
|
||||||
// Find which tables are related with the current one and write it in an array
|
// Find which tables are related with the current one and write it in
|
||||||
$rel_query = 'SELECT master_field,concat(foreign_table,\'->\',foreign_field) as rel ';
|
// an array
|
||||||
$rel_query .= 'FROM ' . PMA_backquote($cfg['Server']['relation']);
|
$rel_query = 'SELECT master_field, concat(foreign_table, \'->\', foreign_field) AS rel '
|
||||||
$rel_query .= ' WHERE master_table = \'' . urldecode($table) .'\'';
|
. ' FROM ' . PMA_backquote($cfg['Server']['relation'])
|
||||||
|
. ' WHERE master_table = \'' . urldecode($table) .'\'';
|
||||||
|
|
||||||
$relations = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
$relations = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
$res_rel = array();
|
$res_rel = array();
|
||||||
while ($relrow = @mysql_fetch_array($relations)){
|
while ($relrow = @mysql_fetch_array($relations)) {
|
||||||
$col = $relrow['master_field'];
|
$col = $relrow['master_field'];
|
||||||
$res_rel[$col]=$relrow['rel'];
|
$res_rel[$col] = $relrow['rel'];
|
||||||
//debug echo "col: ".$col." - ". $relrow['rel']."<br>";
|
// debug echo 'col: ' . $col . ' - ' . $relrow['rel'] . '<br />';
|
||||||
}
|
}
|
||||||
if(count($res_rel)>0){
|
if (count($res_rel) > 0) {
|
||||||
$have_rel=TRUE;
|
$have_rel = TRUE;
|
||||||
}else{
|
} else {
|
||||||
$have_rel=FALSE;
|
$have_rel = FALSE;
|
||||||
}
|
}
|
||||||
}
|
} // end if
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,9 +188,10 @@ while (list($key, $table) = each($the_tables)) {
|
|||||||
<th><?php echo ucfirst($strDefault); ?></th>
|
<th><?php echo ucfirst($strDefault); ?></th>
|
||||||
<th><?php echo ucfirst($strExtra); ?></th>
|
<th><?php echo ucfirst($strExtra); ?></th>
|
||||||
<?php
|
<?php
|
||||||
if($rel_work && $have_rel==TRUE){
|
if ($rel_work && $have_rel) {
|
||||||
echo '<th>'. ucfirst($strLinksTo).'</th>';
|
echo '<th>'. ucfirst($strLinksTo) . '</th>';
|
||||||
}
|
}
|
||||||
|
echo "\n";
|
||||||
?>
|
?>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@@ -241,26 +242,29 @@ while (list($key, $table) = each($the_tables)) {
|
|||||||
echo "\n";
|
echo "\n";
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php
|
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
|
||||||
if (isset($pk_array[$row['Field']])) {
|
<?php
|
||||||
echo '<u>' . $field_name . '</u>';
|
if (isset($pk_array[$row['Field']])) {
|
||||||
} else {
|
echo ' <u>' . $field_name . '</u> ' . "\n";
|
||||||
echo $field_name;
|
} else {
|
||||||
}
|
echo ' ' . $field_name . ' ' . "\n";
|
||||||
?> </td>
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
|
<td bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>
|
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
|
<td bgcolor="<?php echo $bgcolor; ?>"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
|
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
|
||||||
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>
|
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>
|
||||||
<?php
|
<?php
|
||||||
if($rel_work && $have_rel==TRUE){
|
if ($rel_work && $have_rel) {
|
||||||
echo '<td bgcolor="' . $bgcolor . '" nowrap="nowrap">';
|
echo '<td bgcolor="' . $bgcolor . '" nowrap="nowrap">';
|
||||||
if (isset($res_rel[$field_name])) {
|
if (isset($res_rel[$field_name])) {
|
||||||
echo htmlspecialchars($res_rel[$field_name]);
|
echo htmlspecialchars($res_rel[$field_name]);
|
||||||
}
|
}
|
||||||
echo ' </td>' . "\n";
|
echo ' </td>';
|
||||||
}
|
}
|
||||||
|
echo "\n";
|
||||||
?>
|
?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
|
364
tbl_qbe.php3
364
tbl_qbe.php3
@@ -690,216 +690,228 @@ if (!empty($qry_select)) {
|
|||||||
|
|
||||||
// 2. FROM
|
// 2. FROM
|
||||||
|
|
||||||
// Create LEFT JOINS out of Relations
|
// Create LEFT JOINS out of Relations
|
||||||
// Code originally by Mike Beck<mike.beck@ibmiller.de>
|
// Code originally by Mike Beck <mike.beck@ibmiller.de>
|
||||||
// If we can use Relations we could make some left joins
|
// If we can use Relations we could make some left joins
|
||||||
// First find out if relations are available in this database
|
// First find out if relations are available in this database
|
||||||
|
|
||||||
// First we need the really needed Tables - those in TableList might
|
// First we need the really needed Tables - those in TableList might
|
||||||
// still be all Tables.
|
// still be all Tables.
|
||||||
if(count($Field)>0){
|
if (count($Field) > 0) {
|
||||||
|
|
||||||
// we only start this if we have fields, otherwise it would be dumb
|
// we only start this if we have fields, otherwise it would be dumb
|
||||||
while (list(, $value) = each ($Field)) {
|
while (list(, $value) = each ($Field)) {
|
||||||
$parts = explode('.',$value);
|
$parts = explode('.', $value);
|
||||||
if(urldecode($parts[0])!=''){
|
if (urldecode($parts[0]) != '') {
|
||||||
$alltabs_b[] = urldecode($parts[0]);
|
$alltabs_b[] = urldecode($parts[0]);
|
||||||
$alltabs[] =substr(urldecode($parts[0]),1,strlen(urldecode($parts[0]))-2);
|
$alltabs[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2);
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
$rel_work=FALSE;
|
$rel_work = FALSE;
|
||||||
$rel_query = 'SHOW TABLES';
|
$rel_query = 'SHOW TABLES';
|
||||||
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
while($ctable = @mysql_fetch_array($tables)){
|
while ($ctable = @mysql_fetch_array($tables)) {
|
||||||
if($ctable[0] == $cfg['Server']['relation']){
|
if ($ctable[0] == $cfg['Server']['relation']) {
|
||||||
$rel_work=TRUE;
|
$rel_work = TRUE;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
if($rel_work && count($alltabs)>0){
|
if ($rel_work && count($alltabs) > 0) {
|
||||||
|
|
||||||
// now we need all tables that we have in the whereclause
|
// now we need all tables that we have in the whereclause
|
||||||
for ($x = 0; $x < $col; $x++) {
|
for ($x = 0; $x < $col; $x++) {
|
||||||
$wtable=explode('.',$curField[$x]);
|
$wtable = explode('.', $curField[$x]);
|
||||||
$ctable= str_replace('`', '',$wtable[0]);
|
$ctable = str_replace('`', '', $wtable[0]);
|
||||||
if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
|
if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
|
||||||
if($where[$ctable]!='='){
|
if ($where[$ctable] != '=') {
|
||||||
$where[$ctable]=substr($curCriteria[$x],0,1);
|
$where[$ctable] = substr($curCriteria[$x], 0, 1);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($where)>1){
|
|
||||||
// if we have enough whereclauses then we want those that have
|
|
||||||
// a '=' (not for example 'like'
|
|
||||||
while (list($key,$value) = each ($where)){
|
|
||||||
if($value=='='){
|
|
||||||
$wheretabs[]=$key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // end for
|
||||||
|
|
||||||
|
|
||||||
// if there was nothing starting with '=' we have to use all we got in the
|
if (count($where) > 1) {
|
||||||
// first place (in this case we can use & here - if it works with old versions
|
// if we have enough whereclauses then we want those that have
|
||||||
// of php ??
|
// a '=' (not for example 'like')
|
||||||
if(count($wheretabs)==0){
|
while (list($key, $value) = each($where)) {
|
||||||
$wheretabs=$where;
|
if ($value == '=') {
|
||||||
}
|
$wheretabs[] = $key;
|
||||||
// i expect it will make sense to have the table which is most often
|
}
|
||||||
// found as foreign_table as the one to start our FROM...
|
|
||||||
// but we have to make sure that if there is a WHERE clause then we have
|
|
||||||
// a master out of those that are used there
|
|
||||||
|
|
||||||
// We will need this a few times:
|
|
||||||
$incrit = '(\''. str_replace(',', "','", implode(',',$alltabs)) . '\')';
|
|
||||||
|
|
||||||
$rel_query = 'SELECT master_table as wer,count(foreign_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
|
|
||||||
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit;
|
|
||||||
$rel_query .= ' GROUP by master_table ORDER by hits desc ';
|
|
||||||
|
|
||||||
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
|
||||||
|
|
||||||
// if we don't find anything we try the other way round
|
|
||||||
if(mysql_num_rows($rel_id)==0){
|
|
||||||
$rel_query = 'SELECT foreign_table as wer,count(master_table) as hits from '.PMA_backquote($cfg['Server']['relation']);
|
|
||||||
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit;
|
|
||||||
$rel_query .= ' GROUP by foreign_table ORDER by hits desc ';
|
|
||||||
|
|
||||||
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
|
||||||
}
|
|
||||||
while ($row = mysql_fetch_array($rel_id)){
|
|
||||||
// we want the first one (highest number of hits) or
|
|
||||||
// the first one that is in the WHERE clause
|
|
||||||
if(!isset($master)){
|
|
||||||
$master = $row['wer'];
|
|
||||||
}else{
|
|
||||||
// remember that we found more than one because
|
|
||||||
// this means we need to refine more
|
|
||||||
$hit=2;
|
|
||||||
}
|
}
|
||||||
if(is_array($wheretabs)){
|
} // end if
|
||||||
while (list($key, $value) = each ($wheretabs)){
|
|
||||||
if($row['master_table']==$key){
|
|
||||||
|
// if there was nothing starting with '=' we have to use all we got in
|
||||||
|
// the first place (in this case we can use & here - if it works with
|
||||||
|
// old versions of php ??)
|
||||||
|
if (count($wheretabs) == 0) {
|
||||||
|
$wheretabs = $where;
|
||||||
|
}
|
||||||
|
// I expect it will make sense to have the table which is most often
|
||||||
|
// found as foreign_table as the one to start our FROM...
|
||||||
|
// but we have to make sure that if there is a WHERE clause then we
|
||||||
|
// have a master out of those that are used there
|
||||||
|
|
||||||
|
// We will need this a few times:
|
||||||
|
$incrit = '(\'' . str_replace(',', "','", implode(',', $alltabs)) . '\')';
|
||||||
|
|
||||||
|
$rel_query = 'SELECT master_table AS wer, COUNT(foreign_table) AS hits FROM ' . PMA_backquote($cfg['Server']['relation'])
|
||||||
|
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
|
||||||
|
. ' GROUP BY master_table ORDER BY hits DESC';
|
||||||
|
|
||||||
|
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
|
|
||||||
|
// if we don't find anything we try the other way round
|
||||||
|
if (mysql_num_rows($rel_id) == 0) {
|
||||||
|
$rel_query = 'SELECT foreign_table AS wer, COUNT(master_table) AS hits FROM ' . PMA_backquote($cfg['Server']['relation'])
|
||||||
|
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
|
||||||
|
. ' GROUP BY foreign_table ORDER BY hits DESC';
|
||||||
|
|
||||||
|
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
|
}
|
||||||
|
while ($row = mysql_fetch_array($rel_id)) {
|
||||||
|
// we want the first one (highest number of hits) or the first one
|
||||||
|
// that is in the WHERE clause
|
||||||
|
if (!isset($master)) {
|
||||||
|
$master = $row['wer'];
|
||||||
|
} else {
|
||||||
|
// remember that we found more than one because this means we
|
||||||
|
// need to refine more
|
||||||
|
$hit = 2;
|
||||||
|
} // end if.. else...
|
||||||
|
if (is_array($wheretabs)) {
|
||||||
|
while (list($key, $value) = each($wheretabs)) {
|
||||||
|
if ($row['master_table'] == $key) {
|
||||||
$master = $row['wer'];
|
$master = $row['wer'];
|
||||||
$ex=1;
|
$ex = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
|
} // end if
|
||||||
|
if ($ex == 1) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ($ex==1){break;}
|
} // end while
|
||||||
}
|
|
||||||
|
|
||||||
if($ex ==1||$hit!=2){
|
if ($ex ==1 || $hit != 2) {
|
||||||
// if $ex is not 1 then obviously none of the tables
|
// if $ex is not 1 then obviously none of the tables that are used
|
||||||
// that are used in the whereclause could be found -
|
// in the whereclause could be found - that means that using left
|
||||||
// that means that using left joins doesn't make much sense anyway
|
// joins doesn't make much sense anyway
|
||||||
|
|
||||||
if($master != ''){
|
if ($master != '') {
|
||||||
$qry_from = PMA_backquote($master);
|
$qry_from = PMA_backquote($master);
|
||||||
}
|
}
|
||||||
// now we want one Array that has all tablenames but master
|
|
||||||
|
|
||||||
while (list(, $value) = each ($alltabs)) {
|
|
||||||
if($value != $master){
|
|
||||||
$reltabs[] = $value;
|
|
||||||
$rel[$value]['mcon']=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// now we only use everything but the first table
|
|
||||||
$incrit_s = '(\''. str_replace(',', "','", implode(',',$reltabs)) . '\')';
|
|
||||||
|
|
||||||
$rel_query = 'SELECT * from '.PMA_backquote($cfg['Server']['relation']);
|
|
||||||
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit_s;
|
|
||||||
$rel_query .= ' ORDER by foreign_table,master_table ';
|
|
||||||
|
|
||||||
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
// now we want one Array that has all tablenames but master
|
||||||
|
while (list(, $value) = each($alltabs)) {
|
||||||
while ($row = mysql_fetch_array($rel_id)){
|
if ($value != $master) {
|
||||||
|
$reltabs[] = $value;
|
||||||
|
$rel[$value]['mcon'] =0;
|
||||||
|
}
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
// now we only use everything but the first table
|
||||||
|
$incrit_s = '(\'' . str_replace(',', "','", implode(',', $reltabs)) . '\')';
|
||||||
|
|
||||||
|
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation'])
|
||||||
|
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s
|
||||||
|
. ' ORDER BY foreign_table, master_table ';
|
||||||
|
|
||||||
|
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
|
|
||||||
|
while ($row = mysql_fetch_array($rel_id)) {
|
||||||
$foreign_table = $row['foreign_table'];
|
$foreign_table = $row['foreign_table'];
|
||||||
if($rel[$foreign_table]['mcon']==0){
|
if ($rel[$foreign_table]['mcon'] == 0) {
|
||||||
// if we allready found a link to the mastertable we don't want another
|
// if we already found a link to the mastertable we don't
|
||||||
// otherwise we take whatever we get
|
// want another otherwise we take whatever we get
|
||||||
$rel[$foreign_table]['link'] = ' LEFT JOIN '.PMA_backquote($foreign_table);
|
$rel[$foreign_table]['link'] = ' LEFT JOIN ' . PMA_backquote($foreign_table)
|
||||||
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['master_table']).'.'.PMA_backquote($row['master_field']);
|
. ' ON ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field'])
|
||||||
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']) .' ';
|
. ' = ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field'])
|
||||||
|
. ' ';
|
||||||
}
|
}
|
||||||
if($row['master_table'] == $master){
|
if ($row['master_table'] == $master) {
|
||||||
$rel[$foreign_table]['mcon']=1;
|
$rel[$foreign_table]['mcon'] = 1;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
// possibly we still don't have all - there might be some that are
|
// possibly we still don't have all - there might be some that are
|
||||||
// only found as a foreign_table in relation to one of those that we allready have
|
// only found as a foreign_table in relation to one of those that we
|
||||||
if($master!=''){
|
// already have
|
||||||
$found[] = $master;
|
if ($master != '') {
|
||||||
|
$found[] = $master;
|
||||||
$qry_from = PMA_backquote($master);
|
$qry_from = PMA_backquote($master);
|
||||||
}
|
} // end if
|
||||||
|
|
||||||
while (list($key, $varr) = each ($rel)) {
|
while (list($key, $varr) = each($rel)) {
|
||||||
if($varr['link'] == ''){
|
if ($varr['link'] == '') {
|
||||||
$rest[] = $key;
|
$rest[] = $key;
|
||||||
}else{
|
} else {
|
||||||
$found[] = $key;
|
$found[] = $key;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
if(is_array($rest) && is_array($found) && count($rest)>0){
|
if (is_array($rest) && is_array($found) && count($rest) > 0) {
|
||||||
$incrit_d = '(\''. str_replace(',', "','", implode(',',$found)) . '\')';
|
$incrit_d = '(\'' . str_replace(',', "','", implode(',', $found)) . '\')';
|
||||||
$incrit_s = '(\''. str_replace(',', "','", implode(',',$rest)) . '\')';
|
$incrit_s = '(\'' . str_replace(',', "','", implode(',', $rest)) . '\')';
|
||||||
|
|
||||||
$rel_query = 'SELECT * from '.$cfg['Server']['relation'];
|
$rel_query = 'SELECT * FROM ' . $cfg['Server']['relation']
|
||||||
$rel_query .= ' WHERE master_table IN '.$incrit_s.' AND foreign_table in '.$incrit_d;
|
. ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d
|
||||||
$rel_query .= ' ORDER by master_table,foreign_table ';
|
. ' ORDER BY master_table, foreign_table';
|
||||||
|
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
||||||
$rel_id = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
|
||||||
while ($row = mysql_fetch_array($rel_id)){
|
while ($row = mysql_fetch_array($rel_id)) {
|
||||||
$foreign_table = $row['foreign_table'];
|
$foreign_table = $row['foreign_table'];
|
||||||
// echo 'pr<70>fe '.$master_table;
|
if ($rel[$foreign_table]['mcon'] == 0) {
|
||||||
if($rel[$foreign_table]['mcon']==0){
|
// if we allready found a link to the mastertable we
|
||||||
// if we allready found a link to the mastertable we don't want another
|
// don't want another otherwise we take whatever we get
|
||||||
// otherwise we take whatever we get
|
$rel[$foreign_table]['link'] = ' LEFT JOIN ' . $foreign_table
|
||||||
$rel[$foreign_table]['link'] = ' LEFT JOIN '.$foreign_table;
|
. ' ON ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field'])
|
||||||
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']);
|
. ' = ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field']) . ' ';
|
||||||
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['master_table']).'.'.PMA_backquote($row['master_field']) .' ';
|
|
||||||
|
// in extreme cases we hadn't found a master yet, so
|
||||||
// in extreme cases we hadn't found a master yet, so let's use
|
// let's use the one we found now
|
||||||
// the one we found now
|
$master = $row['foreign_table'];
|
||||||
$master = $row['foreign_table'];
|
|
||||||
}
|
}
|
||||||
if($row['master_table'] == $master){
|
if ($row['master_table'] == $master) {
|
||||||
$rel[$foreign_table]['mcon']=1;
|
$rel[$foreign_table]['mcon'] = 1;
|
||||||
}
|
}
|
||||||
}
|
} // end while
|
||||||
}
|
} // end if
|
||||||
// now let's see what we found - every table that doesn't have a link gets
|
|
||||||
// added directly to the FROM the links go to a second variable $lj which is added afterwards
|
// now let's see what we found - every table that doesn't have a
|
||||||
reset ($rel);
|
// link gets added directly to the FROM the links go to a second
|
||||||
while (list($key, $varr) = each ($rel)) {
|
// variable $lj which is added afterwards
|
||||||
if($varr['link'] == ''){
|
$lj = '';
|
||||||
if($qry_from != ''){
|
$ljm = '';
|
||||||
|
reset($rel);
|
||||||
|
while (list($key, $varr) = each($rel)) {
|
||||||
|
if ($varr['link'] == '') {
|
||||||
|
if ($qry_from != '') {
|
||||||
$qry_from .= ',';
|
$qry_from .= ',';
|
||||||
}
|
}
|
||||||
$qry_from .= PMA_backquote($key);
|
$qry_from .= PMA_backquote($key);
|
||||||
// echo 'add '.$key;
|
} else if ($varr['mcon'] == 0) {
|
||||||
}else{
|
// those that have no link with the mastertable we will
|
||||||
if($varr['mcon']==0){
|
// show at the end
|
||||||
// those that have no link with the mastertable we will show at the end
|
$lj .= $varr['link'];
|
||||||
$lj .= $varr['link'];
|
} else {
|
||||||
}else{
|
$ljm .= $varr['link'];
|
||||||
$ljm .= $varr['link'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
// on one occasion i had qry_from at this point end with a , as I
|
||||||
|
// can't find why this happened i check this now:
|
||||||
|
if (substr($qry_from, strlen($qry_from) - 1, 1) == ',') {
|
||||||
|
$qry_from = substr($qry_from, 0, strlen($qry_from));
|
||||||
}
|
}
|
||||||
// on one occasion i had qry_from at this point end with a ,
|
$qry_from .= $ljm . $lj;
|
||||||
// as i can't find why this happened i check this now:
|
|
||||||
if(substr($qry_from, strlen($qry_from)-1,1)==','){
|
} // end $ex == 1 (testing if it is worth the pain)
|
||||||
$qry_from =substr($qry_from,0,strlen($qry_from));
|
|
||||||
}
|
} // end rel work and $alltabs > 0
|
||||||
$qry_from .= $ljm.$lj;
|
|
||||||
} // End $ex==1 (testing if it is worth the pain
|
if (empty($qry_from) && is_array($alltabs)) {
|
||||||
}// End rel work and $alltabs>0
|
$qry_from = implode(',', $alltabs);
|
||||||
if(empty($qry_from) && is_array($alltabs)) {
|
}
|
||||||
$qry_from=implode(',',$alltabs);
|
|
||||||
}
|
} // end count($Field) > 0
|
||||||
} // End count($Field)>0
|
|
||||||
if (!empty($qry_from)) {
|
if (!empty($qry_from)) {
|
||||||
$encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
|
$encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
|
||||||
echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
|
echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
|
||||||
|
Reference in New Issue
Block a user