* 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. * 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

View File

@@ -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');
} }
/** /**

View File

@@ -142,28 +142,28 @@ while (list($key, $table) = each($the_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">
<?php
if (isset($pk_array[$row['Field']])) { if (isset($pk_array[$row['Field']])) {
echo '<u>' . $field_name . '</u>'; echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
} else { } 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; ?>"<?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); ?>&nbsp;</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 if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
<td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td> <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</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 '&nbsp;</td>' . "\n"; echo '&nbsp;</td>';
} }
echo "\n";
?> ?>
</tr> </tr>
<?php <?php

View File

@@ -706,7 +706,7 @@ if(count($Field)>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);
@@ -714,7 +714,7 @@ if(count($Field)>0){
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
@@ -726,57 +726,57 @@ if(count($Field)>0){
$where[$ctable] = substr($curCriteria[$x], 0, 1); $where[$ctable] = substr($curCriteria[$x], 0, 1);
} }
} }
} } // end for
if (count($where) > 1) { if (count($where) > 1) {
// if we have enough whereclauses then we want those that have // 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)) { while (list($key, $value) = each($where)) {
if ($value == '=') { if ($value == '=') {
$wheretabs[] = $key; $wheretabs[] = $key;
} }
} }
} } // end if
// if there was nothing starting with '=' we have to use all we got in the // if there was nothing starting with '=' we have to use all we got in
// first place (in this case we can use & here - if it works with old versions // the first place (in this case we can use & here - if it works with
// of php ?? // old versions of php ??)
if (count($wheretabs) == 0) { if (count($wheretabs) == 0) {
$wheretabs = $where; $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... // 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 // but we have to make sure that if there is a WHERE clause then we
// a master out of those that are used there // have a master out of those that are used there
// We will need this a few times: // We will need this a few times:
$incrit = '(\'' . str_replace(',', "','", implode(',', $alltabs)) . '\')'; $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 = '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; . ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
$rel_query .= ' GROUP by master_table ORDER by hits desc '; . ' GROUP BY master_table ORDER BY hits DESC';
$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);
// if we don't find anything we try the other way round // if we don't find anything we try the other way round
if (mysql_num_rows($rel_id) == 0) { 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 = '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; . ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
$rel_query .= ' GROUP by foreign_table ORDER by hits desc '; . ' GROUP BY foreign_table ORDER BY hits DESC';
$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)) {
// we want the first one (highest number of hits) or // we want the first one (highest number of hits) or the first one
// the first one that is in the WHERE clause // that is in the WHERE clause
if (!isset($master)) { if (!isset($master)) {
$master = $row['wer']; $master = $row['wer'];
} else { } else {
// remember that we found more than one because // remember that we found more than one because this means we
// this means we need to refine more // need to refine more
$hit = 2; $hit = 2;
} } // end if.. else...
if (is_array($wheretabs)) { if (is_array($wheretabs)) {
while (list($key, $value) = each($wheretabs)) { while (list($key, $value) = each($wheretabs)) {
if ($row['master_table'] == $key) { if ($row['master_table'] == $key) {
@@ -784,55 +784,60 @@ if(count($Field)>0){
$ex = 1; $ex = 1;
break; break;
} }
} // end while
} // end if
if ($ex == 1) {
break;
} }
} } // end while
if ($ex==1){break;}
}
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
// now we want one Array that has all tablenames but master
while (list(, $value) = each($alltabs)) { while (list(, $value) = each($alltabs)) {
if ($value != $master) { if ($value != $master) {
$reltabs[] = $value; $reltabs[] = $value;
$rel[$value]['mcon'] =0; $rel[$value]['mcon'] =0;
} }
} } // end while
// now we only use everything but the first table // now we only use everything but the first table
$incrit_s = '(\'' . str_replace(',', "','", implode(',', $reltabs)) . '\')'; $incrit_s = '(\'' . str_replace(',', "','", implode(',', $reltabs)) . '\')';
$rel_query = 'SELECT * from '.PMA_backquote($cfg['Server']['relation']); $rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation'])
$rel_query .= ' WHERE master_table IN '.$incrit.' AND foreign_table in '.$incrit_s; . ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s
$rel_query .= ' ORDER by foreign_table,master_table '; . ' ORDER BY foreign_table, master_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'];
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
// already have
if ($master != '') { if ($master != '') {
$found[] = $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'] == '') {
@@ -840,37 +845,40 @@ if(count($Field)>0){
} 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 don't want another // if we allready found a link to the mastertable we
// otherwise we take whatever we get // don't want another otherwise we take whatever we get
$rel[$foreign_table]['link'] = ' LEFT JOIN '.$foreign_table; $rel[$foreign_table]['link'] = ' LEFT JOIN ' . $foreign_table
$rel[$foreign_table]['link'] .= ' ON '.PMA_backquote($row['foreign_table']).'.'.PMA_backquote($row['foreign_field']); . ' 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']) .' '; . ' = ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field']) . ' ';
// in extreme cases we hadn't found a master yet, so let's use // in extreme cases we hadn't found a master yet, so
// the one we found now // let's use 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
// link gets added directly to the FROM the links go to a second
// variable $lj which is added afterwards
$lj = '';
$ljm = '';
reset($rel); reset($rel);
while (list($key, $varr) = each($rel)) { while (list($key, $varr) = each($rel)) {
if ($varr['link'] == '') { if ($varr['link'] == '') {
@@ -878,28 +886,32 @@ if(count($Field)>0){
$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 , // on one occasion i had qry_from at this point end with a , as I
// as i can't find why this happened i check this now: // can't find why this happened i check this now:
if (substr($qry_from, strlen($qry_from) - 1, 1) == ',') { if (substr($qry_from, strlen($qry_from) - 1, 1) == ',') {
$qry_from = substr($qry_from, 0, strlen($qry_from)); $qry_from = substr($qry_from, 0, strlen($qry_from));
} }
$qry_from .= $ljm . $lj; $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)) { if (empty($qry_from) && is_array($alltabs)) {
$qry_from = implode(',', $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";