This commit is contained in:
Marc Delisle
2009-05-18 14:18:53 +00:00
parent 72bd3e8cd6
commit ce7be6d009
689 changed files with 0 additions and 198914 deletions

View File

@@ -1,42 +0,0 @@
This directory holds import plugins for phpMyAdmin. Plugin should
basically look like following code. Official plugins need to have str*
messages with their definition in language files, if you build some
plugins for your use, you can use directly texts in plugin.
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4 ft=php:
/* Demo import plugin for phpMyAdmin */
if (isset($plugin_list)) {
$plugin_list['name'] = array( // set name of your plugin
'text' => 'strName', // text to be displayed as choice
'extension' => '', // extension this plugin can handle
'options' => array( // array of options for your plugin (optional)
array('type' => '', 'name' => '', 'text' => ''), // type: bool or text, name: form element name, text: description in GUI, size: size of text element (optional). len: maximal size of input (optional)
),
'options_text' => 'strNameImportOptions', // text to describe plugin options (must be set if options are used)
);
} else {
/* We do not define function when plugin is just queried for information above */
$buffer = '';
while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing
$offset -= strlen($buffer);
break;
} elseif ($data === TRUE) {
// Handle rest of buffer
} else {
// Append new data to buffer
$buffer .= $data;
}
// PARSE $buffer here, post sql queries using:
PMA_importRunQuery($sql, $verbose_sql_with_comments);
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery();
}
?>

View File

@@ -1,325 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* CSV import plugin for phpMyAdmin
*
* @todo add an option for handling NULL values
* @version $Id$
* @package phpMyAdmin-Import
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
*
*/
if ($plugin_param !== 'table') {
return;
}
if (isset($plugin_list)) {
$plugin_list['csv'] = array(
'text' => 'strCSV',
'extension' => 'csv',
'options' => array(
array('type' => 'bool', 'name' => 'replace', 'text' => 'strReplaceTable'),
array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'),
array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2),
array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'),
),
'options_text' => 'strOptions',
);
/* We do not define function when plugin is just queried for information above */
return;
}
$replacements = array(
'\\n' => "\n",
'\\t' => "\t",
'\\r' => "\r",
);
$csv_terminated = strtr($csv_terminated, $replacements);
$csv_enclosed = strtr($csv_enclosed, $replacements);
$csv_escaped = strtr($csv_escaped, $replacements);
$csv_new_line = strtr($csv_new_line, $replacements);
if (strlen($csv_terminated) != 1) {
$message = PMA_Message::error('strInvalidCSVParameter');
$message->addParam('strFieldsTerminatedBy', false);
$error = TRUE;
// The default dialog of MS Excel when generating a CSV produces a
// semi-colon-separated file with no chance of specifying the
// enclosing character. Thus, users who want to import this file
// tend to remove the enclosing character on the Import dialog.
// I could not find a test case where having no enclosing characters
// confuses this script.
// But the parser won't work correctly with strings so we allow just
// one character.
} elseif (strlen($csv_enclosed) > 1) {
$message = PMA_Message::error('strInvalidCSVParameter');
$message->addParam('strFieldsEnclosedBy', false);
$error = TRUE;
} elseif (strlen($csv_escaped) != 1) {
$message = PMA_Message::error('strInvalidCSVParameter');
$message->addParam('strFieldsEscapedBy', false);
$error = TRUE;
} elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') {
$message = PMA_Message::error('strInvalidCSVParameter');
$message->addParam('strLinesTerminatedBy', false);
$error = TRUE;
}
$buffer = '';
if (isset($csv_replace)) {
$sql_template = 'REPLACE';
} else {
$sql_template = 'INSERT';
if (isset($csv_ignore)) {
$sql_template .= ' IGNORE';
}
}
$sql_template .= ' INTO ' . PMA_backquote($table);
$tmp_fields = PMA_DBI_get_fields($db, $table);
if (empty($csv_columns)) {
$fields = $tmp_fields;
} else {
$sql_template .= ' (';
$fields = array();
$tmp = split(',( ?)', $csv_columns);
foreach ($tmp as $key => $val) {
if (count($fields) > 0) {
$sql_template .= ', ';
}
/* Trim also `, if user already included backquoted fields */
$val = trim($val, " \t\r\n\0\x0B`");
$found = FALSE;
foreach ($tmp_fields as $id => $field) {
if ($field['Field'] == $val) {
$found = TRUE;
break;
}
}
if (!$found) {
$message = PMA_Message::error('strInvalidColumn');
$message->addParam($val);
$error = TRUE;
break;
}
$fields[] = $field;
$sql_template .= PMA_backquote($val);
}
$sql_template .= ') ';
}
$required_fields = count($fields);
$sql_template .= ' VALUES (';
// Defaults for parser
$i = 0;
$len = 0;
$line = 1;
$lasti = -1;
$values = array();
$csv_finish = FALSE;
while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing
$offset -= strlen($buffer);
break;
} elseif ($data === TRUE) {
// Handle rest of buffer
} else {
// Append new data to buffer
$buffer .= $data;
unset($data);
// Do not parse string when we're not at the end and don't have new line inside
if (($csv_new_line == 'auto' && strpos($buffer, "\r") === FALSE && strpos($buffer, "\n") === FALSE)
|| ($csv_new_line != 'auto' && strpos($buffer, $csv_new_line) === FALSE)) {
continue;
}
}
// Current length of our buffer
$len = strlen($buffer);
// Currently parsed char
$ch = $buffer[$i];
while ($i < $len) {
// Deadlock protection
if ($lasti == $i && $lastlen == $len) {
$message = PMA_Message::error('strInvalidCSVFormat');
$message->addParam($line);
$error = TRUE;
break;
}
$lasti = $i;
$lastlen = $len;
// This can happen with auto EOL and \r at the end of buffer
if (!$csv_finish) {
// Grab empty field
if ($ch == $csv_terminated) {
if ($i == $len - 1) {
break;
}
$values[] = '';
$i++;
$ch = $buffer[$i];
continue;
}
// Grab one field
$fallbacki = $i;
if ($ch == $csv_enclosed) {
if ($i == $len - 1) {
break;
}
$need_end = TRUE;
$i++;
$ch = $buffer[$i];
} else {
$need_end = FALSE;
}
$fail = FALSE;
$value = '';
while (($need_end && $ch != $csv_enclosed)
|| (!$need_end && !($ch == $csv_terminated
|| $ch == $csv_new_line || ($csv_new_line == 'auto'
&& ($ch == "\r" || $ch == "\n"))))) {
if ($ch == $csv_escaped) {
if ($i == $len - 1) {
$fail = TRUE;
break;
}
$i++;
$ch = $buffer[$i];
}
$value .= $ch;
if ($i == $len - 1) {
if (!$finished) {
$fail = TRUE;
}
break;
}
$i++;
$ch = $buffer[$i];
}
// unquoted NULL string
if (false === $need_end && $value === 'NULL') {
$value = null;
}
if ($fail) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
}
// Need to strip trailing enclosing char?
if ($need_end && $ch == $csv_enclosed) {
if ($finished && $i == $len - 1) {
$ch = NULL;
} elseif ($i == $len - 1) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
} else {
$i++;
$ch = $buffer[$i];
}
}
// Are we at the end?
if ($ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n")) || ($finished && $i == $len - 1)) {
$csv_finish = TRUE;
}
// Go to next char
if ($ch == $csv_terminated) {
if ($i == $len - 1) {
$i = $fallbacki;
$ch = $buffer[$i];
break;
}
$i++;
$ch = $buffer[$i];
}
// If everything went okay, store value
$values[] = $value;
}
// End of line
if ($csv_finish || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))) {
if ($csv_new_line == 'auto' && $ch == "\r") { // Handle "\r\n"
if ($i >= ($len - 2) && !$finished) {
break; // We need more data to decide new line
}
if ($buffer[$i + 1] == "\n") {
$i++;
}
}
// We didn't parse value till the end of line, so there was empty one
if (!$csv_finish) {
$values[] = '';
}
// Do we have correct count of values?
if (count($values) != $required_fields) {
// Hack for excel
if ($values[count($values) - 1] == ';') {
unset($values[count($values) - 1]);
} else {
$message = PMA_Message::error('strInvalidCSVFieldCount');
$message->addParam($line);
$error = TRUE;
break;
}
}
$first = TRUE;
$sql = $sql_template;
foreach ($values as $key => $val) {
if (!$first) {
$sql .= ', ';
}
if ($val === null) {
$sql .= 'NULL';
} else {
$sql .= '\'' . addslashes($val) . '\'';
}
$first = FALSE;
}
$sql .= ')';
/**
* @todo maybe we could add original line to verbose SQL in comment
*/
PMA_importRunQuery($sql, $sql);
$line++;
$csv_finish = FALSE;
$values = array();
$buffer = substr($buffer, $i + 1);
$len = strlen($buffer);
$i = 0;
$lasti = -1;
$ch = $buffer[0];
}
} // End of parser loop
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery();
if (count($values) != 0 && !$error) {
$message = PMA_Message::error('$strInvalidCSVFormat');
$message->addParam($line);
$error = TRUE;
}
?>

View File

@@ -1,95 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* DocSQL import plugin for phpMyAdmin
*
* @version $Id$
* @package phpMyAdmin-Import
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Load relations.
*/
require_once './libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam();
/**
* We need relations enabled and we work only on database
*/
if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
|| ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']) {
return;
}
if (isset($plugin_list)) {
$plugin_list['docsql'] = array( // set name of your plugin
'text' => 'strDocSQL', // text to be displayed as choice
'extension' => '', // extension this plugin can handle
'options' => array( // array of options for your plugin (optional)
array('type' => 'text', 'name' => 'table', 'text' => 'strTableName'),
),
'options_text' => 'strOptions', // text to describe plugin options (must be set if options are used)
);
/* We do not define function when plugin is just queried for information above */
return;
}
$tab = $_POST['docsql_table'];
$buffer = '';
/* Read whole buffer, we except it is small enough */
while (!$finished && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing
break;
} elseif ($data === TRUE) {
// nothing to read
break;
} else {
// Append new data to buffer
$buffer .= $data;
}
} // End of import loop
/* Process the data */
if ($data === TRUE && !$error && !$timeout_passed) {
$buffer = str_replace("\r\n", "\n", $buffer);
$buffer = str_replace("\r", "\n", $buffer);
$lines = explode("\n", $buffer);
foreach ($lines AS $lkey => $line) {
//echo '<p>' . $line . '</p>';
$inf = explode('|', $line);
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
$qry = '
INSERT INTO
' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
(db_name, table_name, column_name, ' . PMA_backquote('comment') . ')
VALUES (
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
\'' . PMA_sqlAddslashes(trim($tab)) . '\',
\'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]), true);
} // end inf[1] exists
if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
$for = explode('->', $inf[2]);
$qry = '
INSERT INTO
' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
VALUES (
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
\'' . PMA_sqlAddslashes(trim($tab)) . '\',
\'' . PMA_sqlAddslashes(trim($inf[0])) . '\',
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
\'' . PMA_sqlAddslashes(trim($for[0])) . '\',
\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
} // end inf[2] exists
} // End lines loop
} // End import
// Commit any possible data in buffers
PMA_importRunQuery();
?>

View File

@@ -1,108 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* CSV import plugin for phpMyAdmin
*
* @version $Id$
* @package phpMyAdmin-Import
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
*
*/
if ($plugin_param !== 'table') {
return;
}
if (isset($plugin_list)) {
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
$GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE;
$result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
if ($result != FALSE && PMA_DBI_num_rows($result) > 0) {
$tmp = PMA_DBI_fetch_row($result);
if ($tmp[1] == 'ON') {
$GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE;
}
}
PMA_DBI_free_result($result);
unset($result);
}
$plugin_list['ldi'] = array(
'text' => 'strLDI',
'extension' => 'ldi', // This is nonsense, however we want to default to our parser for csv
'options' => array(
array('type' => 'bool', 'name' => 'replace', 'text' => 'strReplaceTable'),
array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'),
array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 2),
array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2),
array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'),
array('type' => 'bool', 'name' => 'local_option', 'text' => 'strLDILocal'),
),
'options_text' => 'strOptions',
);
/* We do not define function when plugin is just queried for information above */
return;
}
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
// We handle only some kind of data!
$message = PMA_Message::error('strInvalidLDIImport');
$error = TRUE;
return;
}
$sql = 'LOAD DATA';
if (isset($ldi_local_option)) {
$sql .= ' LOCAL';
}
$sql .= ' INFILE \'' . PMA_sqlAddslashes($import_file) . '\'';
if (isset($ldi_replace)) {
$sql .= ' REPLACE';
} elseif (isset($ldi_ignore)) {
$sql .= ' IGNORE';
}
$sql .= ' INTO TABLE ' . PMA_backquote($table);
if (strlen($ldi_terminated) > 0) {
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
}
if (strlen($ldi_enclosed) > 0) {
$sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\'';
}
if (strlen($ldi_escaped) > 0) {
$sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\'';
}
if (strlen($ldi_new_line) > 0){
if ($ldi_new_line == 'auto') {
$ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
}
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
}
if ($skip_queries > 0) {
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
$skip_queries = 0;
}
if (strlen($ldi_columns) > 0) {
$sql .= ' (';
$tmp = split(',( ?)', $ldi_columns);
$cnt_tmp = count($tmp);
for ($i = 0; $i < $cnt_tmp; $i++) {
if ($i > 0) {
$sql .= ', ';
}
/* Trim also `, if user already included backquoted fields */
$sql .= PMA_backquote(trim($tmp[$i], " \t\r\n\0\x0B`"));
} // end for
$sql .= ')';
}
PMA_importRunQuery($sql, $sql);
PMA_importRunQuery();
$finished = TRUE;
?>

View File

@@ -1,307 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* SQL import plugin for phpMyAdmin
*
* @version $Id$
* @package phpMyAdmin-Import
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
*
*/
if (isset($plugin_list)) {
$plugin_list['sql'] = array(
'text' => 'strSQL',
'extension' => 'sql',
'options_text' => 'strOptions',
);
$compats = PMA_DBI_getCompatibilities();
if (count($compats) > 0) {
$values = array();
foreach($compats as $val) {
$values[$val] = $val;
}
$plugin_list['sql']['options'] = array(
array(
'type' => 'select',
'name' => 'compatibility',
'text' => 'strSQLCompatibility',
'values' => $values,
'doc' => array(
'manual_MySQL_Database_Administration',
'Server_SQL_mode',
),
),
array(
'type' => 'bool',
'name' => 'no_auto_value_on_zero',
'text' => 'strDoNotAutoIncrementZeroValues',
'doc' => array(
'manual_MySQL_Database_Administration',
'Server_SQL_mode',
'sqlmode_no_auto_value_on_zero'
),
),
);
}
/* We do not define function when plugin is just queried for information above */
return;
}
$buffer = '';
// Defaults for parser
$sql = '';
$start_pos = 0;
$i = 0;
$len= 0;
$big_value = 2147483647;
if (isset($_POST['sql_delimiter'])) {
$sql_delimiter = $_POST['sql_delimiter'];
} else {
$sql_delimiter = ';';
}
// Handle compatibility options
$sql_modes = array();
if (isset($_REQUEST['sql_compatibility']) && 'NONE' != $_REQUEST['sql_compatibility']) {
$sql_modes[] = $_REQUEST['sql_compatibility'];
}
if (isset($_REQUEST['sql_no_auto_value_on_zero'])) {
$sql_modes[] = 'NO_AUTO_VALUE_ON_ZERO';
}
if (count($sql_modes) > 0) {
PMA_DBI_try_query('SET SQL_MODE="' . implode(',', $sql_modes) . '"');
}
unset($sql_modes);
/**
* will be set in PMA_importGetNextChunk()
*
* @global boolean $GLOBALS['finished']
*/
$GLOBALS['finished'] = false;
while (!($GLOBALS['finished'] && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing
$offset -= strlen($buffer);
break;
} elseif ($data === TRUE) {
// Handle rest of buffer
} else {
// Append new data to buffer
$buffer .= $data;
// free memory
unset($data);
// Do not parse string when we're not at the end and don't have ; inside
if ((strpos($buffer, $sql_delimiter, $i) === FALSE) && !$GLOBALS['finished']) {
continue;
}
}
// Current length of our buffer
$len = strlen($buffer);
// Grab some SQL queries out of it
while ($i < $len) {
$found_delimiter = false;
// Find first interesting character
$old_i = $i;
// this is about 7 times faster that looking for each sequence i
// one by one with strpos()
if (preg_match('/(\'|"|#|-- |\/\*|`|(?i)DELIMITER)/', $buffer, $matches, PREG_OFFSET_CAPTURE, $i)) {
// in $matches, index 0 contains the match for the complete
// expression but we don't use it
$first_position = $matches[1][1];
} else {
$first_position = $big_value;
}
/**
* @todo we should not look for a delimiter that might be
* inside quotes (or even double-quotes)
*/
// the cost of doing this one with preg_match() would be too high
$first_sql_delimiter = strpos($buffer, $sql_delimiter, $i);
if ($first_sql_delimiter === FALSE) {
$first_sql_delimiter = $big_value;
} else {
$found_delimiter = true;
}
// set $i to the position of the first quote, comment.start or delimiter found
$i = min($first_position, $first_sql_delimiter);
if ($i == $big_value) {
// none of the above was found in the string
$i = $old_i;
if (!$GLOBALS['finished']) {
break;
}
// at the end there might be some whitespace...
if (trim($buffer) == '') {
$buffer = '';
$len = 0;
break;
}
// We hit end of query, go there!
$i = strlen($buffer) - 1;
}
// Grab current character
$ch = $buffer[$i];
// Quotes
if (strpos('\'"`', $ch) !== FALSE) {
$quote = $ch;
$endq = FALSE;
while (!$endq) {
// Find next quote
$pos = strpos($buffer, $quote, $i + 1);
// No quote? Too short string
if ($pos === FALSE) {
// We hit end of string => unclosed quote, but we handle it as end of query
if ($GLOBALS['finished']) {
$endq = TRUE;
$i = $len - 1;
}
$found_delimiter = false;
break;
}
// Was not the quote escaped?
$j = $pos - 1;
while ($buffer[$j] == '\\') $j--;
// Even count means it was not escaped
$endq = (((($pos - 1) - $j) % 2) == 0);
// Skip the string
$i = $pos;
if ($first_sql_delimiter < $pos) {
$found_delimiter = false;
}
}
if (!$endq) {
break;
}
$i++;
// Aren't we at the end?
if ($GLOBALS['finished'] && $i == $len) {
$i--;
} else {
continue;
}
}
// Not enough data to decide
if ((($i == ($len - 1) && ($ch == '-' || $ch == '/'))
|| ($i == ($len - 2) && (($ch == '-' && $buffer[$i + 1] == '-')
|| ($ch == '/' && $buffer[$i + 1] == '*')))) && !$GLOBALS['finished']) {
break;
}
// Comments
if ($ch == '#'
|| ($i < ($len - 1) && $ch == '-' && $buffer[$i + 1] == '-'
&& (($i < ($len - 2) && $buffer[$i + 2] <= ' ')
|| ($i == ($len - 1) && $GLOBALS['finished'])))
|| ($i < ($len - 1) && $ch == '/' && $buffer[$i + 1] == '*')
) {
// Copy current string to SQL
if ($start_pos != $i) {
$sql .= substr($buffer, $start_pos, $i - $start_pos);
}
// Skip the rest
$j = $i;
$i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i);
// didn't we hit end of string?
if ($i === FALSE) {
if ($GLOBALS['finished']) {
$i = $len - 1;
} else {
break;
}
}
// Skip *
if ($ch == '/') {
// Check for MySQL conditional comments and include them as-is
if ($buffer[$j + 2] == '!') {
$comment = substr($buffer, $j + 3, $i - $j - 3);
if (preg_match('/^[0-9]{5}/', $comment, $version)) {
if ($version[0] <= PMA_MYSQL_INT_VERSION) {
$sql .= substr($comment, 5);
}
} else {
$sql .= $comment;
}
}
$i++;
}
// Skip last char
$i++;
// Next query part will start here
$start_pos = $i;
// Aren't we at the end?
if ($i == $len) {
$i--;
} else {
continue;
}
}
// Change delimiter, if redefined, and skip it (don't send to server!)
if (strtoupper(substr($buffer, $i, 9)) == "DELIMITER"
&& ($buffer[$i + 9] <= ' ')
&& ($i < $len - 11)
&& strpos($buffer, "\n", $i + 11) !== FALSE) {
$new_line_pos = strpos($buffer, "\n", $i + 10);
$sql_delimiter = substr($buffer, $i + 10, $new_line_pos - $i - 10);
$i = $new_line_pos + 1;
// Next query part will start here
$start_pos = $i;
continue;
}
// End of SQL
if ($found_delimiter || ($GLOBALS['finished'] && ($i == $len - 1))) {
$tmp_sql = $sql;
if ($start_pos < $len) {
$length_to_grab = $i - $start_pos;
if (! $found_delimiter) {
$length_to_grab++;
}
$tmp_sql .= substr($buffer, $start_pos, $length_to_grab);
unset($length_to_grab);
}
// Do not try to execute empty SQL
if (! preg_match('/^([\s]*;)*$/', trim($tmp_sql))) {
$sql = $tmp_sql;
PMA_importRunQuery($sql, substr($buffer, 0, $i + strlen($sql_delimiter)));
$buffer = substr($buffer, $i + strlen($sql_delimiter));
// Reset parser:
$len = strlen($buffer);
$sql = '';
$i = 0;
$start_pos = 0;
// Any chance we will get a complete query?
//if ((strpos($buffer, ';') === FALSE) && !$GLOBALS['finished']) {
if ((strpos($buffer, $sql_delimiter) === FALSE) && !$GLOBALS['finished']) {
break;
}
} else {
$i++;
$start_pos = $i;
}
}
} // End of parser loop
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery('', substr($buffer, 0, $len));
PMA_importRunQuery();
?>