Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/acp/acp_database.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_database.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2828                global $cache, $db, $user, $auth, $template, $table_prefix;
    2929                global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    30                
     30
    3131                $user->add_lang('acp/database');
    3232
     
    8383
    8484                                                @set_time_limit(1200);
     85                                                @set_time_limit(0);
    8586
    8687                                                $time = time();
     
    142143
    143144                                                                        case 'oracle':
    144                                                                                 $extractor->flush('TRUNCATE TABLE ' . $table_name . "\\\n");
     145                                                                                $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
    145146                                                                        break;
    146147
     
    188189                                                        'U_ACTION'      => $this->u_action . '&action=download'
    189190                                                ));
    190                                                
     191
    191192                                                $available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');
    192193
     
    425426                                                $dh = @opendir($dir);
    426427
     428                                                $backup_files = array();
     429
    427430                                                if ($dh)
    428431                                                {
     
    431434                                                                if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches))
    432435                                                                {
    433                                                                         $supported = in_array($matches[2], $methods);
    434 
    435                                                                         if ($supported == 'true')
     436                                                                        if (in_array($matches[2], $methods))
    436437                                                                        {
    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;
    442439                                                                        }
    443440                                                                }
    444441                                                        }
    445442                                                        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                                                        }
    446457                                                }
    447458
     
    509520                        header("Content-Type: $mimetype; name=\"$name\"");
    510521                        header("Content-disposition: attachment; filename=$name");
    511        
     522
    512523                        switch ($format)
    513524                        {
     
    528539                        }
    529540                }
    530                
     541
    531542                if ($store == true)
    532543                {
    533544                        global $phpbb_root_path;
    534545                        $file = $phpbb_root_path . 'store/' . $filename . $ext;
    535        
     546
    536547                        $this->fp = $open($file, 'w');
    537        
     548
    538549                        if (!$this->fp)
    539550                        {
    540                                 trigger_error('Unable to write temporary file to storage folder', E_USER_ERROR);
     551                                trigger_error('FILE_WRITE_FAIL', E_USER_ERROR);
    541552                        }
    542553                }
     
    546557        {
    547558                static $close;
     559
    548560                if ($this->store)
    549561                {
     
    663675                {
    664676                        $fields_cnt = mysqli_num_fields($result);
    665                
     677
    666678                        // Get field information
    667679                        $field = mysqli_fetch_fields($result);
    668680                        $field_set = array();
    669                
     681
    670682                        for ($j = 0; $j < $fields_cnt; $j++)
    671683                        {
     
    680692                        $query_len              = 0;
    681693                        $max_len                = get_usable_memory();
    682                
     694
    683695                        while ($row = mysqli_fetch_row($result))
    684696                        {
     
    751763                        }
    752764                        $field_set = array();
    753                        
     765
    754766                        for ($j = 0; $j < $fields_cnt; $j++)
    755767                        {
     
    967979                }
    968980                $db->sql_freeresult($result);
    969                
     981
    970982                foreach ($ar as $value)
    971983                {
     
    11251137                }
    11261138                $db->sql_freeresult($result);
    1127        
     1139
    11281140                $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
    11291141                        FROM pg_class c, pg_attribute a, pg_type t
     
    11461158                                        AND d.adnum = " . $row['attnum'];
    11471159                        $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))
    11501164                        {
    11511165                                unset($row['rowdefault']);
     
    11531167                        else
    11541168                        {
    1155                                 $row['rowdefault'] = $db->sql_fetchfield('rowdefault', false, $def_res);
    1156                         }
    1157                         $db->sql_freeresult($def_res);
     1169                                $row['rowdefault'] = $def_row['rowdefault'];
     1170                        }
    11581171
    11591172                        if ($row['type'] == 'bpchar')
     
    11891202                                $line .= ' NOT NULL';
    11901203                        }
    1191                        
     1204
    11921205                        $lines[] = $line;
    11931206                }
     
    13891402                $sql_data .= "\nCREATE TABLE [$table_name] (\n";
    13901403                $rows = array();
    1391        
     1404
    13921405                $text_flag = false;
    1393        
     1406
    13941407                $sql = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') as IS_IDENTITY
    13951408                        FROM INFORMATION_SCHEMA.COLUMNS
    13961409                        WHERE TABLE_NAME = '$table_name'";
    13971410                $result = $db->sql_query($sql);
    1398        
     1411
    13991412                while ($row = $db->sql_fetchrow($result))
    14001413                {
    14011414                        $line = "\t[{$row['COLUMN_NAME']}] [{$row['DATA_TYPE']}]";
    1402        
     1415
    14031416                        if ($row['DATA_TYPE'] == 'text')
    14041417                        {
    14051418                                $text_flag = true;
    14061419                        }
    1407        
     1420
    14081421                        if ($row['IS_IDENTITY'])
    14091422                        {
    14101423                                $line .= ' IDENTITY (1 , 1)';
    14111424                        }
    1412        
     1425
    14131426                        if ($row['CHARACTER_MAXIMUM_LENGTH'] && $row['DATA_TYPE'] !== 'text')
    14141427                        {
    14151428                                $line .= ' (' . $row['CHARACTER_MAXIMUM_LENGTH'] . ')';
    14161429                        }
    1417        
     1430
    14181431                        if ($row['IS_NULLABLE'] == 'YES')
    14191432                        {
     
    14241437                                $line .= ' NOT NULL';
    14251438                        }
    1426        
     1439
    14271440                        if ($row['COLUMN_DEFAULT'])
    14281441                        {
    14291442                                $line .= ' DEFAULT ' . $row['COLUMN_DEFAULT'];
    14301443                        }
    1431        
     1444
    14321445                        $rows[] = $line;
    14331446                }
    14341447                $db->sql_freeresult($result);
    1435        
     1448
    14361449                $sql_data .= implode(",\n", $rows);
    14371450                $sql_data .= "\n) ON [PRIMARY]";
    1438        
     1451
    14391452                if ($text_flag)
    14401453                {
    14411454                        $sql_data .= " TEXTIMAGE_ON [PRIMARY]";
    14421455                }
    1443        
     1456
    14441457                $sql_data .= "\nGO\n\n";
    14451458                $rows = array();
    1446        
     1459
    14471460                $sql = "SELECT CONSTRAINT_NAME, COLUMN_NAME
    14481461                        FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
     
    14641477                }
    14651478                $db->sql_freeresult($result);
    1466        
     1479
    14671480                $index = array();
    14681481                $sql = "EXEC sp_statistics '$table_name'";
     
    14761489                }
    14771490                $db->sql_freeresult($result);
    1478        
     1491
    14791492                foreach ($index as $index_name => $column_name)
    14801493                {
    14811494                        $index[$index_name] = implode(', ', $column_name);
    14821495                }
    1483        
     1496
    14841497                foreach ($index as $index_name => $columns)
    14851498                {
     
    15091522                $ident_set = false;
    15101523                $sql_data = '';
    1511                
     1524
    15121525                // Grab all of the data from current table.
    15131526                $sql = "SELECT *
     
    16031616                $ident_set = false;
    16041617                $sql_data = '';
    1605                
     1618
    16061619                // Grab all of the data from current table.
    16071620                $sql = "SELECT *
     
    17041717                global $db;
    17051718                $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";
    17081720                $sql_data .= "\nCREATE TABLE $table_name (\n";
    17091721
     
    17201732                        if ($row['data_type'] !== 'CLOB')
    17211733                        {
    1722                                 if ($row['data_type'] !== 'VARCHAR2')
     1734                                if ($row['data_type'] !== 'VARCHAR2' && $row['data_type'] !== 'CHAR')
    17231735                                {
    17241736                                        $line .= '(' . $row['data_precision'] . ')';
     
    17501762                $result = $db->sql_query($sql);
    17511763
    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                }
    17571777
    17581778                $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME
     
    17631783                $result = $db->sql_query($sql);
    17641784
    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                }
    17701798
    17711799                $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
    17761804                        WHERE A.REFERENCED_TYPE = 'SEQUENCE'
    17771805                                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";
    17791808                $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";
    17831823                }
    17841824                $db->sql_freeresult($result);
     
    17901830                while ($row = $db->sql_fetchrow($result))
    17911831                {
    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";
    17931833                }
    17941834                $db->sql_freeresult($result);
     
    18101850                foreach ($index as $index_name => $column_names)
    18111851                {
    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";
    18131853                }
    18141854                $db->sql_freeresult($result);
     
    18201860                global $db;
    18211861                $ary_type = $ary_name = array();
    1822                
     1862
    18231863                // Grab all of the data from current table.
    18241864                $sql = "SELECT *
     
    18431883                        for ($i = 0; $i < $i_num_fields; $i++)
    18441884                        {
    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]))
    18481889                                {
    18491890                                        $str_quote = '';
     
    18741915
    18751916                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
    1876                                 $schema_fields[$i] = '"' . $ary_name[$i] . "'";
     1917                                $schema_fields[$i] = '"' . $ary_name[$i] . '"';
    18771918                        }
    18781919
    18791920                        // Take the ordered fields and their associated data and build it
    18801921                        // 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";
    18821923
    18831924                        $this->flush($sql_data);
     
    19161957                global $db;
    19171958                $ary_type = $ary_name = array();
    1918                
     1959
    19191960                // Grab all of the data from current table.
    19201961                $sql = "SELECT *
     
    21982239function sanitize_data_oracle($text)
    21992240{
    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);
    22022245
    22032246        $val = array();
     
    22452288        $record = '';
    22462289        $delim_len = strlen($delim);
    2247        
     2290
    22482291        while (!$eof($fp))
    22492292        {
Note: See TracChangeset for help on using the changeset viewer.