Optimization, warnings and coding standards

This commit is contained in:
Loïc Chapeaux
2002-04-27 17:30:12 +00:00
parent e8bec3ac5e
commit f25cd2c3a3
3 changed files with 54 additions and 60 deletions

View File

@@ -23,6 +23,8 @@ $Source$
translations thanks to Sime Essert <sime@nofrx.org>. translations thanks to Sime Essert <sime@nofrx.org>.
* tbl_properties.php3, lines 1238-1240: fix new fields names in the * tbl_properties.php3, lines 1238-1240: fix new fields names in the
relation table. relation table.
* tbl_printview.php3; tbl_qbe.php3: optimization, warnings and coding
standards.
* Compressed ChangeLog till the 2.2.6 release. * Compressed ChangeLog till the 2.2.6 release.
2002-04-26 Lo<4C>c Chapeaux <lolo@phpheaven.net> 2002-04-26 Lo<4C>c Chapeaux <lolo@phpheaven.net>

View File

@@ -58,10 +58,8 @@ reset($the_tables);
while (list($key, $table) = each($the_tables)) { while (list($key, $table) = each($the_tables)) {
$table = urldecode($table); $table = urldecode($table);
// if ($multi_tables) {
echo '<div style="page-break-after: always;">' . "\n"; echo '<div style="page-break-after: always;">' . "\n";
echo '<h1>' . $table . '</h1>' . "\n"; echo '<h1>' . $table . '</h1>' . "\n";
// } // end if
/** /**
* Gets table informations * Gets table informations
@@ -135,16 +133,12 @@ while (list($key, $table) = each($the_tables)) {
$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; $have_rel = FALSE;
$rel_query = 'SHOW TABLES'; if ($cfg['Server']['relation']) {
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url); $tables = @mysql_query('SELECT COUNT(*) AS count FROM ' . PMA_backquote($cfg['Server']['relation']));
while ($ctable = @mysql_fetch_array($tables)) { $have_rel = ($tables) ? mysql_result($tables, 0, 'count') : FALSE;
if ($ctable[0] == $cfg['Server']['relation']) { } // end if
$rel_work = TRUE; if ($have_rel) {
}
} // end while
if ($rel_work) {
unset($res_rel);
// Find which tables are related with the current one and write it in // Find which tables are related with the current one and write it in
// an array // an array
$rel_query = 'SELECT master_field, concat(foreign_table, \'->\', foreign_field) AS rel ' $rel_query = 'SELECT master_field, concat(foreign_table, \'->\', foreign_field) AS rel '
@@ -156,7 +150,6 @@ while (list($key, $table) = each($the_tables)) {
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 />';
} }
if (count($res_rel) > 0) { if (count($res_rel) > 0) {
$have_rel = TRUE; $have_rel = TRUE;
@@ -188,7 +181,7 @@ 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) { if ($have_rel) {
echo '<th>' . ucfirst($strLinksTo) . '</th>'; echo '<th>' . ucfirst($strLinksTo) . '</th>';
} }
echo "\n"; echo "\n";
@@ -257,7 +250,7 @@ while (list($key, $table) = each($the_tables)) {
<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) { if ($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]);

View File

@@ -697,24 +697,31 @@ if (!empty($qry_select)) {
// 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 (isset($Field) && count($Field) > 0) {
// Initialize some variables
$alltabs = array();
$where = array();
$wheretabs = array();
$reltabs = array();
$rel = array();
$rest = array();
$found = array();
$rel_work = FALSE;
$ex = 0;
$hit = 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[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2); $alltabs[] = substr(urldecode($parts[0]), 1, strlen(urldecode($parts[0])) - 2);
} }
} // end while } // end while
$rel_work = FALSE; if ($cfg['Server']['relation']) {
$rel_query = 'SHOW TABLES'; $tables = @mysql_query('SELECT COUNT(*) AS count FROM ' . PMA_backquote($cfg['Server']['relation']));
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url); $rel_work = ($tables) ? mysql_result($tables, 0, 'count') : FALSE;
while ($ctable = @mysql_fetch_array($tables)) { } // end if
if ($ctable[0] == $cfg['Server']['relation']) {
$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
@@ -751,7 +758,7 @@ if (count($Field) > 0) {
// have 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 = '(\'' . 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'])
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit . ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit
@@ -777,18 +784,13 @@ if (count($Field) > 0) {
// need to refine more // need to refine more
$hit = 2; $hit = 2;
} // end if.. else... } // end if.. else...
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) {
$master = $row['wer']; $master = $row['wer'];
$ex = 1; $ex = 1;
break; break 2;
} }
} // end while } // end while
} // end if
if ($ex == 1) {
break;
}
} // end while } // end while
if ($ex == 1 || $hit != 2) { if ($ex == 1 || $hit != 2) {
@@ -809,7 +811,7 @@ if (count($Field) > 0) {
} // end while } // 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 = '(\'' . implode('\', \'', $reltabs) . '\')';
$rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation']) $rel_query = 'SELECT * FROM ' . PMA_backquote($cfg['Server']['relation'])
. ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s . ' WHERE master_table IN ' . $incrit . ' AND foreign_table IN ' . $incrit_s
@@ -824,8 +826,7 @@ if (count($Field) > 0) {
// want another 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)
. ' ON ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field']) . ' ON ' . PMA_backquote($row['master_table']) . '.' . PMA_backquote($row['master_field'])
. ' = ' . 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;
@@ -846,9 +847,9 @@ if (count($Field) > 0) {
$found[] = $key; $found[] = $key;
} }
} // end while } // end while
if (is_array($rest) && is_array($found) && count($rest) > 0) { if (count($rest) > 0) {
$incrit_d = '(\'' . str_replace(',', "','", implode(',', $found)) . '\')'; $incrit_d = '(\'' . implode('\', \'', $found) . '\')';
$incrit_s = '(\'' . str_replace(',', "','", implode(',', $rest)) . '\')'; $incrit_s = '(\'' . implode('\', \'', $rest) . '\')';
$rel_query = 'SELECT * FROM ' . $cfg['Server']['relation'] $rel_query = 'SELECT * FROM ' . $cfg['Server']['relation']
. ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d . ' WHERE master_table IN ' . $incrit_s . ' AND foreign_table IN ' . $incrit_d
@@ -862,7 +863,7 @@ if (count($Field) > 0) {
// don't want another 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
. ' ON ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field']) . ' ON ' . PMA_backquote($row['foreign_table']) . '.' . PMA_backquote($row['foreign_field'])
. ' = ' . 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 // in extreme cases we hadn't found a master yet, so
// let's use the one we found now // let's use the one we found now
@@ -897,16 +898,14 @@ if (count($Field) > 0) {
// on one occasion i had qry_from at this point end with a , as I // 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: // can't find why this happened i check this now:
if (substr($qry_from, strlen($qry_from) - 1, 1) == ',') { $qry_from = ereg_replace(', $', '', $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 $ex == 1 (testing if it is worth the pain)
} // end rel work and $alltabs > 0 } // end rel work and $alltabs > 0
if (empty($qry_from) && is_array($alltabs)) { if (empty($qry_from) && count($alltabs)) {
$qry_from = implode(', ', $alltabs); $qry_from = implode(', ', $alltabs);
} }