* libraries/common.lib.php3, line 70: "invalid" path.

* tbl_printview.php3; tbl_qbe.php3: coding standards and warnings.
This commit is contained in:
Loïc Chapeaux
2002-04-26 17:08:44 +00:00
parent 5677d360b6
commit 8d120c7cd6
4 changed files with 241 additions and 223 deletions

View File

@@ -11,6 +11,8 @@ $Source$
* lang/brazilian_portuguese.inc.php3: updated thanks to Renato Lins.
* sql.php3; tbl_replace.php3: patch #547030 - file_exists $goto thanks to
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>
* tbl_qbe.php3: automatic joints from Relation table, thanks

View File

@@ -72,7 +72,7 @@ if (!defined('PMA_COMMON_LIB_INCLUDED')){
// For compatibility with old config.inc.php3
if (!isset($cfg)) {
include('config_import.inc.php3');
include('./config_import.inc.php3');
}
/**

View File

@@ -142,28 +142,28 @@ while (list($key, $table) = each($the_tables)) {
if ($ctable[0] == $cfg['Server']['relation']) {
$rel_work = TRUE;
}
}
} // end while
if ($rel_work) {
unset($res_rel);
// Find which tables are related with the current one and write it in an array
$rel_query = 'SELECT master_field,concat(foreign_table,\'->\',foreign_field) as rel ';
$rel_query .= 'FROM ' . PMA_backquote($cfg['Server']['relation']);
$rel_query .= ' WHERE master_table = \'' . urldecode($table) .'\'';
// Find which tables are related with the current one and write it in
// an array
$rel_query = 'SELECT master_field, concat(foreign_table, \'->\', foreign_field) AS rel '
. ' FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table = \'' . urldecode($table) .'\'';
$relations = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
$res_rel = array();
while ($relrow = @mysql_fetch_array($relations)) {
$col = $relrow['master_field'];
$res_rel[$col] = $relrow['rel'];
//debug echo "col: ".$col." - ". $relrow['rel']."<br>";
// debug echo 'col: ' . $col . ' - ' . $relrow['rel'] . '<br />';
}
if (count($res_rel) > 0) {
$have_rel = TRUE;
} else {
$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($strExtra); ?></th>
<?php
if($rel_work && $have_rel==TRUE){
if ($rel_work && $have_rel) {
echo '<th>'. ucfirst($strLinksTo) . '</th>';
}
echo "\n";
?>
</tr>
@@ -241,26 +242,29 @@ while (list($key, $table) = each($the_tables)) {
echo "\n";
?>
<tr>
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
<?php
if (isset($pk_array[$row['Field']])) {
echo '<u>' . $field_name . '</u>';
echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
} else {
echo $field_name;
echo ' ' . $field_name . '&nbsp;' . "\n";
}
?>&nbsp;</td>
?>
</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; ?>"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>
<?php
if($rel_work && $have_rel==TRUE){
if ($rel_work && $have_rel) {
echo '<td bgcolor="' . $bgcolor . '" nowrap="nowrap">';
if (isset($res_rel[$field_name])) {
echo htmlspecialchars($res_rel[$field_name]);
}
echo '&nbsp;</td>' . "\n";
echo '&nbsp;</td>';
}
echo "\n";
?>
</tr>
<?php

View File

@@ -706,7 +706,7 @@ if(count($Field)>0){
$alltabs_b[] = urldecode($parts[0]);
$alltabs[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2);
}
}
} // end while
$rel_work = FALSE;
$rel_query = 'SHOW TABLES';
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
@@ -714,7 +714,7 @@ if(count($Field)>0){
if ($ctable[0] == $cfg['Server']['relation']) {
$rel_work = TRUE;
}
}
} // end while
if ($rel_work && count($alltabs) > 0) {
// now we need all tables that we have in the whereclause
@@ -726,57 +726,57 @@ if(count($Field)>0){
$where[$ctable] = substr($curCriteria[$x], 0, 1);
}
}
}
} // end for
if (count($where) > 1) {
// if we have enough whereclauses then we want those that have
// a '=' (not for example 'like'
// a '=' (not for example 'like')
while (list($key, $value) = each($where)) {
if ($value == '=') {
$wheretabs[] = $key;
}
}
}
} // end if
// 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 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
// 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
// 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_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']);
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit;
$rel_query .= ' GROUP by foreign_table ORDER by hits desc ';
$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
// 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
// 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) {
@@ -784,55 +784,60 @@ if(count($Field)>0){
$ex = 1;
break;
}
} // end while
} // end if
if ($ex == 1) {
break;
}
}
if ($ex==1){break;}
}
} // end while
if ($ex ==1 || $hit != 2) {
// if $ex is not 1 then obviously none of the tables
// that are used in the whereclause could be found -
// that means that using left joins doesn't make much sense anyway
// if $ex is not 1 then obviously none of the tables that are used
// in the whereclause could be found - that means that using left
// joins doesn't make much sense anyway
if ($master != '') {
$qry_from = PMA_backquote($master);
}
// now we want one Array that has all tablenames but 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;
}
}
} // 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']);
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit_s;
$rel_query .= ' ORDER by foreign_table,master_table ';
$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'];
if ($rel[$foreign_table]['mcon'] == 0) {
// if we allready found a link to the mastertable we don't want another
// otherwise we take whatever we get
$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']);
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']) .' ';
// if we already found a link to the mastertable we don't
// want another otherwise we take whatever we get
$rel[$foreign_table]['link'] = ' LEFT JOIN ' . PMA_backquote($foreign_table)
. ' ON ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field'])
. ' = ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field'])
. ' ';
}
if ($row['master_table'] == $master) {
$rel[$foreign_table]['mcon'] = 1;
}
}
} // end while
// 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
// already have
if ($master != '') {
$found[] = $master;
$qry_from = PMA_backquote($master);
}
} // end if
while (list($key, $varr) = each($rel)) {
if ($varr['link'] == '') {
@@ -840,37 +845,40 @@ if(count($Field)>0){
} else {
$found[] = $key;
}
}
} // end while
if (is_array($rest) && is_array($found) && count($rest) > 0) {
$incrit_d = '(\'' . str_replace(',', "','", implode(',', $found)) . '\')';
$incrit_s = '(\'' . str_replace(',', "','", implode(',', $rest)) . '\')';
$rel_query = 'SELECT * from '.$cfg['Server']['relation'];
$rel_query .= ' WHERE master_table IN '.$incrit_s.' AND foreign_table in '.$incrit_d;
$rel_query .= ' ORDER by master_table,foreign_table ';
$rel_query = 'SELECT * FROM ' . $cfg['Server']['relation']
. ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d
. ' ORDER BY master_table, foreign_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'];
// echo 'pr<70>fe '.$master_table;
if ($rel[$foreign_table]['mcon'] == 0) {
// if we allready found a link to the mastertable we don't want another
// otherwise we take whatever we get
$rel[$foreign_table]['link'] = ' LEFT JOIN '.$foreign_table;
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']);
$rel[$foreign_table]['link'] .= ' = '.PMA_backquote($row['master_table']).'.'.PMA_backquote($row['master_field']) .' ';
// if we allready found a link to the mastertable we
// don't want another otherwise we take whatever we get
$rel[$foreign_table]['link'] = ' LEFT JOIN ' . $foreign_table
. ' ON ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field'])
. ' = ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field']) . ' ';
// in extreme cases we hadn't found a master yet, so let's use
// the one we found now
// in extreme cases we hadn't found a master yet, so
// let's use the one we found now
$master = $row['foreign_table'];
}
if ($row['master_table'] == $master) {
$rel[$foreign_table]['mcon'] = 1;
}
}
}
// 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
} // 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
$lj = '';
$ljm = '';
reset($rel);
while (list($key, $varr) = each($rel)) {
if ($varr['link'] == '') {
@@ -878,28 +886,32 @@ if(count($Field)>0){
$qry_from .= ',';
}
$qry_from .= PMA_backquote($key);
// echo 'add '.$key;
}else{
if($varr['mcon']==0){
// those that have no link with the mastertable we will show at the end
} else if ($varr['mcon'] == 0) {
// those that have no link with the mastertable we will
// show at the end
$lj .= $varr['link'];
} else {
$ljm .= $varr['link'];
}
}
}
// 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:
} // 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));
}
$qry_from .= $ljm . $lj;
} // End $ex==1 (testing if it is worth the pain
}// End rel work and $alltabs>0
} // end $ex == 1 (testing if it is worth the pain)
} // end rel work and $alltabs > 0
if (empty($qry_from) && is_array($alltabs)) {
$qry_from = implode(',', $alltabs);
}
} // End count($Field)>0
} // end count($Field) > 0
if (!empty($qry_from)) {
$encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
echo 'FROM ' . htmlspecialchars($qry_from) . "\n";