Changeset 702 for trunk/forum/includes/acp/acp_database.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/acp/acp_database.php
r400 r702 3 3 * 4 4 * @package acp 5 * @version $Id : acp_database.php 8814 2008-09-04 12:01:47Z acydburn$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 28 28 global $cache, $db, $user, $auth, $template, $table_prefix; 29 29 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 30 30 31 31 $user->add_lang('acp/database'); 32 32 … … 83 83 84 84 @set_time_limit(1200); 85 @set_time_limit(0); 85 86 86 87 $time = time(); … … 142 143 143 144 case 'oracle': 144 $extractor->flush('TRUNCATE TABLE ' . $table_name . " \\\n");145 $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n"); 145 146 break; 146 147 … … 188 189 'U_ACTION' => $this->u_action . '&action=download' 189 190 )); 190 191 191 192 $available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2'); 192 193 … … 425 426 $dh = @opendir($dir); 426 427 428 $backup_files = array(); 429 427 430 if ($dh) 428 431 { … … 431 434 if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches)) 432 435 { 433 $supported = in_array($matches[2], $methods); 434 435 if ($supported == 'true') 436 if (in_array($matches[2], $methods)) 436 437 { 437 $template->assign_block_vars('files', array( 438 'FILE' => $file, 439 'NAME' => gmdate("d-m-Y H:i:s", $matches[1]), 440 'SUPPORTED' => $supported 441 )); 438 $backup_files[gmdate("d-m-Y H:i:s", $matches[1])] = $file; 442 439 } 443 440 } 444 441 } 445 442 closedir($dh); 443 } 444 445 if (!empty($backup_files)) 446 { 447 krsort($backup_files); 448 449 foreach ($backup_files as $name => $file) 450 { 451 $template->assign_block_vars('files', array( 452 'FILE' => $file, 453 'NAME' => $name, 454 'SUPPORTED' => true, 455 )); 456 } 446 457 } 447 458 … … 509 520 header("Content-Type: $mimetype; name=\"$name\""); 510 521 header("Content-disposition: attachment; filename=$name"); 511 522 512 523 switch ($format) 513 524 { … … 528 539 } 529 540 } 530 541 531 542 if ($store == true) 532 543 { 533 544 global $phpbb_root_path; 534 545 $file = $phpbb_root_path . 'store/' . $filename . $ext; 535 546 536 547 $this->fp = $open($file, 'w'); 537 548 538 549 if (!$this->fp) 539 550 { 540 trigger_error(' Unable to write temporary file to storage folder', E_USER_ERROR);551 trigger_error('FILE_WRITE_FAIL', E_USER_ERROR); 541 552 } 542 553 } … … 546 557 { 547 558 static $close; 559 548 560 if ($this->store) 549 561 { … … 663 675 { 664 676 $fields_cnt = mysqli_num_fields($result); 665 677 666 678 // Get field information 667 679 $field = mysqli_fetch_fields($result); 668 680 $field_set = array(); 669 681 670 682 for ($j = 0; $j < $fields_cnt; $j++) 671 683 { … … 680 692 $query_len = 0; 681 693 $max_len = get_usable_memory(); 682 694 683 695 while ($row = mysqli_fetch_row($result)) 684 696 { … … 751 763 } 752 764 $field_set = array(); 753 765 754 766 for ($j = 0; $j < $fields_cnt; $j++) 755 767 { … … 967 979 } 968 980 $db->sql_freeresult($result); 969 981 970 982 foreach ($ar as $value) 971 983 { … … 1125 1137 } 1126 1138 $db->sql_freeresult($result); 1127 1139 1128 1140 $field_query = "SELECT a.attnum, a.attname as field, t.typname as type, a.attlen as length, a.atttypmod as lengthvar, a.attnotnull as notnull 1129 1141 FROM pg_class c, pg_attribute a, pg_type t … … 1146 1158 AND d.adnum = " . $row['attnum']; 1147 1159 $def_res = $db->sql_query($sql_get_default); 1148 1149 if (!$def_res) 1160 $def_row = $db->sql_fetchrow($def_res); 1161 $db->sql_freeresult($def_res); 1162 1163 if (empty($def_row)) 1150 1164 { 1151 1165 unset($row['rowdefault']); … … 1153 1167 else 1154 1168 { 1155 $row['rowdefault'] = $db->sql_fetchfield('rowdefault', false, $def_res); 1156 } 1157 $db->sql_freeresult($def_res); 1169 $row['rowdefault'] = $def_row['rowdefault']; 1170 } 1158 1171 1159 1172 if ($row['type'] == 'bpchar') … … 1189 1202 $line .= ' NOT NULL'; 1190 1203 } 1191 1204 1192 1205 $lines[] = $line; 1193 1206 } … … 1389 1402 $sql_data .= "\nCREATE TABLE [$table_name] (\n"; 1390 1403 $rows = array(); 1391 1404 1392 1405 $text_flag = false; 1393 1406 1394 1407 $sql = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') as IS_IDENTITY 1395 1408 FROM INFORMATION_SCHEMA.COLUMNS 1396 1409 WHERE TABLE_NAME = '$table_name'"; 1397 1410 $result = $db->sql_query($sql); 1398 1411 1399 1412 while ($row = $db->sql_fetchrow($result)) 1400 1413 { 1401 1414 $line = "\t[{$row['COLUMN_NAME']}] [{$row['DATA_TYPE']}]"; 1402 1415 1403 1416 if ($row['DATA_TYPE'] == 'text') 1404 1417 { 1405 1418 $text_flag = true; 1406 1419 } 1407 1420 1408 1421 if ($row['IS_IDENTITY']) 1409 1422 { 1410 1423 $line .= ' IDENTITY (1 , 1)'; 1411 1424 } 1412 1425 1413 1426 if ($row['CHARACTER_MAXIMUM_LENGTH'] && $row['DATA_TYPE'] !== 'text') 1414 1427 { 1415 1428 $line .= ' (' . $row['CHARACTER_MAXIMUM_LENGTH'] . ')'; 1416 1429 } 1417 1430 1418 1431 if ($row['IS_NULLABLE'] == 'YES') 1419 1432 { … … 1424 1437 $line .= ' NOT NULL'; 1425 1438 } 1426 1439 1427 1440 if ($row['COLUMN_DEFAULT']) 1428 1441 { 1429 1442 $line .= ' DEFAULT ' . $row['COLUMN_DEFAULT']; 1430 1443 } 1431 1444 1432 1445 $rows[] = $line; 1433 1446 } 1434 1447 $db->sql_freeresult($result); 1435 1448 1436 1449 $sql_data .= implode(",\n", $rows); 1437 1450 $sql_data .= "\n) ON [PRIMARY]"; 1438 1451 1439 1452 if ($text_flag) 1440 1453 { 1441 1454 $sql_data .= " TEXTIMAGE_ON [PRIMARY]"; 1442 1455 } 1443 1456 1444 1457 $sql_data .= "\nGO\n\n"; 1445 1458 $rows = array(); 1446 1459 1447 1460 $sql = "SELECT CONSTRAINT_NAME, COLUMN_NAME 1448 1461 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE … … 1464 1477 } 1465 1478 $db->sql_freeresult($result); 1466 1479 1467 1480 $index = array(); 1468 1481 $sql = "EXEC sp_statistics '$table_name'"; … … 1476 1489 } 1477 1490 $db->sql_freeresult($result); 1478 1491 1479 1492 foreach ($index as $index_name => $column_name) 1480 1493 { 1481 1494 $index[$index_name] = implode(', ', $column_name); 1482 1495 } 1483 1496 1484 1497 foreach ($index as $index_name => $columns) 1485 1498 { … … 1509 1522 $ident_set = false; 1510 1523 $sql_data = ''; 1511 1524 1512 1525 // Grab all of the data from current table. 1513 1526 $sql = "SELECT * … … 1603 1616 $ident_set = false; 1604 1617 $sql_data = ''; 1605 1618 1606 1619 // Grab all of the data from current table. 1607 1620 $sql = "SELECT * … … 1704 1717 global $db; 1705 1718 $sql_data = '-- Table: ' . $table_name . "\n"; 1706 $sql_data .= "DROP TABLE $table_name;\n"; 1707 $sql_data .= '\\' . "\n"; 1719 $sql_data .= "DROP TABLE $table_name\n/\n"; 1708 1720 $sql_data .= "\nCREATE TABLE $table_name (\n"; 1709 1721 … … 1720 1732 if ($row['data_type'] !== 'CLOB') 1721 1733 { 1722 if ($row['data_type'] !== 'VARCHAR2' )1734 if ($row['data_type'] !== 'VARCHAR2' && $row['data_type'] !== 'CHAR') 1723 1735 { 1724 1736 $line .= '(' . $row['data_precision'] . ')'; … … 1750 1762 $result = $db->sql_query($sql); 1751 1763 1752 while ($row = $db->sql_fetchrow($result)) 1753 { 1754 $rows[] = " CONSTRAINT {$row['constraint_name']} PRIMARY KEY ({$row['column_name']})"; 1755 } 1756 $db->sql_freeresult($result); 1764 $primary_key = array(); 1765 $contraint_name = ''; 1766 while ($row = $db->sql_fetchrow($result)) 1767 { 1768 $constraint_name = '"' . $row['constraint_name'] . '"'; 1769 $primary_key[] = '"' . $row['column_name'] . '"'; 1770 } 1771 $db->sql_freeresult($result); 1772 1773 if (sizeof($primary_key)) 1774 { 1775 $rows[] = " CONSTRAINT {$constraint_name} PRIMARY KEY (" . implode(', ', $primary_key) . ')'; 1776 } 1757 1777 1758 1778 $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME … … 1763 1783 $result = $db->sql_query($sql); 1764 1784 1765 while ($row = $db->sql_fetchrow($result)) 1766 { 1767 $rows[] = " CONSTRAINT {$row['constraint_name']} UNIQUE ({$row['column_name']})"; 1768 } 1769 $db->sql_freeresult($result); 1785 $unique = array(); 1786 $contraint_name = ''; 1787 while ($row = $db->sql_fetchrow($result)) 1788 { 1789 $constraint_name = '"' . $row['constraint_name'] . '"'; 1790 $unique[] = '"' . $row['column_name'] . '"'; 1791 } 1792 $db->sql_freeresult($result); 1793 1794 if (sizeof($unique)) 1795 { 1796 $rows[] = " CONSTRAINT {$constraint_name} UNIQUE (" . implode(', ', $unique) . ')'; 1797 } 1770 1798 1771 1799 $sql_data .= implode(",\n", $rows); 1772 $sql_data .= "\n)\n \\";1773 1774 $sql = "SELECT A.REFERENCED_NAME 1775 FROM USER_DEPENDENCIES A, USER_TRIGGERS B 1800 $sql_data .= "\n)\n/\n"; 1801 1802 $sql = "SELECT A.REFERENCED_NAME, C.* 1803 FROM USER_DEPENDENCIES A, USER_TRIGGERS B, USER_SEQUENCES C 1776 1804 WHERE A.REFERENCED_TYPE = 'SEQUENCE' 1777 1805 AND A.NAME = B.TRIGGER_NAME 1778 AND B. TABLE_NAME = '{$table_name}'"; 1806 AND B.TABLE_NAME = '{$table_name}' 1807 AND C.SEQUENCE_NAME = A.REFERENCED_NAME"; 1779 1808 $result = $db->sql_query($sql); 1780 while ($row = $db->sql_fetchrow($result)) 1781 { 1782 $sql_data .= "\nCREATE SEQUENCE {$row['referenced_name']}\\\n"; 1809 1810 $type = request_var('type', ''); 1811 1812 while ($row = $db->sql_fetchrow($result)) 1813 { 1814 $sql_data .= "\nDROP SEQUENCE \"{$row['referenced_name']}\"\n/\n"; 1815 $sql_data .= "\nCREATE SEQUENCE \"{$row['referenced_name']}\""; 1816 1817 if ($type == 'full') 1818 { 1819 $sql_data .= ' START WITH ' . $row['last_number']; 1820 } 1821 1822 $sql_data .= "\n/\n"; 1783 1823 } 1784 1824 $db->sql_freeresult($result); … … 1790 1830 while ($row = $db->sql_fetchrow($result)) 1791 1831 { 1792 $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\ \";1832 $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\n/\n"; 1793 1833 } 1794 1834 $db->sql_freeresult($result); … … 1810 1850 foreach ($index as $index_name => $column_names) 1811 1851 { 1812 $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n \\";1852 $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n/\n"; 1813 1853 } 1814 1854 $db->sql_freeresult($result); … … 1820 1860 global $db; 1821 1861 $ary_type = $ary_name = array(); 1822 1862 1823 1863 // Grab all of the data from current table. 1824 1864 $sql = "SELECT * … … 1843 1883 for ($i = 0; $i < $i_num_fields; $i++) 1844 1884 { 1845 $str_val = $row[$ary_name[$i]]; 1846 1847 if (preg_match('#char|text|bool|raw#i', $ary_type[$i])) 1885 // Oracle uses uppercase - we use lowercase 1886 $str_val = $row[strtolower($ary_name[$i])]; 1887 1888 if (preg_match('#char|text|bool|raw|clob#i', $ary_type[$i])) 1848 1889 { 1849 1890 $str_quote = ''; … … 1874 1915 1875 1916 $schema_vals[$i] = $str_quote . $str_val . $str_quote; 1876 $schema_fields[$i] = '"' . $ary_name[$i] . "'";1917 $schema_fields[$i] = '"' . $ary_name[$i] . '"'; 1877 1918 } 1878 1919 1879 1920 // Take the ordered fields and their associated data and build it 1880 1921 // into a valid sql statement to recreate that field in the data. 1881 $sql_data = "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ") ;\n";1922 $sql_data = "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ")\n/\n"; 1882 1923 1883 1924 $this->flush($sql_data); … … 1916 1957 global $db; 1917 1958 $ary_type = $ary_name = array(); 1918 1959 1919 1960 // Grab all of the data from current table. 1920 1961 $sql = "SELECT * … … 2198 2239 function sanitize_data_oracle($text) 2199 2240 { 2200 $data = preg_split('/[\0\n\t\r\b\f\'"\\\]/', $text); 2201 preg_match_all('/[\0\n\t\r\b\f\'"\\\]/', $text, $matches); 2241 // $data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text); 2242 // preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches); 2243 $data = preg_split('/[\0\b\f\'\/]/', $text); 2244 preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches); 2202 2245 2203 2246 $val = array(); … … 2245 2288 $record = ''; 2246 2289 $delim_len = strlen($delim); 2247 2290 2248 2291 while (!$eof($fp)) 2249 2292 {
Note:
See TracChangeset
for help on using the changeset viewer.