From ef68436ac04da078ffdcacd7e1f785473a303d45 Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Sun, 02 Oct 2011 23:56:18 +0000 Subject: First version of the newly restructured repository --- (limited to 'backend/php/src/setup/data_initialization') diff --git a/backend/php/src/setup/data_initialization/additional_table_structures.sql b/backend/php/src/setup/data_initialization/additional_table_structures.sql new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/additional_table_structures.sql diff --git a/backend/php/src/setup/data_initialization/data_initialization.sql b/backend/php/src/setup/data_initialization/data_initialization.sql new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/data_initialization.sql diff --git a/backend/php/src/setup/data_initialization/howto.txt b/backend/php/src/setup/data_initialization/howto.txt new file mode 100644 index 0000000..a6f0e24 --- a/dev/null +++ b/backend/php/src/setup/data_initialization/howto.txt @@ -0,0 +1,13 @@ +Hello there, + +To make use of the Data Initialization feature in POG Setup, put your insert statements in the data_initialization.sql file. (One per line). +Then, on step 1 of Setup, choose "Drop, recreate tables and reset data": + +This will + +1. Drop any tables that have the same name as the object(s) you have in the objects folder. +2. Recreate the tables and indexes(if needed) +3. Execute the insert statements in data_initialization.sql one by one. + +Regards, +The POG Team \ No newline at end of file diff --git a/backend/php/src/setup/data_initialization/read_dump_lib.php b/backend/php/src/setup/data_initialization/read_dump_lib.php new file mode 100644 index 0000000..ed579ab --- a/dev/null +++ b/backend/php/src/setup/data_initialization/read_dump_lib.php @@ -0,0 +1,205 @@ + add the current substring to the + // returned array + if (!$i) { + $ret[] = array('query' => $sql, 'empty' => $nothing); + return TRUE; + } + // Backquotes or no backslashes before quotes: it's indeed the + // end of the string -> exit the loop + elseif ($string_start == '`' || $sql[$i-1] != '\\') { + $string_start = ''; + $in_string = FALSE; + break; + } + // one or more Backslashes before the presumed end of string... + else { + // ... first checks for escaped backslashes + $j = 2; + $escaped_backslash = FALSE; + while ($i-$j > 0 && $sql[$i-$j] == '\\') { + $escaped_backslash = !$escaped_backslash; + $j++; + } + // ... if escaped backslashes: it's really the end of the + // string -> exit the loop + if ($escaped_backslash) { + $string_start = ''; + $in_string = FALSE; + break; + } + // ... else loop + else { + $i++; + } + } // end if...elseif...else + } // end for + } // end if (in string) + + // lets skip comments (/*, -- and #) + elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { + $i = strpos($sql, $char == '/' ? '*/' : "\n", $i); + // didn't we hit end of string? + if ($i === FALSE) { + break; + } + if ($char == '/') { + $i++; + } + } + + // We are not in a string, first check for delimiter... + elseif ($char == ';') { + // if delimiter found, add the parsed part to the returned array + $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); + $nothing = TRUE; + $sql = ltrim(substr($sql, min($i + 1, $sql_len))); + $sql_len = strlen($sql); + if ($sql_len) { + $i = -1; + } else { + // The submited statement(s) end(s) here + return TRUE; + } + } // end elseif (is delimiter) + + // ... then check for start of a string,... + elseif (($char == '"') || ($char == '\'') || ($char == '`')) { + $in_string = TRUE; + $nothing = FALSE; + $string_start = $char; + } // end elseif (is start of string) + + elseif ($nothing) { + $nothing = FALSE; + } + + // loic1: send a fake header each 30 sec. to bypass browser timeout + $time1 = time(); + if ($time1 >= $time0 + 30) { + $time0 = $time1; + header('X-pmaPing: Pong'); + } // end if + } // end for + + // add any rest to the returned array + if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) { + $ret[] = array('query' => $sql, 'empty' => $nothing); + } + + return TRUE; +} // end of the 'PMA_splitSqlFile()' function + + +/** + * Reads (and decompresses) a (compressed) file into a string + * + * @param string the path to the file + * @param string the MIME type of the file, if empty MIME type is autodetected + * + * @global array the phpMyAdmin configuration + * + * @return string the content of the file or + * boolean FALSE in case of an error. + */ +function PMA_readFile($path, $mime = '') { + global $cfg; + + if (!file_exists($path)) { + return FALSE; + } + switch ($mime) { + case '': + $file = @fopen($path, 'rb'); + if (!$file) { + return FALSE; + } + $test = fread($file, 3); + fclose($file); + if ($test[0] == chr(31) && $test[1] == chr(139)) { + return PMA_readFile($path, 'application/x-gzip'); + } + if ($test == 'BZh') { + return PMA_readFile($path, 'application/x-bzip'); + } + return PMA_readFile($path, 'text/plain'); + case 'text/plain': + $file = @fopen($path, 'rb'); + if (!$file) { + return FALSE; + } + $content = fread($file, filesize($path)); + fclose($file); + break; + case 'application/x-gzip': + if ($cfg['GZipDump'] && @function_exists('gzopen')) { + $file = @gzopen($path, 'rb'); + if (!$file) { + return FALSE; + } + $content = ''; + while (!gzeof($file)) { + $content .= gzgetc($file); + } + gzclose($file); + } else { + return FALSE; + } + break; + case 'application/x-bzip': + if ($cfg['BZipDump'] && @function_exists('bzdecompress')) { + $file = @fopen($path, 'rb'); + if (!$file) { + return FALSE; + } + $content = fread($file, filesize($path)); + fclose($file); + $content = bzdecompress($content); + } else { + return FALSE; + } + break; + default: + return FALSE; + } + return $content; +} + +?> -- cgit v0.9.0.2