00001 <?php
00002
00003
00004
00019 function PMA_splitSqlFile(&$ret, $sql, $release)
00020 {
00021
00022
00023 $sql = rtrim($sql, "\n\r");
00024 $sql_len = strlen($sql);
00025 $char = '';
00026 $string_start = '';
00027 $in_string = FALSE;
00028 $nothing = TRUE;
00029 $time0 = time();
00030
00031 for ($i = 0; $i < $sql_len; ++$i) {
00032 $char = $sql[$i];
00033
00034
00035
00036 if ($in_string) {
00037 for (;;) {
00038 $i = strpos($sql, $string_start, $i);
00039
00040
00041 if (!$i) {
00042 $ret[] = array('query' => $sql, 'empty' => $nothing);
00043 return TRUE;
00044 }
00045
00046
00047 else if ($string_start == '`' || $sql[$i-1] != '\\') {
00048 $string_start = '';
00049 $in_string = FALSE;
00050 break;
00051 }
00052
00053 else {
00054
00055 $j = 2;
00056 $escaped_backslash = FALSE;
00057 while ($i-$j > 0 && $sql[$i-$j] == '\\') {
00058 $escaped_backslash = !$escaped_backslash;
00059 $j++;
00060 }
00061
00062
00063 if ($escaped_backslash) {
00064 $string_start = '';
00065 $in_string = FALSE;
00066 break;
00067 }
00068
00069 else {
00070 $i++;
00071 }
00072 }
00073 }
00074 }
00075
00076
00077 else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
00078 $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
00079
00080 if ($i === FALSE) {
00081 break;
00082 }
00083 if ($char == '/') $i++;
00084 }
00085
00086
00087 else if ($char == ';') {
00088
00089 $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
00090 $nothing = TRUE;
00091 $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
00092 $sql_len = strlen($sql);
00093 if ($sql_len) {
00094 $i = -1;
00095 } else {
00096
00097 return TRUE;
00098 }
00099 }
00100
00101
00102 else if (($char == '"') || ($char == '\'') || ($char == '`')) {
00103 $in_string = TRUE;
00104 $nothing = FALSE;
00105 $string_start = $char;
00106 }
00107
00108 elseif ($nothing) {
00109 $nothing = FALSE;
00110 }
00111
00112
00113 $time1 = time();
00114 if ($time1 >= $time0 + 30) {
00115 $time0 = $time1;
00116 header('X-pmaPing: Pong');
00117 }
00118 }
00119
00120
00121 if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
00122 $ret[] = array('query' => $sql, 'empty' => $nothing);
00123 }
00124
00125 return TRUE;
00126 }
00127
00128
00140 function PMA_readFile($path, $mime = '') {
00141 global $cfg;
00142
00143 if (!file_exists($path)) {
00144 return FALSE;
00145 }
00146 switch ($mime) {
00147 case '':
00148 $file = @fopen($path, 'rb');
00149 if (!$file) {
00150 return FALSE;
00151 }
00152 $test = fread($file, 3);
00153 fclose($file);
00154 if ($test[0] == chr(31) && $test[1] == chr(139)) return PMA_readFile($path, 'application/x-gzip');
00155 if ($test == 'BZh') return PMA_readFile($path, 'application/x-bzip');
00156 return PMA_readFile($path, 'text/plain');
00157 case 'text/plain':
00158 $file = @fopen($path, 'rb');
00159 if (!$file) {
00160 return FALSE;
00161 }
00162 $content = fread($file, filesize($path));
00163 fclose($file);
00164 break;
00165 case 'application/x-gzip':
00166 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
00167 $file = @gzopen($path, 'rb');
00168 if (!$file) {
00169 return FALSE;
00170 }
00171 $content = '';
00172 while (!gzeof($file)) {
00173 $content .= gzgetc($file);
00174 }
00175 gzclose($file);
00176 } else {
00177 return FALSE;
00178 }
00179 break;
00180 case 'application/x-bzip':
00181 if ($cfg['BZipDump'] && @function_exists('bzdecompress')) {
00182 $file = @fopen($path, 'rb');
00183 if (!$file) {
00184 return FALSE;
00185 }
00186 $content = fread($file, filesize($path));
00187 fclose($file);
00188 $content = bzdecompress($content);
00189 } else {
00190 return FALSE;
00191 }
00192 break;
00193 default:
00194 return FALSE;
00195 }
00196 return $content;
00197 }
00198
00199 ?>