Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

oracle_extractor.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 6.63 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\db\extractor;
015   
016  use phpbb\db\extractor\exception\extractor_not_initialized_exception;
017   
018  class oracle_extractor extends base_extractor
019  {
020      /**
021      * {@inheritdoc}
022      */
023      public function write_table($table_name)
024      {
025          if (!$this->is_initialized)
026          {
027              throw new extractor_not_initialized_exception();
028          }
029   
030          $sql_data = '-- Table: ' . $table_name . "\n";
031          $sql_data .= "DROP TABLE $table_name\n/\n";
032          $sql_data .= "\nCREATE TABLE $table_name (\n";
033   
034          $sql = "SELECT COLUMN_NAME, DATA_TYPE, DATA_PRECISION, DATA_LENGTH, NULLABLE, DATA_DEFAULT
035              FROM ALL_TAB_COLS
036              WHERE table_name = '{$table_name}'";
037          $result = $this->db->sql_query($sql);
038   
039          $rows = array();
040          while ($row = $this->db->sql_fetchrow($result))
041          {
042              $line = '  "' . $row['column_name'] . '" ' . $row['data_type'];
043   
044              if ($row['data_type'] !== 'CLOB')
045              {
046                  if ($row['data_type'] !== 'VARCHAR2' && $row['data_type'] !== 'CHAR')
047                  {
048                      $line .= '(' . $row['data_precision'] . ')';
049                  }
050                  else
051                  {
052                      $line .= '(' . $row['data_length'] . ')';
053                  }
054              }
055   
056              if (!empty($row['data_default']))
057              {
058                  $line .= ' DEFAULT ' . $row['data_default'];
059              }
060   
061              if ($row['nullable'] == 'N')
062              {
063                  $line .= ' NOT NULL';
064              }
065              $rows[] = $line;
066          }
067          $this->db->sql_freeresult($result);
068   
069          $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME
070              FROM USER_CONS_COLUMNS A, USER_CONSTRAINTS B
071              WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
072                  AND B.CONSTRAINT_TYPE = 'P'
073                  AND A.TABLE_NAME = '{$table_name}'";
074          $result = $this->db->sql_query($sql);
075   
076          $primary_key = array();
077          $constraint_name = '';
078          while ($row = $this->db->sql_fetchrow($result))
079          {
080              $constraint_name = '"' . $row['constraint_name'] . '"';
081              $primary_key[] = '"' . $row['column_name'] . '"';
082          }
083          $this->db->sql_freeresult($result);
084   
085          if (count($primary_key))
086          {
087              $rows[] = "  CONSTRAINT {$constraint_name} PRIMARY KEY (" . implode(', ', $primary_key) . ')';
088          }
089   
090          $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME
091              FROM USER_CONS_COLUMNS A, USER_CONSTRAINTS B
092              WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
093                  AND B.CONSTRAINT_TYPE = 'U'
094                  AND A.TABLE_NAME = '{$table_name}'";
095          $result = $this->db->sql_query($sql);
096   
097          $unique = array();
098          $constraint_name = '';
099          while ($row = $this->db->sql_fetchrow($result))
100          {
101              $constraint_name = '"' . $row['constraint_name'] . '"';
102              $unique[] = '"' . $row['column_name'] . '"';
103          }
104          $this->db->sql_freeresult($result);
105   
106          if (count($unique))
107          {
108              $rows[] = "  CONSTRAINT {$constraint_name} UNIQUE (" . implode(', ', $unique) . ')';
109          }
110   
111          $sql_data .= implode(",\n", $rows);
112          $sql_data .= "\n)\n/\n";
113   
114          $sql = "SELECT A.REFERENCED_NAME, C.*
115              FROM USER_DEPENDENCIES A, USER_TRIGGERS B, USER_SEQUENCES C
116              WHERE A.REFERENCED_TYPE = 'SEQUENCE'
117                  AND A.NAME = B.TRIGGER_NAME
118                  AND B.TABLE_NAME = '{$table_name}'
119                  AND C.SEQUENCE_NAME = A.REFERENCED_NAME";
120          $result = $this->db->sql_query($sql);
121   
122          $type = $this->request->variable('type', '');
123   
124          while ($row = $this->db->sql_fetchrow($result))
125          {
126              $sql_data .= "\nDROP SEQUENCE \"{$row['referenced_name']}\"\n/\n";
127              $sql_data .= "\nCREATE SEQUENCE \"{$row['referenced_name']}\"";
128   
129              if ($type == 'full')
130              {
131                  $sql_data .= ' START WITH ' . $row['last_number'];
132              }
133   
134              $sql_data .= "\n/\n";
135          }
136          $this->db->sql_freeresult($result);
137   
138          $sql = "SELECT DESCRIPTION, WHEN_CLAUSE, TRIGGER_BODY
139              FROM USER_TRIGGERS
140              WHERE TABLE_NAME = '{$table_name}'";
141          $result = $this->db->sql_query($sql);
142          while ($row = $this->db->sql_fetchrow($result))
143          {
144              $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\n/\n";
145          }
146          $this->db->sql_freeresult($result);
147   
148          $sql = "SELECT A.INDEX_NAME, B.COLUMN_NAME
149              FROM USER_INDEXES A, USER_IND_COLUMNS B
150              WHERE A.UNIQUENESS = 'NONUNIQUE'
151                  AND A.INDEX_NAME = B.INDEX_NAME
152                  AND B.TABLE_NAME = '{$table_name}'";
153          $result = $this->db->sql_query($sql);
154   
155          $index = array();
156   
157          while ($row = $this->db->sql_fetchrow($result))
158          {
159              $index[$row['index_name']][] = $row['column_name'];
160          }
161   
162          foreach ($index as $index_name => $column_names)
163          {
164              $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n/\n";
165          }
166          $this->db->sql_freeresult($result);
167          $this->flush($sql_data);
168      }
169   
170      /**
171      * {@inheritdoc}
172      */
173      public function write_data($table_name)
174      {
175          if (!$this->is_initialized)
176          {
177              throw new extractor_not_initialized_exception();
178          }
179   
180          $ary_type = $ary_name = array();
181   
182          // Grab all of the data from current table.
183          $sql = "SELECT *
184              FROM $table_name";
185          $result = $this->db->sql_query($sql);
186   
187          $i_num_fields = ocinumcols($result);
188   
189          for ($i = 0; $i < $i_num_fields; $i++)
190          {
191              $ary_type[$i] = ocicolumntype($result, $i + 1);
192              $ary_name[$i] = ocicolumnname($result, $i + 1);
193          }
194   
195          while ($row = $this->db->sql_fetchrow($result))
196          {
197              $schema_vals = $schema_fields = array();
198   
199              // Build the SQL statement to recreate the data.
200              for ($i = 0; $i < $i_num_fields; $i++)
201              {
202                  // Oracle uses uppercase - we use lowercase
203                  $str_val = $row[strtolower($ary_name[$i])];
204   
205                  if (preg_match('#char|text|bool|raw|clob#i', $ary_type[$i]))
206                  {
207                      $str_quote = '';
208                      $str_empty = "''";
209                      $str_val = sanitize_data_oracle($str_val);
210                  }
211                  else if (preg_match('#date|timestamp#i', $ary_type[$i]))
212                  {
213                      if (empty($str_val))
214                      {
215                          $str_quote = '';
216                      }
217                      else
218                      {
219                          $str_quote = "'";
220                      }
221                  }
222                  else
223                  {
224                      $str_quote = '';
225                      $str_empty = 'NULL';
226                  }
227   
228                  if (empty($str_val) && $str_val !== '0')
229                  {
230                      $str_val = $str_empty;
231                  }
232   
233                  $schema_vals[$i] = $str_quote . $str_val . $str_quote;
234                  $schema_fields[$i] = '"' . $ary_name[$i] . '"';
235              }
236   
237              // Take the ordered fields and their associated data and build it
238              // into a valid sql statement to recreate that field in the data.
239              $sql_data = "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ")\n/\n";
240   
241              $this->flush($sql_data);
242          }
243          $this->db->sql_freeresult($result);
244      }
245   
246      /**
247      * {@inheritdoc}
248      */
249      public function write_start($table_prefix)
250      {
251          if (!$this->is_initialized)
252          {
253              throw new extractor_not_initialized_exception();
254          }
255   
256          $sql_data = "--\n";
257          $sql_data .= "-- phpBB Backup Script\n";
258          $sql_data .= "-- Dump of tables for $table_prefix\n";
259          $sql_data .= "-- DATE : " . gmdate("d-m-Y H:i:s", $this->time) . " GMT\n";
260          $sql_data .= "--\n";
261          $this->flush($sql_data);
262      }
263  }
264