diff options
author | David M <davidmj@users.sourceforge.net> | 2006-06-12 21:55:30 +0000 |
---|---|---|
committer | David M <davidmj@users.sourceforge.net> | 2006-06-12 21:55:30 +0000 |
commit | 4a0ddb9dfbe76f0e074d85a417541591ec25daa6 (patch) | |
tree | 417ba1e849ddb4b9d864882cde5e93df20427560 /phpBB/includes/acp/acp_database.php | |
parent | fdaba4d67ef75bb06629d854a58b0529b85e2882 (diff) | |
download | forums-4a0ddb9dfbe76f0e074d85a417541591ec25daa6.tar forums-4a0ddb9dfbe76f0e074d85a417541591ec25daa6.tar.gz forums-4a0ddb9dfbe76f0e074d85a417541591ec25daa6.tar.bz2 forums-4a0ddb9dfbe76f0e074d85a417541591ec25daa6.tar.xz forums-4a0ddb9dfbe76f0e074d85a417541591ec25daa6.zip |
assorted backup fixes
git-svn-id: file:///svn/phpbb/trunk@6053 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acp/acp_database.php')
-rw-r--r-- | phpBB/includes/acp/acp_database.php | 87 |
1 files changed, 72 insertions, 15 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php index daf9e0b78b..c4fc075e73 100644 --- a/phpBB/includes/acp/acp_database.php +++ b/phpBB/includes/acp/acp_database.php @@ -176,6 +176,7 @@ class acp_database case 'mssql': case 'mssql_odbc': $sql_data .= '# Table: ' . $table_name . "\n"; + $sql_data .= "IF OBJECT_ID(N'$table_name', N'U') IS NOT NULL\n"; $sql_data .= "DROP TABLE $table_name;\nGO\n"; break; } @@ -520,6 +521,7 @@ class acp_database case 'mssql_odbc': $ary_type = $ary_name = array(); + $ident_set = false; // Grab all of the data from current table. $sql = "SELECT * FROM {$table_name}"; @@ -529,7 +531,17 @@ class acp_database if ($retrieved_data) { - $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\n"; + $sql = "SELECT 1 as has_identity + FROM INFORMATION_SCHEMA.COLUMNS + WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1"; + $result2 = $db->sql_query($sql); + $row2 = $db->sql_fetchrow($result2); + if (!empty($row2['has_identity'])) + { + $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n"; + $ident_set = true; + } + $db->sql_freeresult($result2); } $i_num_fields = odbc_num_fields($result); @@ -572,7 +584,7 @@ class acp_database $str_empty = 'NULL'; } - if (empty($str_val) && $str_val !== '0') + if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) { $str_val = $str_empty; } @@ -609,12 +621,17 @@ class acp_database if ($retrieved_data) { - $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\n"; + $sql_data = "\nGO\n"; + if ($ident_set) + { + $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n"; + } } break; case 'mssql': $ary_type = $ary_name = array(); + $ident_set = false; // Grab all of the data from current table. $sql = "SELECT * FROM {$table_name}"; @@ -622,11 +639,6 @@ class acp_database $retrieved_data = mssql_num_rows($result); - if ($retrieved_data) - { - $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\n"; - } - $i_num_fields = mssql_num_fields($result); for ($i = 0; $i < $i_num_fields; $i++) @@ -635,6 +647,21 @@ class acp_database $ary_name[$i] = mssql_field_name($result, $i); } + if ($retrieved_data) + { + $sql = "SELECT 1 as has_identity + FROM INFORMATION_SCHEMA.COLUMNS + WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1"; + $result2 = $db->sql_query($sql); + $row2 = $db->sql_fetchrow($result2); + if (!empty($row2['has_identity'])) + { + $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n"; + $ident_set = true; + } + $db->sql_freeresult($result2); + } + while ($row = $db->sql_fetchrow($result)) { $schema_vals = $schema_fields = array(); @@ -667,7 +694,7 @@ class acp_database $str_empty = 'NULL'; } - if (empty($str_val) && $str_val !== '0') + if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) { $str_val = $str_empty; } @@ -704,7 +731,11 @@ class acp_database if ($retrieved_data) { - $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\n"; + $sql_data = "\nGO\n"; + if ($ident_set) + { + $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n"; + } } break; @@ -1095,7 +1126,30 @@ class acp_database { // Strip out sql comments... remove_remarks($data); - $pieces = split_sql_file($data, ';'); + switch (SQL_LAYER) + { + case 'firebird': + $delim = ';;'; + break; + + case 'mysql': + case 'mysql4': + case 'mysqli': + case 'sqlite': + case 'postgres': + $delim = ';'; + break; + + case 'oracle': + $delim = '/'; + break; + + case 'mssql': + case 'mssql-odbc': + $delim = 'GO'; + break; + } + $pieces = split_sql_file($data, $delim); $sql_count = count($pieces); for($i = 0; $i < $sql_count; $i++) @@ -1556,8 +1610,11 @@ class acp_database } $rows[] = "\t\t[{$row['COLUMN_NAME']}]"; } - $sql_data .= implode(",\n", $rows); - $sql_data .= "\n\t) ON [PRIMARY] \nGO\n"; + if (sizeof($rows)) + { + $sql_data .= implode(",\n", $rows); + $sql_data .= "\n\t) ON [PRIMARY] \nGO\n"; + } $db->sql_freeresult($result); $index = array(); @@ -1567,7 +1624,7 @@ class acp_database { if ($row['TYPE'] == 3) { - $index[$row['INDEX_NAME']][] = $row['COLUMN_NAME']; + $index[$row['INDEX_NAME']][] = '[' . $row['COLUMN_NAME'] . ']'; } } $db->sql_freeresult($result); @@ -1579,7 +1636,7 @@ class acp_database foreach ($index as $index_name => $columns) { - $sql_data .= "\nCREATE INDEX [$index_name] ON [$table_name]([$columns]) ON [PRIMARY]\nGO\n"; + $sql_data .= "\nCREATE INDEX [$index_name] ON [$table_name]($columns) ON [PRIMARY]\nGO\n"; } break; |