better way to show php code

This commit is contained in:
Marc Delisle
2002-07-13 20:33:15 +00:00
parent ce2e66a014
commit 638b1844b0
2 changed files with 58 additions and 51 deletions

View File

@@ -8,6 +8,7 @@ $Source$
2002-07-13 Marc Delisle <lem9@users.sourceforge.net> 2002-07-13 Marc Delisle <lem9@users.sourceforge.net>
* libraries/common.lib.php3: bug 580929: do not EXPLAIN if this is * libraries/common.lib.php3: bug 580929: do not EXPLAIN if this is
not a SELECT not a SELECT
* sql.php3: better way to show php code
2002-07-13 Alexander M. Turek <rabus@users.sourceforge.net> 2002-07-13 Alexander M. Turek <rabus@users.sourceforge.net>
* Documentation.html: News about bug #540671. * Documentation.html: News about bug #540671.

108
sql.php3
View File

@@ -8,7 +8,6 @@
require('./libraries/grab_globals.lib.php3'); require('./libraries/grab_globals.lib.php3');
require('./libraries/common.lib.php3'); require('./libraries/common.lib.php3');
/** /**
* Defines the url to return to in case of error in a sql statement * Defines the url to return to in case of error in a sql statement
*/ */
@@ -244,7 +243,7 @@ else {
$sql_query = stripslashes($sql_query); $sql_query = stripslashes($sql_query);
} }
// Defines some variables // Defines some variables
// loic1: A table have to be created -> left frame should be reloaded // loic1: A table has to be created -> left frame should be reloaded
if ((!isset($reload) || $reload == 0) if ((!isset($reload) || $reload == 0)
&& eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) { && eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
$reload = 1; $reload = 1;
@@ -328,38 +327,41 @@ else {
// Executes the query // Executes the query
// only if we didn't ask to see the php code (mikebeck) // only if we didn't ask to see the php code (mikebeck)
if (empty($GLOBALS['show_as_php'])){ if (!empty($GLOBALS['show_as_php'])){
unset($result);
$num_rows = 0;
}
else {
$result = @PMA_mysql_query($full_sql_query); $result = @PMA_mysql_query($full_sql_query);
} // Displays an error message if required and stop parsing the script
// Displays an error message if required and stop parsing the script if (PMA_mysql_error()) {
if (PMA_mysql_error()) { $error = PMA_mysql_error();
$error = PMA_mysql_error(); include('./header.inc.php3');
include('./header.inc.php3'); $full_err_url = (ereg('^(db_details|tbl_properties)', $err_url))
$full_err_url = (ereg('^(db_details|tbl_properties)', $err_url)) ? $err_url . '&amp;show_query=y&amp;sql_query=' . urlencode($sql_query)
? $err_url . '&amp;show_query=y&amp;sql_query=' . urlencode($sql_query) : $err_url;
: $err_url; PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
PMA_mysqlDie($error, $full_sql_query, '', $full_err_url); }
}
// tmpfile remove after convert encoding appended by Y.Kawada // tmpfile remove after convert encoding appended by Y.Kawada
if (function_exists('PMA_kanji_file_conv') if (function_exists('PMA_kanji_file_conv')
&& (isset($textfile) && file_exists($textfile))) { && (isset($textfile) && file_exists($textfile))) {
unlink($textfile); unlink($textfile);
} }
// Gets the number of rows affected/returned // Gets the number of rows affected/returned
if (!$is_affected) { if (!$is_affected) {
$num_rows = ($result) ? @mysql_num_rows($result) : 0; $num_rows = ($result) ? @mysql_num_rows($result) : 0;
} else if (!isset($num_rows)) { } else if (!isset($num_rows)) {
$num_rows = @mysql_affected_rows(); $num_rows = @mysql_affected_rows();
} }
// Counts the total number of rows for the same 'SELECT' query without the // Counts the total number of rows for the same 'SELECT' query without the
// 'LIMIT' clause that may have been programatically added // 'LIMIT' clause that may have been programatically added
if (empty($sql_limit_to_append)) { if (empty($sql_limit_to_append)) {
$unlim_num_rows = $num_rows; $unlim_num_rows = $num_rows;
} }
else if ($is_select) { else if ($is_select) {
// SK -- Patch : correct calculations for GROUP BY, HAVING, DISTINCT // SK -- Patch : correct calculations for GROUP BY, HAVING, DISTINCT
// Reads only the from-part of the query... // Reads only the from-part of the query...
@@ -368,35 +370,36 @@ else {
// lowercase reserved words are removed, so we have a simple split // lowercase reserved words are removed, so we have a simple split
// pattern: // pattern:
$array = split('[[:space:]]+(FROM|ORDER BY)[[:space:]]+', $sql_query); $array = split('[[:space:]]+(FROM|ORDER BY)[[:space:]]+', $sql_query);
// if $array[1] is empty here, there is an error in the query: // if $array[1] is empty here, there is an error in the query:
// "... FROM [ORDER BY ...]", but the query is already executed with // "... FROM [ORDER BY ...]", but the query is already executed with
// success so this check is redundant??? // success so this check is redundant???
if (!empty($array[1])) { if (!empty($array[1])) {
// ... and makes a count(*) to count the entries // ... and makes a count(*) to count the entries
// Special case: SELECT DISTINCT ... FROM ... // Special case: SELECT DISTINCT ... FROM ...
// the count of resulting rows can be found as: // the count of resulting rows can be found as:
// SELECT COUNT(DISTINCT ...) FROM ... // SELECT COUNT(DISTINCT ...) FROM ...
if (eregi('^SELECT DISTINCT(.*)', $array[0], $array_dist)) { if (eregi('^SELECT DISTINCT(.*)', $array[0], $array_dist)) {
$count_what = 'DISTINCT ' . $array_dist[1]; $count_what = 'DISTINCT ' . $array_dist[1];
} else {
$count_what = '*';
}
$count_query = 'SELECT COUNT(' . $count_what . ') AS count FROM ' . $array[1];
if ($cnt_all_result = mysql_query($count_query)) {
if ($is_group) {
$unlim_num_rows = @mysql_num_rows($cnt_all_result);
} else { } else {
$unlim_num_rows = mysql_result($cnt_all_result, 0, 'count'); $count_what = '*';
} }
mysql_free_result($cnt_all_result); $count_query = 'SELECT COUNT(' . $count_what . ') AS count FROM ' . $array[1];
if ($cnt_all_result = mysql_query($count_query)) {
if ($is_group) {
$unlim_num_rows = @mysql_num_rows($cnt_all_result);
} else {
$unlim_num_rows = mysql_result($cnt_all_result, 0, 'count');
}
mysql_free_result($cnt_all_result);
}
} else {
$unlim_num_rows = 0;
} }
} else { } // end rows total count
$unlim_num_rows = 0; } // end else "didn't ask to see php code"
}
} // end rows total count
// No rows returned -> move back to the calling page // No rows returned -> move back to the calling page
if ($num_rows < 1 || $is_affected) { if ($num_rows < 1 || $is_affected) {
@@ -408,6 +411,8 @@ else {
$message = $strAffectedRows . '&nbsp;' . $num_rows; $message = $strAffectedRows . '&nbsp;' . $num_rows;
} else if (!empty($zero_rows)) { } else if (!empty($zero_rows)) {
$message = $zero_rows; $message = $zero_rows;
} else if (!empty($GLOBALS['show_as_php'])){
$message = $strPhp;
} else { } else {
$message = $strEmptyResultSet; $message = $strEmptyResultSet;
} }
@@ -487,11 +492,12 @@ else {
} }
// Gets the list of fields properties // Gets the list of fields properties
while ($field = PMA_mysql_fetch_field($result)) { if (isset($result) && $result) {
$fields_meta[] = $field; while ($field = PMA_mysql_fetch_field($result)) {
$fields_meta[] = $field;
}
$fields_cnt = count($fields_meta);
} }
$fields_cnt = count($fields_meta);
// Displays the results in a table // Displays the results in a table
include('./libraries/display_tbl.lib.php3'); include('./libraries/display_tbl.lib.php3');
if (empty($disp_mode)) { if (empty($disp_mode)) {