本文整理汇总了PHP中PMA_SQP_analyze函数的典型用法代码示例。如果您正苦于以下问题:PHP PMA_SQP_analyze函数的具体用法?PHP PMA_SQP_analyze怎么用?PHP PMA_SQP_analyze使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PMA_SQP_analyze函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public static function parse($_sql)
{
if (!is_array($_sql)) {
$_sql = self::parsePMA($_sql);
}
$analyzedSql = PMA_SQP_analyze($_sql);
return self::trim(@$analyzedSql[0]);
}
示例2: PMA_exportData
/**
* Dispatches between the versions of 'getTableContent' to use depending
* on the php version
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
* @global integer the number of records
* @global integer the current record position
*
* @access public
*
* @see PMA_getTableContentFast(), PMA_getTableContentOld()
*
* @author staybyte
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $use_backquotes;
global $rows_cnt;
global $current_row;
$formatted_table_name = isset($GLOBALS['use_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
$head = $crlf . '#' . $crlf . '# ' . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf;
if (!PMA_exportOutputHandler($head)) {
return FALSE;
}
$buffer = '';
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
if ($result != FALSE) {
$fields_cnt = mysql_num_fields($result);
$rows_cnt = mysql_num_rows($result);
// get the real types of the table's fields (in an array)
// the key of the array is the backquoted field name
$field_types = PMA_fieldTypes($db, $table, $use_backquotes);
// 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)
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
// Checks whether the field is an integer or not
for ($j = 0; $j < $fields_cnt; $j++) {
if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
$field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $use_backquotes);
} else {
$field_set[$j] = PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes);
}
$type = $field_types[$field_set[$j]];
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || PMA_MYSQL_INT_VERSION < 40100 && $type == 'timestamp') {
$field_num[$j] = TRUE;
} else {
$field_num[$j] = FALSE;
}
// blob
if ($type == 'blob' || $type == 'mediumblob' || $type == 'longblob' || $type == 'tinyblob') {
$field_blob[$j] = TRUE;
} else {
$field_blob[$j] = FALSE;
}
}
// end for
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
// update
$schema_insert = 'UPDATE ' . PMA_backquote($table, $use_backquotes) . ' SET ';
$fields_no = count($field_set);
} else {
// insert or replace
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'replace') {
$sql_command = 'REPLACE';
} else {
$sql_command = 'INSERT';
}
// delayed inserts?
if (isset($GLOBALS['delayed'])) {
$insert_delayed = ' DELAYED';
} else {
$insert_delayed = '';
}
// Sets the scheme
if (isset($GLOBALS['showcolumns'])) {
$fields = implode(', ', $field_set);
$schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $use_backquotes) . ' (' . $fields . ') VALUES (';
} else {
$schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $use_backquotes) . ' VALUES (';
}
}
$search = array("", "\n", "\r", "");
//\x08\\x09, not required
$replace = array('\\0', '\\n', '\\r', '\\Z');
$current_row = 0;
while ($row = PMA_mysql_fetch_row($result)) {
$current_row++;
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j])) {
$values[] = 'NULL';
//.........这里部分代码省略.........
示例3: PMA_getForeigners
/**
* Gets all Relations to foreign tables for a given table or
* optionally a given column in a table
*
* @param string $db the name of the db to check for
* @param string $table the name of the table to check for
* @param string $column the name of the column to check for
* @param string $source the source for foreign key information
*
* @return array db,table,column
*
* @access public
*/
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
$cfgRelation = PMA_getRelationsParam();
$foreign = array();
if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
$rel_query = '
SELECT `master_field`,
`foreign_db`,
`foreign_table`,
`foreign_field`
FROM ' . PMA_Util::backquote($cfgRelation['db']) . '.' . PMA_Util::backquote($cfgRelation['relation']) . '
WHERE `master_db` = \'' . PMA_Util::sqlAddSlashes($db) . '\'
AND `master_table` = \'' . PMA_Util::sqlAddSlashes($table) . '\' ';
if (mb_strlen($column)) {
$rel_query .= ' AND `master_field` = ' . '\'' . PMA_Util::sqlAddSlashes($column) . '\'';
}
$foreign = $GLOBALS['dbi']->fetchResult($rel_query, 'master_field', null, $GLOBALS['controllink']);
}
if (($source == 'both' || $source == 'foreign') && mb_strlen($table)) {
$showCreateTableQuery = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table);
$show_create_table = $GLOBALS['dbi']->fetchValue($showCreateTableQuery, 0, 1);
if ($show_create_table) {
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
$foreign['foreign_keys_data'] = $analyzed_sql[0]['foreign_keys'];
}
}
/**
* Emulating relations for some information_schema and data_dictionary tables
*/
$isInformationSchema = mb_strtolower($db) == 'information_schema';
$is_data_dictionary = PMA_DRIZZLE && mb_strtolower($db) == 'data_dictionary';
$isMysql = mb_strtolower($db) == 'mysql';
if (($isInformationSchema || $is_data_dictionary || $isMysql) && ($source == 'internal' || $source == 'both')) {
if ($isInformationSchema) {
$relations_key = 'information_schema_relations';
include_once './libraries/information_schema_relations.lib.php';
} else {
if ($is_data_dictionary) {
$relations_key = 'data_dictionary_relations';
include_once './libraries/data_dictionary_relations.lib.php';
} else {
$relations_key = 'mysql_relations';
include_once './libraries/mysql_relations.lib.php';
}
}
if (isset($GLOBALS[$relations_key][$table])) {
foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
if ((!mb_strlen($column) || $column == $field) && (!isset($foreign[$field]) || !mb_strlen($foreign[$field]))) {
$foreign[$field] = $relations;
}
}
}
}
return $foreign;
}
示例4: PMA_SQP_parse
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @package phpMyAdmin
*/
if (!defined('PHPMYADMIN')) {
exit;
}
/**
*
*/
$GLOBALS['unparsed_sql'] = $sql_query;
$parsed_sql = PMA_SQP_parse($sql_query);
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
// for bug 780516: now that we use case insensitive preg_match
// or flags from the analyser, do not put back the reformatted query
// into $sql_query, to make this kind of query work without
// capitalizing keywords:
//
// CREATE TABLE SG_Persons (
// id int(10) unsigned NOT NULL auto_increment,
// first varchar(64) NOT NULL default '',
// PRIMARY KEY (`id`)
// )
// check for a real SELECT ... FROM
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
// If the query is a Select, extract the db and table names and modify
// $db and $table, to have correct page headers, links and left frame.
// db and table name may be enclosed with backquotes, db is optionnal,
示例5: PMA_showMessage
//.........这里部分代码省略.........
if (isset($GLOBALS['special_message'])) {
echo PMA_sanitize($GLOBALS['special_message']);
unset($GLOBALS['special_message']);
}
echo '</div>';
}
if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
// Html format the query to be displayed
// If we want to show some sql code it is easiest to create it here
/* SQL-Parser-Analyzer */
if (!empty($GLOBALS['show_as_php'])) {
$new_line = '\\n"<br />' . "\n" . ' . "';
$query_base = htmlspecialchars(addslashes($sql_query));
$query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
} else {
$query_base = $sql_query;
}
$query_too_big = false;
if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
// when the query is large (for example an INSERT of binary
// data), the parser chokes; so avoid parsing the query
$query_too_big = true;
$shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
} elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
// (here, use "! empty" because when deleting a bookmark,
// $GLOBALS['parsed_sql'] is set but empty
$parsed_sql = $GLOBALS['parsed_sql'];
} else {
// Parse SQL if needed
$parsed_sql = PMA_SQP_parse($query_base);
}
// Analyze it
if (isset($parsed_sql) && !PMA_SQP_isError()) {
$analyzed_display_query = PMA_SQP_analyze($parsed_sql);
// Same as below (append LIMIT), append the remembered ORDER BY
if ($GLOBALS['cfg']['RememberSorting'] && isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_order_to_append'])) {
$query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_order_to_append'] . $analyzed_display_query[0]['limit_clause'] . ' ' . $analyzed_display_query[0]['section_after_limit'];
// Need to reparse query
$parsed_sql = PMA_SQP_parse($query_base);
// update the $analyzed_display_query
$analyzed_display_query[0]['section_before_limit'] .= $GLOBALS['sql_order_to_append'];
$analyzed_display_query[0]['order_by_clause'] = $GLOBALS['sorted_col'];
}
// Here we append the LIMIT added for navigation, to
// enable its display. Adding it higher in the code
// to $sql_query would create a problem when
// using the Refresh or Edit links.
// Only append it on SELECTs.
/**
* @todo what would be the best to do when someone hits Refresh:
* use the current LIMITs ?
*/
if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
$query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
// Need to reparse query
$parsed_sql = PMA_SQP_parse($query_base);
}
}
if (!empty($GLOBALS['show_as_php'])) {
$query_base = '$sql = "' . $query_base;
} elseif (!empty($GLOBALS['validatequery'])) {
try {
$query_base = PMA_validateSQL($query_base);
} catch (Exception $e) {
PMA_Message::error(__('Failed to connect to SQL validator!'))->display();
}
示例6: PMA_SQP_getAliasesFromQuery
/**
* Get Aliases from select query
* Note: only useful for select query on single table.
*
* @param string $select_query The Select SQL Query
* @param string $db Current DB
*
* @return Array alias information from select query
*/
function PMA_SQP_getAliasesFromQuery($select_query, $db)
{
if (empty($select_query) || empty($db)) {
return array();
}
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($select_query));
$aliases = array($db => array('alias' => null, 'tables' => array()));
foreach ($analyzed_sql[0]['table_ref'] as $table) {
$t_db = !empty($table['db']) ? $table['db'] : $db;
if (!isset($aliases[$t_db])) {
$aliases[$t_db] = array('alias' => null, 'tables' => array());
}
$aliases[$t_db]['tables'][$table['table_true_name']] = array('alias' => !empty($table['table_alias']) ? $table['table_alias'] : null, 'columns' => array());
}
foreach ($analyzed_sql[0]['select_expr'] as $cols) {
if (!empty($cols['alias'])) {
$t_db = !empty($cols['db']) ? $cols['db'] : $db;
if (!empty($cols['table_true_name'])) {
$aliases[$t_db]['tables'][$cols['table_true_name']]['columns'][$cols['column']] = $cols['alias'];
} else {
foreach ($aliases[$t_db]['tables'] as $key => $table) {
$aliases[$t_db]['tables'][$key]['columns'][$cols['column']] = $cols['alias'];
}
}
}
}
return $aliases;
}
示例7: PMA_displayHtmlForColumnChange
/**
* Displays HTML for changing one or more columns
*
* @param string $db database name
* @param string $table table name
* @param array $selected the selected columns
* @param string $action target script to call
*
* @return boolean $regenerate true if error occurred
*
*/
function PMA_displayHtmlForColumnChange($db, $table, $selected, $action)
{
// $selected comes from multi_submits.inc.php
if (empty($selected)) {
$selected[] = $_REQUEST['field'];
$selected_cnt = 1;
} else {
// from a multiple submit
$selected_cnt = count($selected);
}
/**
* @todo optimize in case of multiple fields to modify
*/
$fields_meta = array();
for ($i = 0; $i < $selected_cnt; $i++) {
$fields_meta[] = $GLOBALS['dbi']->getColumns($db, $table, $selected[$i], true);
}
$num_fields = count($fields_meta);
// set these globals because tbl_columns_definition_form.inc.php
// verifies them
// @todo: refactor tbl_columns_definition_form.inc.php so that it uses
// function params
$GLOBALS['action'] = 'tbl_structure.php';
$GLOBALS['num_fields'] = $num_fields;
// Get more complete field information.
// For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options
// and to know when there is an empty DEFAULT value.
// Later, if the analyser returns more information, it
// could be executed to replace the info given by SHOW FULL COLUMNS FROM.
/**
* @todo put this code into a require()
* or maybe make it part of $GLOBALS['dbi']->getColumns();
*/
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25).
$show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
unset($show_create_table);
/**
* Form for changing properties.
*/
include 'libraries/tbl_columns_definition_form.inc.php';
}
示例8: PMA_getForeigners
/**
* Gets all Relations to foreign tables for a given table or
* optionally a given column in a table
*
* @param string $db the name of the db to check for
* @param string $table the name of the table to check for
* @param string $column the name of the column to check for
* @param string $source the source for foreign key information
*
* @return array db,table,column
*
* @access public
*/
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
$cfgRelation = PMA_getRelationsParam();
$foreign = array();
if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
$rel_query = '
SELECT `master_field`,
`foreign_db`,
`foreign_table`,
`foreign_field`
FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
WHERE `master_db` = \'' . PMA_sqlAddSlashes($db) . '\'
AND `master_table` = \'' . PMA_sqlAddSlashes($table) . '\' ';
if (strlen($column)) {
$rel_query .= ' AND `master_field` = \'' . PMA_sqlAddSlashes($column) . '\'';
}
$foreign = PMA_DBI_fetch_result($rel_query, 'master_field', null, $GLOBALS['controllink']);
}
if (($source == 'both' || $source == 'foreign') && strlen($table)) {
$show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$show_create_table = PMA_DBI_fetch_value($show_create_table_query, 0, 1);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
foreach ($analyzed_sql[0]['foreign_keys'] as $one_key) {
// The analyzer may return more than one column name in the
// index list or the ref_index_list; if this happens,
// the current logic just discards the whole index; having
// more than one index field is currently unsupported (see FAQ 3.6)
if (count($one_key['index_list']) == 1) {
foreach ($one_key['index_list'] as $i => $field) {
// If a foreign key is defined in the 'internal' source (pmadb)
// and as a native foreign key, we won't get it twice
// if $source='both' because we use $field as key
// The parser looks for a CONSTRAINT clause just before
// the FOREIGN KEY clause. It finds it (as output from
// SHOW CREATE TABLE) in MySQL 4.0.13, but not in older
// versions like 3.23.58.
// In those cases, the FOREIGN KEY parsing will put numbers
// like -1, 0, 1... instead of the constraint number.
if (isset($one_key['constraint'])) {
$foreign[$field]['constraint'] = $one_key['constraint'];
}
if (isset($one_key['ref_db_name'])) {
$foreign[$field]['foreign_db'] = $one_key['ref_db_name'];
} else {
$foreign[$field]['foreign_db'] = $db;
}
$foreign[$field]['foreign_table'] = $one_key['ref_table_name'];
$foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i];
if (isset($one_key['on_delete'])) {
$foreign[$field]['on_delete'] = $one_key['on_delete'];
}
if (isset($one_key['on_update'])) {
$foreign[$field]['on_update'] = $one_key['on_update'];
}
}
}
}
}
/**
* Emulating relations for some information_schema and data_dictionary tables
*/
$is_information_schema = strtolower($db) == 'information_schema';
$is_data_dictionary = PMA_DRIZZLE && strtolower($db) == 'data_dictionary';
if (($is_information_schema || $is_data_dictionary) && ($source == 'internal' || $source == 'both')) {
if ($is_information_schema) {
$relations_key = 'information_schema_relations';
include_once './libraries/information_schema_relations.lib.php';
} else {
$relations_key = 'data_dictionary_relations';
include_once './libraries/data_dictionary_relations.lib.php';
}
if (isset($GLOBALS[$relations_key][$table])) {
foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
if ((!strlen($column) || $column == $field) && (!isset($foreign[$field]) || !strlen($foreign[$field]))) {
$foreign[$field] = $relations;
}
}
}
}
return $foreign;
}
示例9: PMA_showMessage
//.........这里部分代码省略.........
}
if ($cfg['ShowSQL'] == true && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) {
$local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : ($cfg['SQP']['fmtType'] == 'none' && isset($GLOBALS['unparsed_sql']) && $GLOBALS['unparsed_sql'] != '' ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']);
// Basic url query part
$url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
// Html format the query to be displayed
// The nl2br function isn't used because its result isn't a valid
// xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
// If we want to show some sql code it is easiest to create it here
/* SQL-Parser-Analyzer */
if (!empty($GLOBALS['show_as_php'])) {
$new_line = '\'<br />' . "\n" . ' . \' ';
}
if (isset($new_line)) {
/* SQL-Parser-Analyzer */
$query_base = PMA_sqlAddslashes(htmlspecialchars($local_query), false, false, true);
/* SQL-Parser-Analyzer */
$query_base = preg_replace("@((\r\n)|(\r)|(\n))+@", $new_line, $query_base);
} else {
$query_base = $local_query;
}
// Parse SQL if needed
if (isset($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
$parsed_sql = $GLOBALS['parsed_sql'];
} else {
// when the query is large (for example an INSERT of binary
// data), the parser chokes; so avoid parsing the query
if (strlen($query_base) < 1000) {
$parsed_sql = PMA_SQP_parse($query_base);
}
}
// Analyze it
if (isset($parsed_sql)) {
$analyzed_display_query = PMA_SQP_analyze($parsed_sql);
}
// Here we append the LIMIT added for navigation, to
// enable its display. Adding it higher in the code
// to $local_query would create a problem when
// using the Refresh or Edit links.
// Only append it on SELECTs.
// FIXME: what would be the best to do when someone
// hits Refresh: use the current LIMITs ?
if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
$query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
// Need to reparse query
$parsed_sql = PMA_SQP_parse($query_base);
}
if (!empty($GLOBALS['show_as_php'])) {
$query_base = '$sql = \'' . $query_base;
} elseif (!empty($GLOBALS['validatequery'])) {
$query_base = PMA_validateSQL($query_base);
} else {
if (isset($parsed_sql)) {
$query_base = PMA_formatSql($parsed_sql, $query_base);
}
}
// Prepares links that may be displayed to edit/explain the query
// (don't go to default pages, we must go to the page
// where the query box is available)
// (also, I don't see why we should check the goto variable)
//if (!isset($GLOBALS['goto'])) {
//$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];
$edit_target = isset($GLOBALS['db']) ? isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php' : 'server_sql.php';
//} elseif ($GLOBALS['goto'] != 'main.php') {
// $edit_target = $GLOBALS['goto'];
//} else {
示例10: PMA_GIS_modifyQuery
/**
* Returns a modified sql query with only the label column
* and spatial column(wrapped with 'ASTEXT()' function).
*
* @param string $sql_query original sql query
* @param array $visualizationSettings settings for the visualization
*
* @return the modified sql query.
*/
function PMA_GIS_modifyQuery($sql_query, $visualizationSettings)
{
$modified_query = 'SELECT ';
$analyzed_query = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
// If select clause is not *
if (trim($analyzed_query[0]['select_expr_clause']) != '*') {
// If label column is chosen add it to the query
if (isset($visualizationSettings['labelColumn']) && $visualizationSettings['labelColumn'] != '') {
// Check to see whether an alias has been used on the label column
$is_label_alias = false;
foreach ($analyzed_query[0]['select_expr'] as $select) {
if ($select['alias'] == $visualizationSettings['labelColumn']) {
$modified_query .= sanitize($select) . ' AS `' . $select['alias'] . '`, ';
$is_label_alias = true;
break;
}
}
// If no alias have been used on the label column
if (!$is_label_alias) {
foreach ($analyzed_query[0]['select_expr'] as $select) {
if ($select['column'] == $visualizationSettings['labelColumn']) {
$modified_query .= sanitize($select) . ', ';
}
}
}
}
// Check to see whether an alias has been used on the spatial column
$is_spatial_alias = false;
foreach ($analyzed_query[0]['select_expr'] as $select) {
if ($select['alias'] == $visualizationSettings['spatialColumn']) {
$sanitized = sanitize($select);
$modified_query .= 'ASTEXT(' . $sanitized . ') AS `' . $select['alias'] . '`, ';
// Get the SRID
$modified_query .= 'SRID(' . $sanitized . ') AS `srid` ';
$is_spatial_alias = true;
break;
}
}
// If no alias have been used on the spatial column
if (!$is_spatial_alias) {
foreach ($analyzed_query[0]['select_expr'] as $select) {
if ($select['column'] == $visualizationSettings['spatialColumn']) {
$sanitized = sanitize($select);
$modified_query .= 'ASTEXT(' . $sanitized . ') AS `' . $select['column'] . '`, ';
// Get the SRID
$modified_query .= 'SRID(' . $sanitized . ') AS `srid` ';
}
}
}
// If select cluase is *
} else {
// If label column is chosen add it to the query
if (isset($visualizationSettings['labelColumn']) && $visualizationSettings['labelColumn'] != '') {
$modified_query .= '`' . $visualizationSettings['labelColumn'] . '`, ';
}
// Wrap the spatial column with 'ASTEXT()' function and add it
$modified_query .= 'ASTEXT(`' . $visualizationSettings['spatialColumn'] . '`) AS `' . $visualizationSettings['spatialColumn'] . '`, ';
// Get the SRID
$modified_query .= 'SRID(`' . $visualizationSettings['spatialColumn'] . '`) AS `srid` ';
}
// Append the rest of the query
$from_pos = stripos($sql_query, 'FROM');
$modified_query .= substr($sql_query, $from_pos);
return $modified_query;
}
示例11: PMA_appendLimitClause
/**
* Function to append the limit clause
*
* @param String $full_sql_query full sql query
* @param array $analyzed_sql analyzed sql query
* @param String $display_query display query
*
* @return array
*/
function PMA_appendLimitClause($full_sql_query, $analyzed_sql, $display_query)
{
$sql_limit_to_append = ' LIMIT ' . $_SESSION['tmpval']['pos'] . ', ' . $_SESSION['tmpval']['max_rows'] . " ";
$full_sql_query = PMA_getSqlWithLimitClause($full_sql_query, $analyzed_sql, $sql_limit_to_append);
/**
* @todo pretty printing of this modified query
*/
if ($display_query) {
// if the analysis of the original query revealed that we found
// a section_after_limit, we now have to analyze $display_query
// to display it correctly
if (!empty($analyzed_sql[0]['section_after_limit']) && trim($analyzed_sql[0]['section_after_limit']) != ';') {
$analyzed_display_query = PMA_SQP_analyze(PMA_SQP_parse($display_query));
$display_query = $analyzed_display_query[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_display_query[0]['section_after_limit'];
}
}
return array($sql_limit_to_append, $full_sql_query, isset($analyzed_display_query) ? $analyzed_display_query : null, isset($display_query) ? $display_query : null);
}
示例12: PMA_setComment
/**
* Set a single comment to a certain value.
*
* @param string the name of the db
* @param string the name of the table (may be empty in case of a db comment)
* @param string the name of the column
* @param string the value of the column
* @param string (optional) if a column is renamed, this is the name of the former key which will get deleted
* @param string whether we set pmadb comments, native comments or both
*
* @return boolean true, if comment-query was made.
*
* @global array the list of relations settings
*
* @access public
*/
function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode = 'auto')
{
global $cfgRelation;
if ($mode == 'auto') {
if (PMA_MYSQL_INT_VERSION >= 40100) {
$mode = 'native';
} else {
$mode = 'pmadb';
}
}
// native mode is only for column comments so we need a table name
if ($mode == 'native' && !empty($table)) {
$fields = PMA_DBI_get_fields($db, $table);
// Get more complete field information
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL FIELDS FROM.
// TODO: put this code into a require()
// or maybe make it part of PMA_DBI_get_fields();
if (PMA_MYSQL_INT_VERSION >= 40102) {
$show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$show_create_table_res = PMA_DBI_query($show_create_table_query);
list(, $show_create_table) = PMA_DBI_fetch_row($show_create_table_res);
PMA_DBI_free_result($show_create_table_res);
unset($show_create_table_res, $show_create_table_query);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
}
// TODO: get directly the information of $col
foreach ($fields as $key => $field) {
$tmp_col = $field['Field'];
$types[$tmp_col] = $field['Type'];
$collations[$tmp_col] = $field['Collation'];
$nulls[$tmp_col] = $field['Null'];
$defaults[$tmp_col] = $field['Default'];
$extras[$tmp_col] = $field['Extra'];
if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['on_update_current_timestamp'])) {
$extras[$tmp_col] = 'ON UPDATE CURRENT_TIMESTAMP';
}
if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['default_current_timestamp'])) {
$default_current_timestamps[$tmp_col] = TRUE;
} else {
$default_current_timestamps[$tmp_col] = FALSE;
}
if ($tmp_col == $col) {
break;
}
}
if ($nulls[$col] == 'YES') {
$nulls[$col] = '';
} else {
$nulls[$col] = 'NOT NULL';
}
$query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . PMA_generateAlterTable($col, $col, $types[$col], $collations[$col], $nulls[$col], $defaults[$col], $default_current_timestamps[$col], $extras[$col], $comment);
PMA_DBI_try_query($query, NULL, PMA_DBI_QUERY_STORE);
return TRUE;
}
// $mode == 'pmadb' section:
$cols = array('db_name' => 'db_name ', 'table_name' => 'table_name ', 'column_name' => 'column_name');
if ($removekey != '' and $removekey != $col) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($removekey) . '\'';
PMA_query_as_cu($remove_query);
unset($remove_query);
}
$test_qry = 'SELECT ' . PMA_backquote('comment') . ', mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($col) . '\'';
$test_rs = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE);
if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
$row = PMA_DBI_fetch_assoc($test_rs);
PMA_DBI_free_result($test_rs);
if (strlen($comment) > 0 || strlen($row['mimetype']) > 0 || strlen($row['transformation']) > 0 || strlen($row['transformation_options']) > 0) {
$upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_sqlAddslashes($comment) . '\'' . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddSlashes($col) . '\'';
} else {
$upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($col) . '\'';
}
} else {
if (strlen($comment) > 0) {
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($col) . '\',' . '\'' . PMA_sqlAddslashes($comment) . '\')';
}
}
if (isset($upd_query)) {
$upd_rs = PMA_query_as_cu($upd_query);
unset($upd_query);
return true;
} else {
//.........这里部分代码省略.........
示例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)
{
$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);
}
示例14: analyzeStructure
/**
* Returns the analysis of 'SHOW CREATE TABLE' query for the table.
* In case of a view, the values are taken from the information_schema.
*
* @return array analysis of 'SHOW CREATE TABLE' query for the table
*/
public function analyzeStructure()
{
if (empty($this->_db_name) || empty($this->_name)) {
return false;
}
$analyzed_sql = array();
if ($this->isView()) {
// For a view, 'SHOW CREATE TABLE' returns the definition,
// but the structure of the view. So, we try to mock
// the result of analyzing 'SHOW CREATE TABLE' query.
$analyzed_sql[0] = array();
$analyzed_sql[0]['create_table_fields'] = array();
$results = $this->_dbi->fetchResult("SELECT COLUMN_NAME, DATA_TYPE\r\n FROM information_schema.COLUMNS\r\n WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($this->_db_name) . " AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($this->_name) . "'");
foreach ($results as $result) {
$analyzed_sql[0]['create_table_fields'][$result['COLUMN_NAME']] = array('type' => mb_strtoupper($result['DATA_TYPE']));
}
} else {
$show_create_table = $this->_dbi->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($this->_db_name) . '.' . PMA_Util::backquote($this->_name), 0, 1);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
}
return $analyzed_sql;
}
示例15: PMA_exportData
/**
* Dispatches between the versions of 'getTableContent' to use depending
* on the php version
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
* @global integer the number of records
* @global integer the current record position
*
* @access public
*
* @see PMA_getTableContentFast(), PMA_getTableContentOld()
*
* @author staybyte
*/
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']) ? PMA_backquote($table) : '\'' . $table . '\'';
$head = $crlf . $GLOBALS['comment_marker'] . $crlf . $GLOBALS['comment_marker'] . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf . $crlf;
if (!PMA_exportOutputHandler($head)) {
return FALSE;
}
$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)
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
if ($result != FALSE) {
$fields_cnt = PMA_DBI_num_fields($result);
// Get field information
$fields_meta = PMA_DBI_get_fields_meta($result);
$field_flags = array();
for ($j = 0; $j < $fields_cnt; $j++) {
$field_flags[$j] = PMA_DBI_field_flags($result, $j);
}
for ($j = 0; $j < $fields_cnt; $j++) {
if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
$field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $sql_backquotes);
} else {
$field_set[$j] = PMA_backquote($fields_meta[$j]->name, $sql_backquotes);
}
}
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {
// update
$schema_insert = 'UPDATE ';
if (isset($GLOBALS['sql_ignore'])) {
$schema_insert .= 'IGNORE ';
}
$schema_insert .= PMA_backquote($table, $sql_backquotes) . ' SET ';
} else {
// insert or replace
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') {
$sql_command = 'REPLACE';
} else {
$sql_command = 'INSERT';
}
// delayed inserts?
if (isset($GLOBALS['sql_delayed'])) {
$insert_delayed = ' DELAYED';
} else {
$insert_delayed = '';
}
// insert ignore?
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) {
$insert_delayed .= ' IGNORE';
}
// scheme for inserting fields
if (isset($GLOBALS['sql_columns'])) {
$fields = implode(', ', $field_set);
$schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $sql_backquotes) . ' (' . $fields . ') VALUES ';
} else {
$schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $sql_backquotes) . ' VALUES ';
}
}
$search = array("", "\n", "\r", "");
//\x08\\x09, not required
$replace = array('\\0', '\\n', '\\r', '\\Z');
$current_row = 0;
$query_size = 0;
if (isset($GLOBALS['sql_extended']) && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {
$separator = ',';
$schema_insert .= $crlf;
} else {
$separator = ';';
}
while ($row = PMA_DBI_fetch_row($result)) {
$current_row++;
for ($j = 0; $j < $fields_cnt; $j++) {
//.........这里部分代码省略.........