Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
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 |
sql_parse.php
001 <?php
002 /***************************************************************************
003 * sql_parse.php
004 * -------------------
005 * begin : Thu May 31, 2001
006 * copyright : (C) 2001 The phpBB Group
007 * email : support@phpbb.com
008 *
009 * $Id$
010 *
011 ****************************************************************************/
012
013 /***************************************************************************
014 *
015 * This program is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU General Public License as published by
017 * the Free Software Foundation; either version 2 of the License, or
018 * (at your option) any later version.
019 *
020 ***************************************************************************/
021
022 /***************************************************************************
023 *
024 * These functions are mainly for use in the db_utilities under the admin
025 * however in order to make these functions available elsewhere, specifically
026 * in the installation phase of phpBB I have seperated out a couple of
027 * functions into this file. JLH
028 *
029 \***************************************************************************/
030
031 //
032 // remove_comments will strip the sql comment lines out of an uploaded sql file
033 // specifically for mssql and postgres type files in the install....
034 //
035 function remove_comments(&$output)
036 {
037 $lines = explode("\n", $output);
038 $output = "";
039
040 // try to keep mem. use down
041 $linecount = count($lines);
042
043 $in_comment = false;
044 for($i = 0; $i < $linecount; $i++)
045 {
046 if( preg_match("/^\/\*/", preg_quote($lines[$i])) )
047 {
048 $in_comment = true;
049 }
050
051 if( !$in_comment )
052 {
053 $output .= $lines[$i] . "\n";
054 }
055
056 if( preg_match("/\*\/$/", preg_quote($lines[$i])) )
057 {
058 $in_comment = false;
059 }
060 }
061
062 unset($lines);
063 return $output;
064 }
065
066 //
067 // remove_remarks will strip the sql comment lines out of an uploaded sql file
068 //
069 function remove_remarks($sql)
070 {
071 $lines = explode("\n", $sql);
072
073 // try to keep mem. use down
074 $sql = "";
075
076 $linecount = count($lines);
077 $output = "";
078
079 for ($i = 0; $i < $linecount; $i++)
080 {
081 if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))
082 {
083 if ($lines[$i][0] != "#")
084 {
085 $output .= $lines[$i] . "\n";
086 }
087 else
088 {
089 $output .= "\n";
090 }
091 // Trading a bit of speed for lower mem. use here.
092 $lines[$i] = "";
093 }
094 }
095
096 return $output;
097
098 }
099
100 //
101 // split_sql_file will split an uploaded sql file into single sql statements.
102 // Note: expects trim() to have already been run on $sql.
103 //
104 function split_sql_file($sql, $delimiter)
105 {
106 // Split up our string into "possible" SQL statements.
107 $tokens = explode($delimiter, $sql);
108
109 // try to save mem.
110 $sql = "";
111 $output = array();
112
113 // we don't actually care about the matches preg gives us.
114 $matches = array();
115
116 // this is faster than calling count($oktens) every time thru the loop.
117 $token_count = count($tokens);
118 for ($i = 0; $i < $token_count; $i++)
119 {
120 // Don't wanna add an empty string as the last thing in the array.
121 if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))
122 {
123 // This is the total number of single quotes in the token.
124 $total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
125 // Counts single quotes that are preceded by an odd number of backslashes,
126 // which means they're escaped quotes.
127 $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
128
129 $unescaped_quotes = $total_quotes - $escaped_quotes;
130
131 // If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
132 if (($unescaped_quotes % 2) == 0)
133 {
134 // It's a complete sql statement.
135 $output[] = $tokens[$i];
136 // save memory.
137 $tokens[$i] = "";
138 }
139 else
140 {
141 // incomplete sql statement. keep adding tokens until we have a complete one.
142 // $temp will hold what we have so far.
143 $temp = $tokens[$i] . $delimiter;
144 // save memory..
145 $tokens[$i] = "";
146
147 // Do we have a complete statement yet?
148 $complete_stmt = false;
149
150 for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
151 {
152 // This is the total number of single quotes in the token.
153 $total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
154 // Counts single quotes that are preceded by an odd number of backslashes,
155 // which means they're escaped quotes.
156 $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
157
158 $unescaped_quotes = $total_quotes - $escaped_quotes;
159
160 if (($unescaped_quotes % 2) == 1)
161 {
162 // odd number of unescaped quotes. In combination with the previous incomplete
163 // statement(s), we now have a complete statement. (2 odds always make an even)
164 $output[] = $temp . $tokens[$j];
165
166 // save memory.
167 $tokens[$j] = "";
168 $temp = "";
169
170 // exit the loop.
171 $complete_stmt = true;
172 // make sure the outer loop continues at the right point.
173 $i = $j;
174 }
175 else
176 {
177 // even number of unescaped quotes. We still don't have a complete statement.
178 // (1 odd and 1 even always make an odd)
179 $temp .= $tokens[$j] . $delimiter;
180 // save memory.
181 $tokens[$j] = "";
182 }
183
184 } // for..
185 } // else
186 }
187 }
188
189 return $output;
190 }
191
192 ?>