Optimization, warnings and coding standards
This commit is contained in:
@@ -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>
|
||||||
|
@@ -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,8 +181,8 @@ 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']; ?> </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) {
|
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]);
|
||||||
|
83
tbl_qbe.php3
83
tbl_qbe.php3
@@ -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
|
|
||||||
$rel_work = FALSE;
|
|
||||||
$rel_query = 'SHOW TABLES';
|
|
||||||
$tables = @mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url);
|
|
||||||
while ($ctable = @mysql_fetch_array($tables)) {
|
|
||||||
if ($ctable[0] == $cfg['Server']['relation']) {
|
|
||||||
$rel_work = TRUE;
|
|
||||||
}
|
}
|
||||||
} // end while
|
} // end while
|
||||||
|
if ($cfg['Server']['relation']) {
|
||||||
|
$tables = @mysql_query('SELECT COUNT(*) AS count FROM ' . PMA_backquote($cfg['Server']['relation']));
|
||||||
|
$rel_work = ($tables) ? mysql_result($tables, 0, 'count') : FALSE;
|
||||||
|
} // end if
|
||||||
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,21 +784,16 @@ 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 2;
|
||||||
break;
|
}
|
||||||
}
|
} // end while
|
||||||
} // end while
|
|
||||||
} // end if
|
|
||||||
if ($ex == 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} // end while
|
} // end while
|
||||||
|
|
||||||
if ($ex ==1 || $hit != 2) {
|
if ($ex == 1 || $hit != 2) {
|
||||||
// if $ex is not 1 then obviously none of the tables that are used
|
// 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
|
// in the whereclause could be found - that means that using left
|
||||||
// joins doesn't make much sense anyway
|
// joins doesn't make much sense anyway
|
||||||
@@ -804,16 +806,16 @@ if (count($Field) > 0) {
|
|||||||
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
|
} // 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
|
||||||
. ' 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);
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -883,7 +884,7 @@ if (count($Field) > 0) {
|
|||||||
while (list($key, $varr) = each($rel)) {
|
while (list($key, $varr) = each($rel)) {
|
||||||
if ($varr['link'] == '') {
|
if ($varr['link'] == '') {
|
||||||
if ($qry_from != '') {
|
if ($qry_from != '') {
|
||||||
$qry_from .= ',';
|
$qry_from .= ', ';
|
||||||
}
|
}
|
||||||
$qry_from .= PMA_backquote($key);
|
$qry_from .= PMA_backquote($key);
|
||||||
} else if ($varr['mcon'] == 0) {
|
} else if ($varr['mcon'] == 0) {
|
||||||
@@ -897,17 +898,15 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end count($Field) > 0
|
} // end count($Field) > 0
|
||||||
|
Reference in New Issue
Block a user