mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Fixed restore problem with NULL columns, and added some documentation.
git-svn-id: file:///svn/phpbb/trunk@780 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
e98e3e1403
commit
21a6090308
1 changed files with 71 additions and 10 deletions
|
@ -28,6 +28,10 @@
|
||||||
* adapted from the unoficial phpMyAdmin 2.2.0.
|
* adapted from the unoficial phpMyAdmin 2.2.0.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do the setmodules stuff for the admin control panel.
|
||||||
|
//
|
||||||
|
|
||||||
if($setmodules == 1)
|
if($setmodules == 1)
|
||||||
{
|
{
|
||||||
$filename = basename(__FILE__);
|
$filename = basename(__FILE__);
|
||||||
|
@ -143,6 +147,9 @@ function get_table_def_postgres($table, $crlf)
|
||||||
global $drop, $db;
|
global $drop, $db;
|
||||||
|
|
||||||
$schema_create = "";
|
$schema_create = "";
|
||||||
|
//
|
||||||
|
// Get a listing of the fields, with their associated types, etc.
|
||||||
|
//
|
||||||
|
|
||||||
$field_query = "SELECT a.attnum, a.attname AS field, t.typename as type, a.attlen AS length, a.atttypmod as lengthvar, a.attnotnull as notnull
|
$field_query = "SELECT a.attnum, a.attname AS field, t.typename as type, a.attlen AS length, a.atttypmod as lengthvar, a.attnotnull as notnull
|
||||||
FROM pg_class c, pg_attribute a, pg_type t
|
FROM pg_class c, pg_attribute a, pg_type t
|
||||||
|
@ -164,10 +171,17 @@ function get_table_def_postgres($table, $crlf)
|
||||||
$schema_create .= "DROP TABLE $table;$crlf";
|
$schema_create .= "DROP TABLE $table;$crlf";
|
||||||
} // end if
|
} // end if
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ok now we actually start building the SQL statements to restore the tables
|
||||||
|
//
|
||||||
|
|
||||||
$schema_create .= "CREATE TABLE $table($crlf";
|
$schema_create .= "CREATE TABLE $table($crlf";
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Get the data from the table
|
||||||
|
//
|
||||||
$sql_get_default = "SELECT d.adsrc AS rowdefault
|
$sql_get_default = "SELECT d.adsrc AS rowdefault
|
||||||
FROM pg_attrdef d, pg_class c
|
FROM pg_attrdef d, pg_class c
|
||||||
WHERE (c.relname = '$table')
|
WHERE (c.relname = '$table')
|
||||||
|
@ -220,6 +234,9 @@ function get_table_def_postgres($table, $crlf)
|
||||||
$schema_create .= ", $crlf";
|
$schema_create .= ", $crlf";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// Get the listing of primary keys.
|
||||||
|
//
|
||||||
|
|
||||||
$sql_pri_keys = "SELECT ic.relname AS index_name, bc.relname AS tab_name, ta.attname AS column_name, i.indisunique AS unique_key, i.indisprimary AS primary_key
|
$sql_pri_keys = "SELECT ic.relname AS index_name, bc.relname AS tab_name, ta.attname AS column_name, i.indisunique AS unique_key, i.indisprimary AS primary_key
|
||||||
FROM pg_class bc, pg_class ic, pg_index i, pg_attribute ta, pg_attribute ia
|
FROM pg_class bc, pg_class ic, pg_index i, pg_attribute ta, pg_attribute ia
|
||||||
|
@ -301,6 +318,9 @@ function get_table_def_postgres($table, $crlf)
|
||||||
message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $sql_checks);
|
message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $sql_checks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add the constraints to the sql file.
|
||||||
|
//
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$schema_create .= ' CONSTRAINT ' . $row['index_name'] . ' CHECK ' . $row['rcsrc'] . ",$crlf";
|
$schema_create .= ' CONSTRAINT ' . $row['index_name'] . ' CHECK ' . $row['rcsrc'] . ",$crlf";
|
||||||
|
@ -316,6 +336,9 @@ function get_table_def_postgres($table, $crlf)
|
||||||
$schema_create .= $index_create;
|
$schema_create .= $index_create;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ok now we've built all the sql return it to the calling function.
|
||||||
|
//
|
||||||
return (stripslashes($schema_create));
|
return (stripslashes($schema_create));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -454,6 +477,10 @@ function get_table_content_postgres($table, $handler)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Grab all of the data from current table.
|
||||||
|
//
|
||||||
|
|
||||||
$result = $db->sql_query("SELECT * FROM $table");
|
$result = $db->sql_query("SELECT * FROM $table");
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
|
@ -477,7 +504,9 @@ function get_table_content_postgres($table, $handler)
|
||||||
unset($schema_vals);
|
unset($schema_vals);
|
||||||
unset($schema_fields);
|
unset($schema_fields);
|
||||||
unset($schema_insert);
|
unset($schema_insert);
|
||||||
|
//
|
||||||
|
// Build the SQL statement to recreate the data.
|
||||||
|
//
|
||||||
for($i = 0; $i < $i_num_fields; $i++)
|
for($i = 0; $i < $i_num_fields; $i++)
|
||||||
{
|
{
|
||||||
$strVal = $row[$aryName[$i]];
|
$strVal = $row[$aryName[$i]];
|
||||||
|
@ -519,6 +548,10 @@ function get_table_content_postgres($table, $handler)
|
||||||
$schema_fields = ereg_replace(",$", "", $schema_fields);
|
$schema_fields = ereg_replace(",$", "", $schema_fields);
|
||||||
$schema_fields = ereg_replace("^ ", "", $schema_fields);
|
$schema_fields = ereg_replace("^ ", "", $schema_fields);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Take the ordered fields and their associated data and build it
|
||||||
|
// into a valid sql statement to recreate that field in the data.
|
||||||
|
//
|
||||||
$schema_insert = "INSERT INTO $table ($schema_fields) VALUES($schema_vals);";
|
$schema_insert = "INSERT INTO $table ($schema_fields) VALUES($schema_vals);";
|
||||||
|
|
||||||
$handler(trim($schema_insert));
|
$handler(trim($schema_insert));
|
||||||
|
@ -528,11 +561,16 @@ function get_table_content_postgres($table, $handler)
|
||||||
|
|
||||||
}// end function get_table_content_postgres...
|
}// end function get_table_content_postgres...
|
||||||
|
|
||||||
|
//
|
||||||
|
// This function is for getting the data from a mysql table.
|
||||||
|
//
|
||||||
|
|
||||||
function get_table_content_mysql($table, $handler)
|
function get_table_content_mysql($table, $handler)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
//
|
||||||
|
// Grab the data from the table.
|
||||||
|
//
|
||||||
$result = $db->sql_query("SELECT * FROM $table");
|
$result = $db->sql_query("SELECT * FROM $table");
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
|
@ -552,26 +590,44 @@ function get_table_content_mysql($table, $handler)
|
||||||
|
|
||||||
$handler($schema_insert);
|
$handler($schema_insert);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop through the resulting rows and build the sql statement.
|
||||||
|
//
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$table_list = '(';
|
$table_list = '(';
|
||||||
$num_fields = $db->sql_numfields($result);
|
$num_fields = $db->sql_numfields($result);
|
||||||
|
//
|
||||||
|
// Grab the list of field names.
|
||||||
|
//
|
||||||
for ($j = 0; $j < $num_fields; $j++)
|
for ($j = 0; $j < $num_fields; $j++)
|
||||||
{
|
{
|
||||||
$table_list .= $db->sql_fieldname($j, $result) . ', ';
|
$table_list .= $db->sql_fieldname($j, $result) . ', ';
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// Get rid of the last comma
|
||||||
|
//
|
||||||
$table_list = ereg_replace(', $', '', $table_list);
|
$table_list = ereg_replace(', $', '', $table_list);
|
||||||
$table_list .= ')';
|
$table_list .= ')';
|
||||||
|
//
|
||||||
|
// Start building the SQL statement.
|
||||||
|
//
|
||||||
$schema_insert = "INSERT INTO $table $table_list VALUES(";
|
$schema_insert = "INSERT INTO $table $table_list VALUES(";
|
||||||
|
//
|
||||||
|
// Loop through the rows and fill in data for each column
|
||||||
|
//
|
||||||
for ($j = 0; $j < $num_fields; $j++)
|
for ($j = 0; $j < $num_fields; $j++)
|
||||||
{
|
{
|
||||||
if(!isset($row[$j]))
|
if(!isset($row[$j]))
|
||||||
{
|
{
|
||||||
$schema_insert .= ' NULL, ';
|
//
|
||||||
|
// If there is no data for the column set it to null.
|
||||||
|
// There was a problem here with an extra space causing the
|
||||||
|
// sql file not to reimport if the last column was null in
|
||||||
|
// any table. Should be fixed now :) JLH
|
||||||
|
//
|
||||||
|
$schema_insert .= ' NULL,';
|
||||||
}
|
}
|
||||||
elseif ($row[$j] != '')
|
elseif ($row[$j] != '')
|
||||||
{
|
{
|
||||||
|
@ -582,9 +638,14 @@ function get_table_content_mysql($table, $handler)
|
||||||
$schema_insert .= '\'\',';
|
$schema_insert .= '\'\',';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// Get rid of the the last comma.
|
||||||
|
//
|
||||||
$schema_insert = ereg_replace(',$', '', $schema_insert);
|
$schema_insert = ereg_replace(',$', '', $schema_insert);
|
||||||
$schema_insert .= ');';
|
$schema_insert .= ');';
|
||||||
|
//
|
||||||
|
// Go ahead and send the insert statement to the handler function.
|
||||||
|
//
|
||||||
$handler(trim($schema_insert));
|
$handler(trim($schema_insert));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue