Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tyron Madlener 2011-06-06 14:41:44 +02:00
commit cbc5a582b6
4 changed files with 74 additions and 126 deletions

View File

@ -75,6 +75,70 @@ function PMA_DBI_query($query, $link = null, $options = 0, $cache_affected_rows
return $res;
}
/**
* runs a query and returns the result
*
* @param string $query query to run
* @param resource $link mysql link resource
* @param integer $options
* @return mixed
*/
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
{
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return false;
}
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true);
}
$r = PMA_DBI_real_query($query, $link, $options);
if ($cache_affected_rows) {
$GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false);
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true) - $time;
$hash = md5($query);
if (isset($_SESSION['debug']['queries'][$hash])) {
$_SESSION['debug']['queries'][$hash]['count']++;
} else {
$_SESSION['debug']['queries'][$hash] = array();
$_SESSION['debug']['queries'][$hash]['count'] = 1;
$_SESSION['debug']['queries'][$hash]['query'] = $query;
$_SESSION['debug']['queries'][$hash]['time'] = $time;
}
$trace = array();
foreach (debug_backtrace() as $trace_step) {
$trace[] = PMA_Error::relPath($trace_step['file']) . '#'
. $trace_step['line'] . ': '
. (isset($trace_step['class']) ? $trace_step['class'] : '')
//. (isset($trace_step['object']) ? get_class($trace_step['object']) : '')
. (isset($trace_step['type']) ? $trace_step['type'] : '')
. (isset($trace_step['function']) ? $trace_step['function'] : '')
. '('
. (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '')
. ')'
;
}
$_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
}
if ($r != false && PMA_Tracker::isActive() == true ) {
PMA_Tracker::handleQuery($query);
}
return $r;
}
/**
* converts charset of a mysql message, usually coming from mysql_error(),
* into PMA charset, usally UTF-8

View File

@ -154,65 +154,15 @@ function PMA_DBI_select_db($dbname, $link = null)
* @param integer $options
* @return mixed
*/
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
function PMA_DBI_real_query($query, $link, $options)
{
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return false;
}
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true);
}
if ($options == ($options | PMA_DBI_QUERY_STORE)) {
$r = mysql_query($query, $link);
return mysql_query($query, $link);
} elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) {
$r = mysql_unbuffered_query($query, $link);
return mysql_unbuffered_query($query, $link);
} else {
$r = mysql_query($query, $link);
return mysql_query($query, $link);
}
if ($cache_affected_rows) {
$GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false);
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true) - $time;
$hash = md5($query);
if (isset($_SESSION['debug']['queries'][$hash])) {
$_SESSION['debug']['queries'][$hash]['count']++;
} else {
$_SESSION['debug']['queries'][$hash] = array();
$_SESSION['debug']['queries'][$hash]['count'] = 1;
$_SESSION['debug']['queries'][$hash]['query'] = $query;
$_SESSION['debug']['queries'][$hash]['time'] = $time;
}
$trace = array();
foreach (debug_backtrace() as $trace_step) {
$trace[] = PMA_Error::relPath($trace_step['file']) . '#'
. $trace_step['line'] . ': '
. (isset($trace_step['class']) ? $trace_step['class'] : '')
//. (isset($trace_step['object']) ? get_class($trace_step['object']) : '')
. (isset($trace_step['type']) ? $trace_step['type'] : '')
. (isset($trace_step['function']) ? $trace_step['function'] : '')
. '('
. (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '')
. ')'
;
}
$_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
}
if ($r != false && PMA_Tracker::isActive() == true ) {
PMA_Tracker::handleQuery($query);
}
return $r;
}
function PMA_DBI_fetch_array($result)
@ -406,7 +356,7 @@ function PMA_DBI_insert_id($link = null)
* @uses $GLOBALS['userlink']
* @uses mysql_affected_rows()
* @param object mysql $link the mysql object
* @param boolean $get_from_cache
* @param boolean $get_from_cache
* @return string integer
*/
function PMA_DBI_affected_rows($link = null, $get_from_cache = true)

View File

@ -164,18 +164,15 @@ function PMA_DBI_select_db($dbname, $link = null)
*
* @uses PMA_DBI_QUERY_STORE
* @uses PMA_DBI_QUERY_UNBUFFERED
* @uses $GLOBALS['userlink']
* @uses MYSQLI_STORE_RESULT
* @uses MYSQLI_USE_RESULT
* @uses mysqli_query()
* @uses defined()
* @param string $query query to execute
* @param object mysqli $link mysqli object
* @param integer $options
* @param boolean $cache_affected_rows
* @return mixed true, false or result object
*/
function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_rows = true)
function PMA_DBI_real_query($query, $link, $options)
{
if ($options == ($options | PMA_DBI_QUERY_STORE)) {
$method = MYSQLI_STORE_RESULT;
@ -185,64 +182,7 @@ function PMA_DBI_try_query($query, $link = null, $options = 0, $cache_affected_r
$method = 0;
}
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
} else {
return false;
}
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true);
}
$r = mysqli_query($link, $query, $method);
if ($cache_affected_rows) {
$GLOBALS['cached_affected_rows'] = PMA_DBI_affected_rows($link, $get_from_cache = false);
}
if ($GLOBALS['cfg']['DBG']['sql']) {
$time = microtime(true) - $time;
$hash = md5($query);
if (isset($_SESSION['debug']['queries'][$hash])) {
$_SESSION['debug']['queries'][$hash]['count']++;
} else {
$_SESSION['debug']['queries'][$hash] = array();
$_SESSION['debug']['queries'][$hash]['count'] = 1;
$_SESSION['debug']['queries'][$hash]['query'] = $query;
$_SESSION['debug']['queries'][$hash]['time'] = $time;
}
$trace = array();
foreach (debug_backtrace() as $trace_step) {
$trace[] = PMA_Error::relPath($trace_step['file']) . '#'
. $trace_step['line'] . ': '
. (isset($trace_step['class']) ? $trace_step['class'] : '')
//. (isset($trace_step['object']) ? get_class($trace_step['object']) : '')
. (isset($trace_step['type']) ? $trace_step['type'] : '')
. (isset($trace_step['function']) ? $trace_step['function'] : '')
. '('
. (isset($trace_step['params']) ? implode(', ', $trace_step['params']) : '')
. ')'
;
}
$_SESSION['debug']['queries'][$hash]['trace'][] = $trace;
}
if ($r != false && PMA_Tracker::isActive() == true ) {
PMA_Tracker::handleQuery($query);
}
return $r;
// From the PHP manual:
// "note: returns true on success or false on failure. For SELECT,
// SHOW, DESCRIBE or EXPLAIN, mysqli_query() will return a result object"
// so, do not use the return value to feed mysqli_num_rows() if it's
// a boolean
return mysqli_query($link, $query, $method);
}
/**
@ -452,9 +392,9 @@ function PMA_DBI_insert_id($link = '')
return false;
}
}
// When no controluser is defined, using mysqli_insert_id($link)
// When no controluser is defined, using mysqli_insert_id($link)
// does not always return the last insert id due to a mixup with
// the tracking mechanism, but this works:
// the tracking mechanism, but this works:
return PMA_DBI_fetch_value('SELECT LAST_INSERT_ID();', 0, 0, $link);
// Curiously, this problem does not happen with the mysql extension but
// there is another problem with BIGINT primary keys so PMA_DBI_insert_id()
@ -467,7 +407,7 @@ function PMA_DBI_insert_id($link = '')
* @uses $GLOBALS['userlink']
* @uses mysqli_affected_rows()
* @param object mysqli $link the mysqli object
* @param boolean $get_from_cache
* @param boolean $get_from_cache
* @return string integer
*/
function PMA_DBI_affected_rows($link = null, $get_from_cache = true)

View File

@ -681,8 +681,6 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false, $a
{
global $sql_drop_table;
global $sql_backquotes;
global $cfgRelation;
global $sql_constraints;
global $sql_constraints_query; // just the text of the query
global $sql_drop_foreign_keys;
@ -1044,7 +1042,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = false,
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $sql_backquotes;
global $rows_cnt;
global $current_row;
$formatted_table_name = (isset($GLOBALS['sql_backquotes']))
@ -1067,9 +1064,6 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
return true;
}
// it's not a VIEW
$buffer = '';
// analyze the query to get the true column names, not the aliases
// (this fixes an undefined index, also if Complete inserts
// are used, we did not get the true column name in case of aliases)