Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jul 24, 2012
2 parents f781e3f + 4c5d5f6 commit b239f94
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 129 deletions.
6 changes: 5 additions & 1 deletion import.php
Expand Up @@ -430,6 +430,10 @@
unset($skip);
}

// This array contain the data like numberof valid sql queries in the statement
// and complete valid sql statement (which affected for rows)
$sql_data = array('valid_sql' => array(), 'valid_queries' => 0);

if (! $error) {
// Check for file existance
require_once("libraries/plugin_interface.lib.php");
Expand All @@ -445,7 +449,7 @@
);
} else {
// Do the real import
$import_plugin->doImport();
$import_plugin->doImport($sql_data);
}
}

Expand Down
25 changes: 14 additions & 11 deletions libraries/DisplayResults.class.php
Expand Up @@ -940,7 +940,7 @@ private function _getAdditionalFieldsForTableNavigation(
private function _getTableHeaders(
&$is_display, $analyzed_sql = '',
$sort_expression = '', $sort_expression_nodirection = '',
$sort_direction = ''
$sort_direction = '', $is_limited_display = false
) {

$table_headers_html = '';
Expand Down Expand Up @@ -1002,7 +1002,7 @@ private function _getTableHeaders(
$this->__set('_vertical_display', $vertical_display);

// Display options (if we are not in print view)
if (! (isset($printview) && ($printview == '1'))) {
if (! (isset($printview) && ($printview == '1')) && ! $is_limited_display) {

$table_headers_html .= $this->_getOptionsBlock();

Expand Down Expand Up @@ -2422,8 +2422,9 @@ private function _addClass(
*
* @see getTable()
*/
private function _getTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
{
private function _getTableBody(
&$dt_result, &$is_display, $map, $analyzed_sql, $is_limited_display = false
) {

global $row; // mostly because of browser transformations,
// to make the row-data accessible in a plugin
Expand All @@ -2447,8 +2448,9 @@ private function _getTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
$vertical_display['data'] = array();
$vertical_display['row_delete'] = array();
$this->__set('_vertical_display', $vertical_display);

// name of the class added to all grid editable elements
$grid_edit_class = 'grid_edit';
$grid_edit_class = $is_limited_display ? '' : 'grid_edit';

// prepare to get the column order, if available
list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql);
Expand Down Expand Up @@ -4246,9 +4248,10 @@ public function setConfigParamsForDisplayTable()
*
* @see sql.php file
*/
public function getTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
{

public function getTable(
&$dt_result, &$the_disp_mode, $analyzed_sql, $is_limited_display = false
) {

$table_html = '';
// Following variable are needed for use in isset/empty or
// use with array indexes/safe use in foreach
Expand Down Expand Up @@ -4394,13 +4397,13 @@ public function getTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
// 3. ----- Prepare the results table -----
$table_html .= $this->_getTableHeaders(
$is_display, $analyzed_sql, $sort_expression,
$sort_expression_nodirection, $sort_direction
$sort_expression_nodirection, $sort_direction, $is_limited_display
)
. '<tbody>' . "\n";

$url_query = '';
$table_html .= $this->_getTableBody(
$dt_result, $is_display, $map, $analyzed_sql
$dt_result, $is_display, $map, $analyzed_sql, $is_limited_display
);

// vertical output case
Expand Down Expand Up @@ -4439,7 +4442,7 @@ public function getTable(&$dt_result, &$the_disp_mode, $analyzed_sql)


// 6. ----- Prepare "Query results operations"
if (! isset($printview) || ($printview != '1')) {
if ((! isset($printview) || ($printview != '1')) && ! $is_limited_display) {
$table_html .= $this->_getResultsOperations(
$the_disp_mode, $analyzed_sql
);
Expand Down
23 changes: 23 additions & 0 deletions libraries/database_interface.lib.php
Expand Up @@ -177,6 +177,29 @@ function PMA_DBI_try_query($query, $link = null, $options = 0,
return $r;
}

/**
* Run multi query statement and return results
*
* @param string $multi_query multi query statement to execute
* @param mysqli $link mysqli object
*
* @return mysqli_result collection | boolean(false)
*/
function PMA_DBI_try_multi_query($multi_query = '', $link = null)
{

if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return false;
}
}

return PMA_DBI_real_multi_query($link, $multi_query);

}

/**
* converts charset of a mysql message, usually coming from mysql_error(),
* into PMA charset, usally UTF-8
Expand Down
18 changes: 18 additions & 0 deletions libraries/dbi/mysql.dbi.lib.php
Expand Up @@ -53,6 +53,24 @@ function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persist
return $link;
}

/**
* Run the multi query and output the results
*
* @param mysqli $link mysqli object
* @param string $query multi query statement to execute
*
* @return boolean false always false since mysql extention not support
* for multi query executions
*/
function PMA_DBI_real_multi_query($link, $query)
{
// N.B.: PHP's 'mysql' extension does not support
// multi_queries so this function will always
// return false. Use the 'mysqli' extension, if
// you need support for multi_queries.
return false;
}

/**
* connects to the database server
*
Expand Down
30 changes: 30 additions & 0 deletions libraries/dbi/mysqli.dbi.lib.php
Expand Up @@ -253,6 +253,19 @@ function PMA_DBI_real_query($query, $link, $options)
return mysqli_query($link, $query, $method);
}

/**
* Run the multi query and output the results
*
* @param mysqli $link mysqli object
* @param string $query multi query statement to execute
*
* @return mysqli_result collection | boolean(false)
*/
function PMA_DBI_real_multi_query($link, $query)
{
return mysqli_multi_query($link, $query);
}

/**
* returns array of rows with associative and numeric keys from $result
*
Expand Down Expand Up @@ -354,6 +367,23 @@ function PMA_DBI_next_result($link = null)
return mysqli_next_result($link);
}

/**
* Store the result returned from multi query
*
* @return mixed false when empty results / result set when not empty
*/
function PMA_DBI_store_result()
{
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return false;
}
}
return mysqli_store_result($link);
}

/**
* Returns a string representing the type of connection used
*
Expand Down
23 changes: 22 additions & 1 deletion libraries/import.lib.php
Expand Up @@ -81,7 +81,7 @@ function PMA_detectCompression($filepath)
* @return void
* @access public
*/
function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
function PMA_importRunQuery($sql = '', $full = '', $controluser = false, &$sql_data = array())
{
global $import_run_buffer, $go_sql, $complete_query, $display_query,
$sql_query, $my_die, $error, $reload,
Expand All @@ -97,6 +97,14 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
if (! empty($import_run_buffer['sql'])
&& trim($import_run_buffer['sql']) != ''
) {

// USE query changes the database, son need to track
// while running multiple queries
$is_use_query
= (stripos($import_run_buffer['sql'], "use ") !== false)
? true
: false;

$max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql']));
if (! $sql_query_disabled) {
$sql_query .= $import_run_buffer['full'];
Expand All @@ -108,7 +116,9 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
$GLOBALS['message'] = PMA_Message::error(__('"DROP DATABASE" statements are disabled.'));
$error = true;
} else {

$executed_queries++;

if ($run_query
&& $GLOBALS['finished']
&& empty($sql)
Expand All @@ -126,6 +136,9 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
$display_query = '';
}
$sql_query = $import_run_buffer['sql'];
$sql_data['valid_sql'][] = $import_run_buffer['sql'];
$sql_data['valid_queries']++;

// If a 'USE <db>' SQL-clause was found,
// set our current $db to the new one
list($db, $reload) = PMA_lookForUse(
Expand All @@ -134,13 +147,15 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
$reload
);
} elseif ($run_query) {

if ($controluser) {
$result = PMA_queryAsControlUser(
$import_run_buffer['sql']
);
} else {
$result = PMA_DBI_try_query($import_run_buffer['sql']);
}

$msg = '# ';
if ($result === false) { // execution failed
if (! isset($my_die)) {
Expand Down Expand Up @@ -169,6 +184,12 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
} else {
$msg .= __('MySQL returned an empty result set (i.e. zero rows).');
}

if (($a_num_rows > 0) || $is_use_query) {
$sql_data['valid_sql'][] = $import_run_buffer['sql'];
$sql_data['valid_queries']++;
}

}
if (! $sql_query_disabled) {
$sql_query .= $msg . "\n";
Expand Down
12 changes: 8 additions & 4 deletions libraries/plugins/import/ImportSql.class.php
Expand Up @@ -93,10 +93,12 @@ public function update (SplSubject $subject)

/**
* Handles the whole import logic
*
* @param &$sql_data array 2-element array with sql data
*
* @return void
*/
public function doImport()
public function doImport(&$sql_data = array())
{
global $error, $timeout_passed;

Expand Down Expand Up @@ -384,7 +386,9 @@ public function doImport()
$sql = $tmp_sql;
PMA_importRunQuery(
$sql,
substr($buffer, 0, $i + strlen($sql_delimiter))
substr($buffer, 0, $i + strlen($sql_delimiter)),
false,
$sql_data
);
$buffer = substr($buffer, $i + strlen($sql_delimiter));
// Reset parser:
Expand All @@ -408,7 +412,7 @@ public function doImport()
} // End of parser loop
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery('', substr($buffer, 0, $len));
PMA_importRunQuery();
PMA_importRunQuery('', substr($buffer, 0, $len), false, $sql_data);
PMA_importRunQuery('', '', false, $sql_data);
}
}

0 comments on commit b239f94

Please sign in to comment.