本文整理汇总了PHP中PMA_Util::formatSql方法的典型用法代码示例。如果您正苦于以下问题:PHP PMA_Util::formatSql方法的具体用法?PHP PMA_Util::formatSql怎么用?PHP PMA_Util::formatSql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMA_Util
的用法示例。
在下文中一共展示了PMA_Util::formatSql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyTransformation
/**
* Does the actual work of each specific transformations plugin.
*
* @param string $buffer text to be transformed
* @param array $options transformation options
* @param string $meta meta information
*
* @return string
*/
public function applyTransformation($buffer, $options = array(), $meta = '')
{
// see PMA_highlightSQL()
$result = PMA_Util::formatSql($buffer);
// Need to clear error state not to break subsequent queries display.
PMA_SQP_resetError();
return $result;
}
示例2: PMA_RTN_handleExecute
/**
* Handles requests for executing a routine
*
* @return void
*/
function PMA_RTN_handleExecute()
{
global $_GET, $_POST, $_REQUEST, $GLOBALS, $db;
/**
* Handle all user requests other than the default of listing routines
*/
if (!empty($_REQUEST['execute_routine']) && !empty($_REQUEST['item_name'])) {
// Build the queries
$routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type'], false);
if ($routine === false) {
$message = __('Error in processing request:') . ' ';
$message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db)));
$message = PMA_message::error($message);
if ($GLOBALS['is_ajax_request']) {
$response = PMA_Response::getInstance();
$response->isSuccess(false);
$response->addJSON('message', $message);
exit;
} else {
echo $message->getDisplay();
unset($_POST);
}
}
$queries = array();
$end_query = array();
$args = array();
$all_functions = $GLOBALS['PMA_Types']->getAllFunctions();
for ($i = 0; $i < $routine['item_num_params']; $i++) {
if (isset($_REQUEST['params'][$routine['item_param_name'][$i]])) {
$value = $_REQUEST['params'][$routine['item_param_name'][$i]];
if (is_array($value)) {
// is SET type
$value = implode(',', $value);
}
$value = PMA_Util::sqlAddSlashes($value);
if (!empty($_REQUEST['funcs'][$routine['item_param_name'][$i]]) && in_array($_REQUEST['funcs'][$routine['item_param_name'][$i]], $all_functions)) {
$queries[] = "SET @p{$i}=" . $_REQUEST['funcs'][$routine['item_param_name'][$i]] . "('{$value}');\n";
} else {
$queries[] = "SET @p{$i}='{$value}';\n";
}
$args[] = "@p{$i}";
} else {
$args[] = "@p{$i}";
}
if ($routine['item_type'] == 'PROCEDURE') {
if ($routine['item_param_dir'][$i] == 'OUT' || $routine['item_param_dir'][$i] == 'INOUT') {
$end_query[] = "@p{$i} AS " . PMA_Util::backquote($routine['item_param_name'][$i]);
}
}
}
if ($routine['item_type'] == 'PROCEDURE') {
$queries[] = "CALL " . PMA_Util::backquote($routine['item_name']) . "(" . implode(', ', $args) . ");\n";
if (count($end_query)) {
$queries[] = "SELECT " . implode(', ', $end_query) . ";\n";
}
} else {
$queries[] = "SELECT " . PMA_Util::backquote($routine['item_name']) . "(" . implode(', ', $args) . ") " . "AS " . PMA_Util::backquote($routine['item_name']) . ";\n";
}
// Get all the queries as one SQL statement
$multiple_query = implode("", $queries);
$outcome = true;
$affected = 0;
// Execute query
if (!$GLOBALS['dbi']->tryMultiQuery($multiple_query)) {
$outcome = false;
}
// Generate output
if ($outcome) {
// Pass the SQL queries through the "pretty printer"
$output = PMA_Util::formatSql(implode($queries, "\n"));
// Display results
$output .= "<fieldset><legend>";
$output .= sprintf(__('Execution results of routine %s'), PMA_Util::backquote(htmlspecialchars($routine['item_name'])));
$output .= "</legend>";
$nbResultsetToDisplay = 0;
do {
$result = $GLOBALS['dbi']->storeResult();
$num_rows = $GLOBALS['dbi']->numRows($result);
if ($result !== false && $num_rows > 0) {
$output .= "<table><tr>";
foreach ($GLOBALS['dbi']->getFieldsMeta($result) as $field) {
$output .= "<th>";
$output .= htmlspecialchars($field->name);
$output .= "</th>";
}
$output .= "</tr>";
$color_class = 'odd';
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$output .= "<tr>" . browseRow($row, $color_class) . "</tr>";
$color_class = $color_class == 'odd' ? 'even' : 'odd';
}
$output .= "</table>";
$nbResultsetToDisplay++;
$affected = $num_rows;
}
//.........这里部分代码省略.........
示例3: PMA_getHtmlForOneStatement
/**
* Function to get html for one data manipulation statement
*
* @param array $entry entry
* @param array $filter_users filter users
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param string $style style
* @param int $line_number line number
* @param array $url_params url parameters
* @param int $offset line number offset
* @param string $drop_image_or_text drop image or text
* @param string $delete_param parameter for delete
*
* @return string
*/
function PMA_getHtmlForOneStatement($entry, $filter_users, $filter_ts_from, $filter_ts_to, $style, $line_number, $url_params, $offset, $drop_image_or_text, $delete_param)
{
$statement = PMA_Util::formatSql($entry['statement'], true);
$timestamp = strtotime($entry['date']);
$filtered_user = in_array($entry['username'], $filter_users);
$html = null;
if ($timestamp >= $filter_ts_from && $timestamp <= $filter_ts_to && (in_array('*', $filter_users) || $filtered_user)) {
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td class="right"><small>' . $line_number . '</small></td>';
$html .= '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
$html .= '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
$html .= '<td>' . $statement . '</td>';
$html .= '<td class="nowrap"><a class="delete_entry_anchor ajax"' . ' href="tbl_tracking.php' . PMA_URL_getCommon($url_params + array('report' => 'true', 'version' => $_REQUEST['version'], $delete_param => $line_number - $offset)) . '">' . $drop_image_or_text . '</a></td>';
$html .= '</tr>';
}
return $html;
}
示例4: PMA_getAllLogItemInfo
/**
* Returns the html for all binary log items.
*
* @param resource $result MySQL Query result
* @param bool $dontlimitchars Whether limit chars
*
* @return string
*/
function PMA_getAllLogItemInfo($result, $dontlimitchars)
{
$html = "";
$odd_row = true;
while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
$html .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">' . '<td> ' . $value['Log_name'] . ' </td>' . '<td class="right"> ' . $value['Pos'] . ' </td>' . '<td> ' . $value['Event_type'] . ' </td>' . '<td class="right"> ' . $value['Server_id'] . ' </td>' . '<td class="right"> ' . (isset($value['Orig_log_pos']) ? $value['Orig_log_pos'] : $value['End_log_pos']) . ' </td>' . '<td> ' . PMA_Util::formatSql($value['Info'], !$dontlimitchars) . ' </td></tr>';
$odd_row = !$odd_row;
}
return $html;
}
示例5: _getRowValues
/**
* Get the values for one data row
*
* @param integer &$dt_result the link id associated to the query
* which results have to be displayed
* @param array $row current row data
* @param integer $row_no the index of current row
* @param array $col_order the column order
* false when a property not found
* @param array $map the list of relations
* @param string $grid_edit_class the class for all editable columns
* @param boolean $col_visib column is visible(false)
* array column isn't visible(string array)
* @param string $where_clause where clause
* @param string $url_sql_query the analyzed sql query
* @param array $analyzed_sql the analyzed query
* @param boolean $directionCondition the directional condition
*
* @return string $row_values_html html content
*
* @access private
*
* @see _getTableBody()
*/
private function _getRowValues(&$dt_result, $row, $row_no, $col_order, $map, $grid_edit_class, $col_visib, $where_clause, $url_sql_query, $analyzed_sql, $directionCondition)
{
$row_values_html = '';
// Following variable are needed for use in isset/empty or
// use with array indexes/safe use in foreach
$sql_query = $this->__get('sql_query');
$fields_meta = $this->__get('fields_meta');
$highlight_columns = $this->__get('highlight_columns');
$mime_map = $this->__get('mime_map');
$row_info = $this->_getRowInfoForSpecialLinks($row, $col_order);
for ($currentColumn = 0; $currentColumn < $this->__get('fields_cnt'); ++$currentColumn) {
// assign $i with appropriate column order
$i = $col_order ? $col_order[$currentColumn] : $currentColumn;
$meta = $fields_meta[$i];
$not_null_class = $meta->not_null ? 'not_null' : '';
$relation_class = isset($map[$meta->name]) ? 'relation' : '';
$hide_class = $col_visib && !$col_visib[$currentColumn] && $_SESSION['tmpval']['disp_direction'] != self::DISP_DIR_VERTICAL ? 'hide' : '';
// handle datetime-related class, for grid editing
$field_type_class = $this->_getClassForDateTimeRelatedFields($meta->type);
$is_field_truncated = false;
// combine all the classes applicable to this column's value
$class = $this->_getClassesForColumn($grid_edit_class, $not_null_class, $relation_class, $hide_class, $field_type_class, $row_no);
// See if this column should get highlight because it's used in the
// where-query.
$condition_field = isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_Util::backquote($meta->name)])) ? true : false;
// Wrap MIME-transformations. [MIME]
$default_function = '_mimeDefaultFunction';
// default_function
$transformation_plugin = $default_function;
$transform_options = array();
if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
if (isset($mime_map[$meta->name]['mimetype']) && isset($mime_map[$meta->name]['transformation']) && !empty($mime_map[$meta->name]['transformation'])) {
$file = $mime_map[$meta->name]['transformation'];
$include_file = 'libraries/plugins/transformations/' . $file;
if (file_exists($include_file)) {
include_once $include_file;
$class_name = str_replace('.class.php', '', $file);
// todo add $plugin_manager
$plugin_manager = null;
$transformation_plugin = new $class_name($plugin_manager);
$transform_options = PMA_Transformation_getOptions(isset($mime_map[$meta->name]['transformation_options']) ? $mime_map[$meta->name]['transformation_options'] : '');
$meta->mimetype = str_replace('_', '/', $mime_map[$meta->name]['mimetype']);
}
// end if file_exists
}
// end if transformation is set
}
// end if mime/transformation works.
$_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'where_clause' => $where_clause, 'transform_key' => $meta->name);
if (!empty($sql_query)) {
$_url_params['sql_query'] = $url_sql_query;
}
$transform_options['wrapper_link'] = PMA_URL_getCommon($_url_params);
$vertical_display = $this->__get('vertical_display');
// Check whether the field needs to display with syntax highlighting
if (!empty($this->transformation_info[strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)]) && trim($row[$i]) != '') {
$row[$i] = PMA_Util::formatSql($row[$i]);
include_once $this->transformation_info[strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)][0];
$transformation_plugin = new $this->transformation_info[strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)][1](null);
$transform_options = PMA_Transformation_getOptions(isset($mime_map[$meta->name]['transformation_options']) ? $mime_map[$meta->name]['transformation_options'] : '');
$meta->mimetype = str_replace('_', '/', $this->transformation_info[strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)][2]);
}
// Check for the predefined fields need to show as link in schemas
include_once 'libraries/special_schema_links.lib.php';
if (isset($GLOBALS['special_schema_links']) && !empty($GLOBALS['special_schema_links'][strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)])) {
$linking_url = $this->_getSpecialLinkUrl($row[$i], $row_info, strtolower($meta->name));
include_once "libraries/plugins/transformations/Text_Plain_Link.class.php";
$transformation_plugin = new Text_Plain_Link(null);
$transform_options = array(0 => $linking_url, 2 => true);
$meta->mimetype = str_replace('_', '/', 'Text/Plain');
}
if ($meta->numeric == 1) {
// n u m e r i c
$vertical_display['data'][$row_no][$i] = $this->_getDataCellForNumericColumns($row[$i], $class, $condition_field, $meta, $map, $is_field_truncated, $analyzed_sql, $transformation_plugin, $default_function, $transform_options);
} elseif (stristr($meta->type, self::BLOB_FIELD)) {
// b l o b
//.........这里部分代码省略.........
示例6: PMA_previewSQL
/**
* Displays SQL query before executing.
*
* @param array|string $query_data Array containing queries or query itself
*
* @return void
*/
function PMA_previewSQL($query_data)
{
$retval = '<div class="preview_sql">';
if (empty($query_data)) {
$retval .= __('No change');
} elseif (is_array($query_data)) {
foreach ($query_data as $query) {
$retval .= PMA_Util::formatSql($query);
}
} else {
$retval .= PMA_Util::formatSql($query_data);
}
$retval .= '</div>';
$response = PMA_Response::getInstance();
$response->addJSON('sql_data', $retval);
exit;
}
示例7: PMA_getHtmlForDataDefinitionStatement
/**
* Function to get html for a data definition statement in schema snapshot
*
* @param array $entry entry
* @param array $filter_users filter users
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param string $style style
* @param int $i column number
* @param array $url_params url parameters
* @param string $drop_image_or_text drop image or text
*
* @return string
*/
function PMA_getHtmlForDataDefinitionStatement($entry, $filter_users, $filter_ts_from, $filter_ts_to, $style, $i, $url_params, $drop_image_or_text)
{
$statement = PMA_Util::formatSql($entry['statement'], true);
$timestamp = strtotime($entry['date']);
$filtered_user = in_array($entry['username'], $filter_users);
$html = null;
if ($timestamp >= $filter_ts_from && $timestamp <= $filter_ts_to && (in_array('*', $filter_users) || $filtered_user)) {
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td><small>' . $i . '</small></td>';
$html .= '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
$html .= '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
$html .= '<td>' . $statement . '</td>';
$html .= '<td class="nowrap"><a href="tbl_tracking.php' . PMA_URL_getCommon($url_params + array('report' => 'true', 'version' => $_REQUEST['version'], 'delete_ddlog' => $i - 1)) . '">' . $drop_image_or_text . '</a></td>';
$html .= '</tr>';
}
return $html;
}
示例8: PMA_getHtmlForServerProcessItem
/**
* Prints Every Item of Server Process
*
* @param Array $process data of Every Item of Server Process
* @param bool $odd_row display odd row or not
* @param bool $show_full_sql show full sql or not
*
* @return string
*/
function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql)
{
// Array keys need to modify due to the way it has used
// to display column values
if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
foreach (array_keys($process) as $key) {
$new_key = ucfirst(mb_strtolower($key));
if ($new_key !== $key) {
$process[$new_key] = $process[$key];
unset($process[$key]);
}
}
}
$url_params = array('kill' => $process['Id'], 'ajax_request' => true);
$kill_process = 'server_status_processes.php' . PMA_URL_getCommon($url_params);
$retval = '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
$retval .= '<td><a class="ajax kill_process" href="' . $kill_process . '">' . __('Kill') . '</a></td>';
$retval .= '<td class="value">' . $process['Id'] . '</td>';
$retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
$retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
$retval .= '<td>' . (!isset($process['db']) || !mb_strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
$retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
$retval .= '<td class="value">' . $process['Time'] . '</td>';
$processStatusStr = empty($process['State']) ? '---' : $process['State'];
$retval .= '<td>' . $processStatusStr . '</td>';
$retval .= '<td>';
if (empty($process['Info'])) {
$retval .= '---';
} else {
$retval .= PMA_Util::formatSql($process['Info'], !$show_full_sql);
}
$retval .= '</td>';
$retval .= '</tr>';
return $retval;
}
示例9: PMA_getMatchedRows
/**
* Find the matching rows for UPDATE/DELETE query.
*
* @param array $analyzed_sql_results Analyzed SQL results from parser.
*
* @return mixed
*/
function PMA_getMatchedRows($analyzed_sql_results = array())
{
// Get the query type.
$query_type = isset($analyzed_sql_results['analyzed_sql'][0]['querytype']) ? $analyzed_sql_results['analyzed_sql'][0]['querytype'] : '';
$matched_row_query = '';
if ($query_type == 'DELETE') {
$matched_row_query = PMA_getSimulatedDeleteQuery($analyzed_sql_results);
} else {
if ($query_type == 'UPDATE') {
$matched_row_query = PMA_getSimulatedUpdateQuery($analyzed_sql_results);
}
}
// Execute the query and get the number of matched rows.
$matched_rows = PMA_executeMatchedRowQuery($matched_row_query);
// URL to matched rows.
$_url_params = array('db' => $GLOBALS['db'], 'sql_query' => $matched_row_query);
$matched_rows_url = 'sql.php' . PMA_URL_getCommon($_url_params);
return array('sql_query' => PMA_Util::formatSql($analyzed_sql_results['parsed_sql']['raw']), 'matched_rows' => $matched_rows, 'matched_rows_url' => $matched_rows_url);
}
示例10: PMA_getMatchedRows
/**
* Find the matching rows for UPDATE/DELETE query.
*
* @param array $analyzed_sql_results Analyzed SQL results from parser.
*
* @return mixed
*/
function PMA_getMatchedRows($analyzed_sql_results = array())
{
$statement = $analyzed_sql_results['statement'];
$matched_row_query = '';
if ($statement instanceof SqlParser\Statements\DeleteStatement) {
$matched_row_query = PMA_getSimulatedDeleteQuery($analyzed_sql_results);
} elseif ($statement instanceof SqlParser\Statements\UpdateStatement) {
$matched_row_query = PMA_getSimulatedUpdateQuery($analyzed_sql_results);
}
// Execute the query and get the number of matched rows.
$matched_rows = PMA_executeMatchedRowQuery($matched_row_query);
// URL to matched rows.
$_url_params = array('db' => $GLOBALS['db'], 'sql_query' => $matched_row_query);
$matched_rows_url = 'sql.php' . PMA_URL_getCommon($_url_params);
return array('sql_query' => PMA_Util::formatSql($analyzed_sql_results['query']), 'matched_rows' => $matched_rows, 'matched_rows_url' => $matched_rows_url);
}
示例11: __
echo '<th>' . __('Data manipulation statement') . '</th>';
echo '<th>' . __('Delete') . '</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$style = 'odd';
foreach ($data['dmlog'] as $entry) {
if (strlen($entry['statement']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
$statement = substr(
$entry['statement'],
0,
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
) . '[...]';
} else {
$statement = PMA_Util::formatSql(PMA_SQP_parse($entry['statement']));
}
$timestamp = strtotime($entry['date']);
if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || in_array($entry['username'], $filter_users))
) {
echo '<tr class="noclick ' . $style . '">';
echo '<td><small>' . $i . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['date']) . '</small></td>';
echo '<td><small>' . htmlspecialchars($entry['username']) . '</small></td>';
echo '<td>' . $statement . '</td>';
echo '<td class="nowrap"><a href="tbl_tracking.php?' . $url_query
. '&report=true&version=' . $version['version']
. '&delete_dmlog=' . ($i - $ddlog_count) . '">'
示例12: simulatedQueryTest
/**
* Tests simulated UPDATE/DELETE query.
*
* @param string $sql_query SQL query
* @param string $simulated_query Simulated query
*
* @return void
*/
function simulatedQueryTest($sql_query, $simulated_query)
{
$parsed_sql = PMA_SQP_parse($sql_query);
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
$analyzed_sql_results = array('parsed_sql' => $parsed_sql, 'analyzed_sql' => $analyzed_sql);
$simulated_data = PMA_getMatchedRows($analyzed_sql_results);
// URL to matched rows.
$_url_params = array('db' => 'PMA', 'sql_query' => $simulated_query);
$matched_rows_url = 'sql.php' . PMA_URL_getCommon($_url_params);
$this->assertEquals(array('sql_query' => PMA_Util::formatSql($analyzed_sql_results['parsed_sql']['raw']), 'matched_rows' => 2, 'matched_rows_url' => $matched_rows_url), $simulated_data);
}
示例13: simulatedQueryTest
/**
* Tests simulated UPDATE/DELETE query.
*
* @param string $sql_query SQL query
* @param string $simulated_query Simulated query
*
* @return void
*/
function simulatedQueryTest($sql_query, $simulated_query)
{
$parser = new SqlParser\Parser($sql_query);
$analyzed_sql_results = array('query' => $sql_query, 'parser' => $parser, 'statement' => $parser->statements[0]);
$simulated_data = PMA_getMatchedRows($analyzed_sql_results);
// URL to matched rows.
$_url_params = array('db' => 'PMA', 'sql_query' => $simulated_query);
$matched_rows_url = 'sql.php' . PMA_URL_getCommon($_url_params);
$this->assertEquals(array('sql_query' => PMA_Util::formatSql($analyzed_sql_results['query']), 'matched_rows' => 2, 'matched_rows_url' => $matched_rows_url), $simulated_data);
}
示例14: testFormatSQLError
function testFormatSQLError()
{
global $SQP_errorString;
$SQP_errorString = true;
$sql = array("raw" => "& \" < >");
$this->assertEquals(
"& " < >",
PMA_Util::formatSql($sql)
);
$SQP_errorString = false;
}
示例15: testFormatSQLTruncate
/**
* Test for formatSql
*
* @return void
*/
function testFormatSQLTruncate()
{
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 6;
$this->assertEquals('<code class="sql"><pre>' . "\n" . 'SELECT[...]' . "\n" . '</pre></code>', PMA_Util::formatSql('SELECT 1 < 2', true));
}