Added a limitation feature for data dumps thanks to Girish Nair and Vinay

This commit is contained in:
Loïc Chapeaux
2001-07-13 17:18:11 +00:00
parent 18f3a14292
commit c74a33e567
27 changed files with 269 additions and 115 deletions

View File

@@ -6,8 +6,9 @@ $Id$
$Source$ $Source$
2001-07-13 Lo<4C>c Chapeaux <lolo@phpheaven.net> 2001-07-13 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* left.php3: no DHTML if there is only one table to display * lib.inc.php3, tbl_dump.php3, tbl_properties.php3, translations: added a
(feature #440420) limitation feature for data dumps thanks to
Girish Nair <girish@sanisoft.com> and Vinay <vinay@sanisoft.com>.
* lib.inc.php3, lines 785-847: rewritten the 'show_message' function in * lib.inc.php3, lines 785-847: rewritten the 'show_message' function in
order it generates a valid xhtml1.0 code and the programatically added order it generates a valid xhtml1.0 code and the programatically added
'LIMIT' clause is displayed only if it has been trully used. 'LIMIT' clause is displayed only if it has been trully used.
@@ -19,6 +20,8 @@ $Source$
- lines 83-89: fixed a bug if the sql query contains a 'limit' clause - lines 83-89: fixed a bug if the sql query contains a 'limit' clause
typed by the user. typed by the user.
* db_readdump.php3.php3, line 64: removed a faulty fix for bug #439565. * db_readdump.php3.php3, line 64: removed a faulty fix for bug #439565.
* left.php3: no DHTML if there is only one table to display
(feature #440420)
2001-07-12 Marc Delisle <lem9@users.sourceforge.net> 2001-07-12 Marc Delisle <lem9@users.sourceforge.net>
* Documentation.html: added a FAQ entry about upload errors * Documentation.html: added a FAQ entry about upload errors

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -271,5 +271,7 @@ $strYes = "Ano";
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -271,5 +271,7 @@ $strYes = "Ano";
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -38,6 +38,8 @@ $strAtEndOfTable = "At End of Table";
$strAttr = "Attributes"; $strAttr = "Attributes";
$strBack = "Back"; $strBack = "Back";
$strBinary = "Binary";
$strBinaryDoNotEdit = "Binary - do not edit";
$strBookmarkLabel = "Label"; $strBookmarkLabel = "Label";
$strBookmarkQuery = "Bookmarked SQL-query"; $strBookmarkQuery = "Bookmarked SQL-query";
$strBookmarkThis = "Bookmark this SQL-query"; $strBookmarkThis = "Bookmark this SQL-query";
@@ -93,6 +95,7 @@ $strEmptyResultSet = "MySQL returned an empty result set (i.e. zero rows).";
$strEnableMagicQuotes = "<b>Warning:</b> You haven't enabled magic_quotes_gpc in your PHP configuration. PhpMyAdmin needs this to work properly. Please have a look at the configuration section of the PHP manual for information on how to enable it."; $strEnableMagicQuotes = "<b>Warning:</b> You haven't enabled magic_quotes_gpc in your PHP configuration. PhpMyAdmin needs this to work properly. Please have a look at the configuration section of the PHP manual for information on how to enable it.";
$strEnclosedBy = "enclosed by"; $strEnclosedBy = "enclosed by";
$strEnd = "End"; $strEnd = "End";
$strEnglishPrivileges = " Note: MySQL privilege names are expressed in English ";
$strError = "Error"; $strError = "Error";
$strEscapedBy = "escaped by"; $strEscapedBy = "escaped by";
$strExtra = "Extra"; $strExtra = "Extra";
@@ -149,6 +152,7 @@ $strMySQLShowStatus = "Show MySQL runtime information";
$strMySQLShowVars = "Show MySQL system variables"; $strMySQLShowVars = "Show MySQL system variables";
$strName = "Name"; $strName = "Name";
$strNbRecords = "No. Of records";
$strNext = "Next"; $strNext = "Next";
$strNo = "No"; $strNo = "No";
$strNoPassword = "No Password"; $strNoPassword = "No Password";
@@ -161,6 +165,7 @@ $strNoUsersFound = "No user(s) found.";
$strNull = "Null"; $strNull = "Null";
$strNumberIndexes = " Number of advanced indexes "; $strNumberIndexes = " Number of advanced indexes ";
$strOffSet = "Offset";
$strOftenQuotation = "Often quotation marks. OPTIONALLY means that only char and varchar fields are enclosed by the \"enclosed by\"-character."; $strOftenQuotation = "Often quotation marks. OPTIONALLY means that only char and varchar fields are enclosed by the \"enclosed by\"-character.";
$strOptimizeTable = "Optimize table"; $strOptimizeTable = "Optimize table";
$strOptionalControls = "Optional. Controls how to write or read special characters."; $strOptionalControls = "Optional. Controls how to write or read special characters.";
@@ -204,6 +209,7 @@ $strRevokePriv = "Revoke Privileges";
$strRowLength = "Row length"; $strRowLength = "Row length";
$strRows = "Rows"; $strRows = "Rows";
$strRowsFrom = "rows starting from"; $strRowsFrom = "rows starting from";
$strRowSize = " Row size ";
$strRowsStatistic = "Row Statistic"; $strRowsStatistic = "Row Statistic";
$strRunning = "running on "; $strRunning = "running on ";
$strRunQuery = ""; //to translate, but its not in use ... $strRunQuery = ""; //to translate, but its not in use ...
@@ -267,11 +273,4 @@ $strWelcome = "Welcome to ";
$strWrongUser = "Wrong username/password. Access denied."; $strWrongUser = "Wrong username/password. Access denied.";
$strYes = "Yes"; $strYes = "Yes";
// automatic generated by langxlorer.php (June 27, 2001, 6:53 pm)
// V0.11 - experimental (Steve Alberty - alberty@neptunlabs.de)
$strBinary="Binary";
$strBinaryDoNotEdit="Binary - do not edit";
$strEnglishPrivileges=" Note: MySQL privilege names are expressed in English ";
$strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -151,6 +151,7 @@ $strMySQLShowStatus = "Afficher l'
$strMySQLShowVars = "Afficher les variables du serveur MySQL"; $strMySQLShowVars = "Afficher les variables du serveur MySQL";
$strName = "Nom"; $strName = "Nom";
$strNbRecords = "Nb. d'enregistrements";
$strNext = "Suivant"; $strNext = "Suivant";
$strNo = "Non"; $strNo = "Non";
$strNoPassword = "aucun mot de passe"; $strNoPassword = "aucun mot de passe";
@@ -163,6 +164,7 @@ $strNoUsersFound = "Il n'y a aucun utilisateur";
$strNull = "Null"; $strNull = "Null";
$strNumberIndexes = " Nombre d'index sp<73>ciaux "; $strNumberIndexes = " Nombre d'index sp<73>ciaux ";
$strOffSet = "D<EFBFBD>but";
$strOftenQuotation = "Souvent des guillemets. OPTIONNEL signifie que seulement les champs de type char et varchar sont entour<75>s par ce caract<63>re."; $strOftenQuotation = "Souvent des guillemets. OPTIONNEL signifie que seulement les champs de type char et varchar sont entour<75>s par ce caract<63>re.";
$strOptimizeTable = "Optimiser la table"; $strOptimizeTable = "Optimiser la table";
$strOptionalControls = "Optionnel. Indique le caract<63>re qui permet d'enlever l'effet des caract<63>res sp<73>ciaux."; $strOptionalControls = "Optionnel. Indique le caract<63>re qui permet d'enlever l'effet des caract<63>res sp<73>ciaux.";

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " ist keine g
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"GZip komprimiert\""; $strGzip = "\"GZip komprimiert\"";
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Zeilengr&ouml;<3B>e "; $strRowSize=" Zeilengr&ouml;<3B>e ";
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -271,5 +271,7 @@ $strYes = "Si";
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize = " Row size "; //to translate $strRowSize = " Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -274,5 +274,7 @@ $strNotValidNumber = " is not a valid row number!"; //to translate
// export Zip (July 07, 2001, 19:48am) // export Zip (July 07, 2001, 19:48am)
$strGzip = "\"gzipped\""; //to translate $strGzip = "\"gzipped\""; //to translate
$strOffSet = "Offset";
$strNbRecords = "No. Of records";
$strRowSize=" Row size "; //to translate $strRowSize=" Row size "; //to translate
?> ?>

View File

@@ -600,123 +600,223 @@ function get_table_def($db, $table, $crlf)
} }
} }
// Get the content of $table as a series of INSERT statements. /**
// After every row, a custom callback function $handler gets called. * Dispatch between the versions of 'get_table_content' to use depending on the
// $handler must accept one parameter ($sql_insert); * php version
*
function get_table_content ($db, $table, $handler){ * @param string the current database name
if (PMA_INT_VERSION>=40005) get_table_content_fast($db, $table, $handler); * @param string the current table name
else get_table_content_old($db, $table, $handler); * @param integer the offset on this table
} * @param integer the last row to get
* @param string the name of the handler (function) to use at the end of
* every row. This handler must accept one parameter
// only php >= 4.0.5 - staybyte - 27. June 2001 * ($sql_insert)
function get_table_content_fast($db, $table, $handler){ *
$result = mysql_query("SELECT * FROM ".db_name($db)."." . * @see get_table_content_fast(), get_table_content_old()
tbl_name($table)) or mysql_die(); * @author staybyte
if ($result!=false){ *
for($j=0; $j<mysql_num_fields($result);$j++){ * Last revision 13 July 2001: Patch for limiting dump size from
$field_set[$j]= mysql_field_name($result,$j); * vinay@sanisoft.com & girish@sanisoft.com
$type=mysql_field_type($result,$j); */
if ($type=="tinyint"||$type=="smallint"||$type=="mediumint"||$type=="int"||$type=="bigint"||$type=="timestamp") function get_table_content($db, $table, $limit_from = 0, $limit_to = 0, $handler)
$field_num[$j]=true;
else $field_num[$j]=false;
}
if(isset($GLOBALS["showcolumns"])){
$fields=implode(", ",$field_set);
$schema_insert = "INSERT INTO $table ($fields) VALUES (";
}
else $schema_insert = "INSERT INTO $table VALUES (";
$field_count=mysql_num_fields($result);
$search=array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
$replace=array("\\n","\\r","\Z");
@set_time_limit(1200); // 20 Minutes
while($row = mysql_fetch_row($result)){
for($j=0; $j < $field_count; $j++){
if (isset($row[$j])){
if ($field_num[$j]) $values[]=$row[$j]; // a number
else $values[]="'".str_replace($search,$replace,AddSlashes($row[$j]))."'"; // string
}
else if(!isset($row[$j])) $values[]="NULL";
else $values[]="''";
}
$insert_line = $schema_insert.implode (",",$values).")";
unset ($values);
$handler($insert_line);
}
}
}
function get_table_content_old($db, $table, $handler)
{ {
$result = mysql_query("SELECT * FROM " . db_name($db) ."." . // Defines the offsets to use
tbl_name($table)) or mysql_die(); if ($limit_from > 0) {
$i = 0; $limit_from--;
while($row = mysql_fetch_row($result)) } else {
{ $limit_from = 0;
@set_time_limit(60); // HaRa }
$table_list = "("; if ($limit_to > 0 && $limit_from >= 0) {
$add_query = " LIMIT $limit_from, $limit_to";
} else {
$add_query = '';
}
for($j=0; $j<mysql_num_fields($result);$j++) // Call the working function depending on the php version
$table_list .= mysql_field_name($result,$j).", "; if (PMA_INT_VERSION >= 40005) {
get_table_content_fast($db, $table, $add_query, $handler);
} else {
get_table_content_old($db, $table, $add_query, $handler);
}
} // end of the 'get_table_content()' function
$table_list = substr($table_list,0,-2);
$table_list .= ")";
if(isset($GLOBALS["showcolumns"])) /**
$schema_insert = "INSERT INTO $table $table_list VALUES ("; * php >= 4.0.5 only : get the content of $table as a series of INSERT
else * statements.
* After every row, a custom callback function $handler gets called.
*
* @param string the current database name
* @param string the current table name
* @param string the 'limit' clause to use with the sql query
* @param string the name of the handler (function) to use at the end of
* every row. This handler must accept one parameter
* ($sql_insert)
*
* @return boolean always true
*
* @author staybyte
*
* Last revision 13 July 2001: Patch for limiting dump size from
* vinay@sanisoft.com & girish@sanisoft.com
*/
function get_table_content_fast($db, $table, $add_query = '', $handler)
{
$result = mysql_query('SELECT * FROM ' . db_name($db) . '.' . tbl_name($table). $add_query) or mysql_die();
if ($result != false) {
// Checks whether the field is an integer or not
for ($j = 0; $j < mysql_num_fields($result); $j++) {
$field_set[$j] = mysql_field_name($result, $j);
$type = mysql_field_type($result, $j);
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
$type == 'bigint' ||$type == 'timestamp') {
$field_num[$j] = true;
} else {
$field_num[$j] = false;
}
} // end for
// Get the scheme
if (isset($GLOBALS['showcolumns'])) {
$fields = implode(', ', $field_set);
$schema_insert = "INSERT INTO $table ($fields) VALUES (";
} else {
$schema_insert = "INSERT INTO $table VALUES ("; $schema_insert = "INSERT INTO $table VALUES (";
for ($j=0; $j<mysql_num_fields($result);$j++)
{
if (!isset($row[$j])) {
$schema_insert .= " NULL,";
}
else if ($row[$j] != "") {
$dummy = "";
$srcstr = $row[$j];
for ($xx=0; $xx < strlen($srcstr); $xx++) {
$yy = strlen($dummy);
if($srcstr[$xx] == "\\") $dummy .= "\\\\";
if($srcstr[$xx] == "'") $dummy .= "\\'";
if($srcstr[$xx] == "\"") $dummy .= "\\\"";
if($srcstr[$xx] == "\x00") $dummy .= "\\0";
if($srcstr[$xx] == "\x0a") $dummy .= "\\n";
if($srcstr[$xx] == "\x0d") $dummy .= "\\r";
if($srcstr[$xx] == "\x08") $dummy .= "\\b";
if($srcstr[$xx] == "\t") $dummy .= "\\t";
if($srcstr[$xx] == "\x1a") $dummy .= "\\Z";
if(strlen($dummy) == $yy) $dummy .= $srcstr[$xx];
}
$schema_insert .= " '".$dummy."',";
}
else {
$schema_insert .= " '',";
}
} }
$schema_insert = ereg_replace(",$", "", $schema_insert);
$schema_insert .= ")"; $field_count = mysql_num_fields($result);
$search = array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
$replace = array("\\n","\\r","\Z");
@set_time_limit(1200); // 20 Minutes
while ($row = mysql_fetch_row($result)) {
for ($j = 0; $j < $field_count; $j++) {
if (!isset($row[$j])) {
$values[] = 'NULL';
} else if (!empty($row[$j])) {
// a number
if ($field_num[$j]) {
$values[] = $row[$j];
}
// a string
else {
$values[] = "'" . str_replace($search, $replace, addslashes($row[$j])) . "'";
}
} else {
$values[] = "''";
} // end if
} // end for
$insert_line = $schema_insert . implode(',', $values) . ')';
unset($values);
// Call the handler
$handler($insert_line);
} // end while
} // end if ($result != false)
return true;
} // end of the 'get_table_content_fast()' function
/**
* php < 4.0.5 only : get the content of $table as a series of INSERT
* statements.
* After every row, a custom callback function $handler gets called.
*
* @param string the current database name
* @param string the current table name
* @param string the 'limit' clause to use with the sql query
* @param string the name of the handler (function) to use at the end of
* every row. This handler must accept one parameter
* ($sql_insert)
*
* @return boolean always true
*
* Last revision 13 July 2001: Patch for limiting dump size from
* vinay@sanisoft.com & girish@sanisoft.com
*/
function get_table_content_old($db, $table, $add_query = '', $handler)
{
$result = mysql_query('SELECT * FROM ' . db_name($db) . '.' . tbl_name($table) . $add_query) or mysql_die();
$i = 0;
while ($row = mysql_fetch_row($result)) {
@set_time_limit(60); // HaRa
$table_list = '(';
for ($j = 0; $j < mysql_num_fields($result); $j++) {
$table_list .= mysql_field_name($result, $j) . ', ';
}
$table_list = substr($table_list, 0, -2);
$table_list .= ')';
if (isset($GLOBALS['showcolumns'])) {
$schema_insert = "INSERT INTO $table $table_list VALUES (";
} else {
$schema_insert = "INSERT INTO $table VALUES (";
}
for ($j = 0; $j < mysql_num_fields($result); $j++) {
if (!isset($row[$j])) {
$schema_insert .= ' NULL,';
} else if ($row[$j] != '') {
$dummy = '';
$srcstr = $row[$j];
for ($xx = 0; $xx < strlen($srcstr); $xx++) {
$yy = strlen($dummy);
if ($srcstr[$xx] == "\\") $dummy .= "\\\\";
if ($srcstr[$xx] == "'") $dummy .= "\\'";
if ($srcstr[$xx] == "\"") $dummy .= "\\\"";
if ($srcstr[$xx] == "\x00") $dummy .= "\\0";
if ($srcstr[$xx] == "\x0a") $dummy .= "\\n";
if ($srcstr[$xx] == "\x0d") $dummy .= "\\r";
if ($srcstr[$xx] == "\x08") $dummy .= "\\b";
if ($srcstr[$xx] == "\t") $dummy .= "\\t";
if ($srcstr[$xx] == "\x1a") $dummy .= "\\Z";
if (strlen($dummy) == $yy) $dummy .= $srcstr[$xx];
}
$schema_insert .= " '" . $dummy . "',";
} else {
$schema_insert .= " '',";
} // end if
} // end for
$schema_insert = ereg_replace(',$', '', $schema_insert);
$schema_insert .= ')';
$handler(trim($schema_insert)); $handler(trim($schema_insert));
++$i; ++$i;
} } // end while
return (true);
}
function count_records($db, $table) return true;
} // end of the 'get_table_content_old()' function
/**
* Counts and displays the number of records in a table
*
* @param string the current database name
* @param string the current table name
* @param boolean whether to retain or to displays the result
*
* @return mixed the number of records if retain is required, true else
*
* Last revision 13 July 2001: Patch for limiting dump size from
* vinay@sanisoft.com & girish@sanisoft.com
*/
function count_records($db, $table, $ret = false)
{ {
$result = mysql_query('select count(*) as num from ' . db_name($db) . '.' . tbl_name($table)); $result = mysql_query('select count(*) as num from ' . db_name($db) . '.' . tbl_name($table));
$num = mysql_result($result,0,"num"); $num = mysql_result($result,0,"num");
echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); if ($ret) {
} return $num;
} else {
echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
return true;
}
} // end of the 'count_records()' function
/** /**

View File

@@ -152,7 +152,7 @@ else
$dump_buffer.= "#$crlf$crlf"; $dump_buffer.= "#$crlf$crlf";
$tmp_buffer=""; $tmp_buffer="";
get_table_content($db, $table, "my_handler"); get_table_content($db, $table, $limit_from, $limit_to, 'my_handler');
$dump_buffer.=$tmp_buffer; $dump_buffer.=$tmp_buffer;
} }
$i++; $i++;

View File

@@ -562,6 +562,14 @@ echo "\n";
<input type="hidden" name="table" value="<?php echo $table; ?>" /> <input type="hidden" name="table" value="<?php echo $table; ?>" />
<?php echo $strViewDumpDB; ?><br /> <?php echo $strViewDumpDB; ?><br />
<table> <table>
<tr>
<td colspan="2">
<?php echo $strOffSet; ?>&nbsp;
<input type="text" name="limit_from" value="0" size="5" style="vertical-align: middle" />&nbsp;
<?php echo $strNbRecords; ?>&nbsp;
<input type="text" name="limit_to" size="5" value="<?php echo count_records($db, $table, true); ?>" style="vertical-align: middle" />
</td>
</tr>
<tr> <tr>
<td> <td>
<input type="radio" name="what" value="structure" checked="checked" /> <input type="radio" name="what" value="structure" checked="checked" />