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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
sqlite3_extractor.php
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 sqlite3_extractor extends base_extractor
019 {
020 /**
021 * {@inheritdoc}
022 */
023 public function write_start($table_prefix)
024 {
025 if (!$this->is_initialized)
026 {
027 throw new extractor_not_initialized_exception();
028 }
029
030 $sql_data = "--\n";
031 $sql_data .= "-- phpBB Backup Script\n";
032 $sql_data .= "-- Dump of tables for $table_prefix\n";
033 $sql_data .= "-- DATE : " . gmdate("d-m-Y H:i:s", $this->time) . " GMT\n";
034 $sql_data .= "--\n";
035 $sql_data .= "BEGIN TRANSACTION;\n";
036 $this->flush($sql_data);
037 }
038
039 /**
040 * {@inheritdoc}
041 */
042 public function write_table($table_name)
043 {
044 if (!$this->is_initialized)
045 {
046 throw new extractor_not_initialized_exception();
047 }
048
049 $sql_data = '-- Table: ' . $table_name . "\n";
050 $sql_data .= "DROP TABLE $table_name;\n";
051
052 $sql = "SELECT sql
053 FROM sqlite_master
054 WHERE type = 'table'
055 AND name = '" . $this->db->sql_escape($table_name) . "'
056 ORDER BY name ASC;";
057 $result = $this->db->sql_query($sql);
058 $row = $this->db->sql_fetchrow($result);
059 $this->db->sql_freeresult($result);
060
061 // Create Table
062 $sql_data .= $row['sql'] . ";\n";
063
064 $result = $this->db->sql_query("PRAGMA index_list('" . $this->db->sql_escape($table_name) . "');");
065
066 while ($row = $this->db->sql_fetchrow($result))
067 {
068 if (strpos($row['name'], 'autoindex') !== false)
069 {
070 continue;
071 }
072
073 $result2 = $this->db->sql_query("PRAGMA index_info('" . $this->db->sql_escape($row['name']) . "');");
074
075 $fields = array();
076 while ($row2 = $this->db->sql_fetchrow($result2))
077 {
078 $fields[] = $row2['name'];
079 }
080 $this->db->sql_freeresult($result2);
081
082 $sql_data .= 'CREATE ' . ($row['unique'] ? 'UNIQUE ' : '') . 'INDEX ' . $row['name'] . ' ON ' . $table_name . ' (' . implode(', ', $fields) . ");\n";
083 }
084 $this->db->sql_freeresult($result);
085
086 $this->flush($sql_data . "\n");
087 }
088
089 /**
090 * {@inheritdoc}
091 */
092 public function write_data($table_name)
093 {
094 if (!$this->is_initialized)
095 {
096 throw new extractor_not_initialized_exception();
097 }
098
099 $result = $this->db->sql_query("PRAGMA table_info('" . $this->db->sql_escape($table_name) . "');");
100
101 $col_types = array();
102 while ($row = $this->db->sql_fetchrow($result))
103 {
104 $col_types[$row['name']] = $row['type'];
105 }
106 $this->db->sql_freeresult($result);
107
108 $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES (';
109
110 $sql = "SELECT *
111 FROM $table_name";
112 $result = $this->db->sql_query($sql);
113
114 while ($row = $this->db->sql_fetchrow($result))
115 {
116 foreach ($row as $column_name => $column_data)
117 {
118 if (is_null($column_data))
119 {
120 $row[$column_name] = 'NULL';
121 }
122 else if ($column_data === '')
123 {
124 $row[$column_name] = "''";
125 }
126 else if (stripos($col_types[$column_name], 'text') !== false || stripos($col_types[$column_name], 'char') !== false || stripos($col_types[$column_name], 'blob') !== false)
127 {
128 $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data));
129 }
130 }
131 $this->flush($sql_insert . implode(', ', $row) . ");\n");
132 }
133 }
134
135 /**
136 * Writes closing line(s) to database backup
137 *
138 * @return null
139 * @throws extractor_not_initialized_exception when calling this function before init_extractor()
140 */
141 public function write_end()
142 {
143 if (!$this->is_initialized)
144 {
145 throw new extractor_not_initialized_exception();
146 }
147
148 $this->flush("COMMIT;\n");
149 parent::write_end();
150 }
151 }
152