diff --git a/ChangeLog b/ChangeLog index 1e610155b..0cb5b567c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11,8 +11,13 @@ $Source$ * libraries/Table.class.php: *NEW* class PMA_Table * tbl_addfield.php, tbl_create.php: use Table.class.php - * libraries/common.lib.php: - moved PMA_generateFieldSpec() into PMA_Table + * db_details_qbe.php, db_details_structure.php, tbl_alter.php, sql.php, + libraries/common.lib.php, libraries/tbl_properties_table_info.inc.php, + libraries/display_export.lib.php, libraries/display_tbl.lib.php, + libraries/get_foreign.lib.php, libraries/relation.lib.php: + moved PMA_generateFieldSpec(), PMA_tableIsView(), PMA_countRecords(), + PMA_generateAlterTable() into class PMA_Table + 2006-02-20 Marc Delisle ### 2.8.0-rc1 released diff --git a/db_details_qbe.php b/db_details_qbe.php index 62febf719..263e12aa4 100644 --- a/db_details_qbe.php +++ b/db_details_qbe.php @@ -10,6 +10,7 @@ * requirements */ require_once('./libraries/common.lib.php'); +require_once './libraries/Table.class.php'; require_once('./libraries/relation.lib.php'); @@ -805,7 +806,7 @@ if (isset($Field) && count($Field) > 0) { $checked_tables = $col_cand; foreach ($col_cand AS $tab) { if ($checked_tables[$tab] != 1 ) { - $tsize[$tab] = PMA_countRecords($db, $tab, true, false); + $tsize[$tab] = PMA_Table::countRecords($db, $tab, true, false); $checked_tables[$tab] = 1; } $csize[$tab] = $tsize[$tab]; diff --git a/db_details_structure.php b/db_details_structure.php index cebef727a..e1aeede9b 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -3,6 +3,7 @@ // vim: expandtab sw=4 ts=4 sts=4: require_once './libraries/common.lib.php'; +require_once './libraries/Table.class.php'; /** * Prepares the tables list if the user where not redirected to this script @@ -175,7 +176,7 @@ $at_least_one_view_exceeds_max_count = false; foreach ($tables as $keyname => $each_table) { if ($each_table['TABLE_ROWS'] === null || $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) { - $each_table['TABLE_ROWS'] = PMA_countRecords($db, + $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db, $each_table['TABLE_NAME'], $return = true, $force_exact = true); } diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 6d3df193c..abde3f373 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -110,8 +110,12 @@ class PMA_Table { return $this->getDbName($quoted) . '.' . $this->getName($quoted); } - function isView() + function isView($db = null, $table = null) { + if (null !== $db && null !== $table) { + return PMA_Table::_isView($db, $table); + } + if ( strpos($this->get('TABLE TYPE'), 'VIEW') ) { return true; } @@ -161,7 +165,7 @@ class PMA_Table { $this->settings = $table_info; if ( $this->get('TABLE_ROWS') === null ) { - $this->set('TABLE_ROWS', PMA_countRecords($this->getDbName(), + $this->set('TABLE_ROWS', PMA_Table::countRecords($this->getDbName(), $this->getName(), true, true)); } @@ -187,6 +191,35 @@ class PMA_Table { $this->__construct(); } + /** + * Checks if this "table" is a view + * + * @deprecated + * @param string the database name + * @param string the table name + * + * @return boolean whether this is a view + * + * @access public + */ + function _isView($db, $table) { + // maybe we already know if the table is a view + // TODO: see what we could do with the possible existence + // of $table_is_view + if (isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']) { + return true; + } + // old MySQL version: no view + if (PMA_MYSQL_INT_VERSION < 50000) { + return false; + } + if ( false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = \'' . $db . '\' AND `TABLE_NAME` = \'' . $table . '\';')) { + return false; + } else { + return true; + } + } + /** * @TODO add documentation * @@ -258,5 +291,75 @@ class PMA_Table { return $query; } // end function + /** + * Counts and returns (or displays) the number of records in a table + * + * Revision 13 July 2001: Patch for limiting dump size from + * vinay@sanisoft.com & girish@sanisoft.com + * + * @param string the current database name + * @param string the current table name + * @param boolean whether to retain or to displays the result + * @param boolean whether to force an exact count + * + * @return mixed the number of records if retain is required, true else + * + * @access public + */ + function countRecords($db, $table, $ret = false, $force_exact = false) + { + global $err_url, $cfg; + if (!$force_exact) { + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\';'); + $showtable = PMA_DBI_fetch_assoc($result); + $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); + if ($num < $cfg['MaxExactCount']) { + unset($num); + } + PMA_DBI_free_result($result); + } + + $tbl_is_view = PMA_Table::isView($db, $table); + + if (!isset($num)) { + if (! $tbl_is_view) { + $num = PMA_DBI_fetch_value('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); + // necessary? + if (! $num) { + $num = 0; + } + // since counting all rows of a view could be too long + } else { + $result = PMA_DBI_query('SELECT 1 FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT ' . $cfg['MaxExactCount'], null, PMA_DBI_QUERY_STORE); + $num = PMA_DBI_num_rows($result); + } + } + if ($ret) { + return $num; + } else { + // Note: as of PMA 2.8.0, we no longer seem to be using + // PMA_Table::countRecords() in display mode. + echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); + if ($tbl_is_view) { + echo ' ' . sprintf($GLOBALS['strViewMaxExactCount'], $cfg['MaxExactCount'], '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]'); + } + return true; + } + } // end of the 'PMA_Table::countRecords()' function + + /** + * @TODO add documentation + */ + function generateAlter($oldcol, $newcol, $type, $length, + $attribute, $collation, $null, $default, $default_current_timestamp, + $extra, $comment='', $default_orig) + { + $empty_a = array(); + return PMA_backquote($oldcol) . ' ' + . PMA_generateFieldSpec($newcol, $type, $length, $attribute, + $collation, $null, $default, $default_current_timestamp, $extra, + $comment, $empty_a, -1, $default_orig); + } // end function + } ?> \ No newline at end of file diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 8593cf1f8..1ec038df0 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -547,6 +547,7 @@ require_once './libraries/sanitizing.lib.php'; require_once './libraries/Theme.class.php'; require_once './libraries/Theme_Manager.class.php'; require_once './libraries/Config.class.php'; +require_once './libraries/Table.class.php'; @@ -1147,14 +1148,14 @@ if (!defined('PMA_MINIMUM_COMMON')) { // if row count is invalid possibly the table is defect // and this would break left frame; // but we can check row count if this is a view, - // since PMA_countRecords() returns a limited row count + // since PMA_Table::countRecords() returns a limited row count // in this case. - // set this because PMA_countRecords() can use it - $tbl_is_view = PMA_tableIsView($db, $table['Name']); + // set this because PMA_Table::countRecords() can use it + $tbl_is_view = PMA_Table::isView($db, $table['Name']); if ($tbl_is_view) { - $table['Rows'] = PMA_countRecords($db, $table['Name'], + $table['Rows'] = PMA_Table::countRecords($db, $table['Name'], $return = true); } } @@ -1311,90 +1312,6 @@ if (!defined('PMA_MINIMUM_COMMON')) { return $the_crlf; } // end of the 'PMA_whichCrlf()' function - /** - * Checks if this "table" is a view - * - * @param string the database name - * @param string the table name - * - * @return boolean whether this is a view - * - * @access public - */ - function PMA_tableIsView($db, $table) { - // maybe we already know if the table is a view - // TODO: see what we could do with the possible existence - // of $table_is_view - if (isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']) { - return true; - } - // old MySQL version: no view - if (PMA_MYSQL_INT_VERSION < 50000) { - return false; - } - if ( false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = \'' . $db . '\' AND TABLE_NAME = \'' . $table . '\';')) { - return false; - } else { - return true; - } - } - - /** - * Counts and returns (or displays) the number of records in a table - * - * Revision 13 July 2001: Patch for limiting dump size from - * vinay@sanisoft.com & girish@sanisoft.com - * - * @param string the current database name - * @param string the current table name - * @param boolean whether to retain or to displays the result - * @param boolean whether to force an exact count - * - * @return mixed the number of records if retain is required, true else - * - * @access public - */ - function PMA_countRecords($db, $table, $ret = false, $force_exact = false) - { - global $err_url, $cfg; - if (!$force_exact) { - $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\';'); - $showtable = PMA_DBI_fetch_assoc($result); - $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); - if ($num < $cfg['MaxExactCount']) { - unset($num); - } - PMA_DBI_free_result($result); - } - - $tbl_is_view = PMA_tableIsView($db, $table); - - if (!isset($num)) { - if (! $tbl_is_view) { - $num = PMA_DBI_fetch_value('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); - // necessary? - if (! $num) { - $num = 0; - } - // since counting all rows of a view could be too long - } else { - $result = PMA_DBI_query('SELECT 1 FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT ' . $cfg['MaxExactCount'], null, PMA_DBI_QUERY_STORE); - $num = PMA_DBI_num_rows($result); - } - } - if ($ret) { - return $num; - } else { - // Note: as of PMA 2.8.0, we no longer seem to be using - // PMA_countRecords() in display mode. - echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); - if ($tbl_is_view) { - echo ' ' . sprintf($GLOBALS['strViewMaxExactCount'], $cfg['MaxExactCount'], '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]'); - } - return true; - } - } // end of the 'PMA_countRecords()' function - /** * Reloads navigation if needed. * @@ -2505,20 +2422,6 @@ window.parent.updateTableTitle('', '', ' '); diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index d9b4953c4..206a348e6 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -2,6 +2,8 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: +require_once './libraries/Table.class.php'; + /** * Set of functions used to display the records returned by a sql query */ @@ -72,7 +74,7 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total) // 2. Display mode is not "false for all elements" -> updates the // display mode if ($the_disp_mode != 'nnnn000000') { - // 2.0 Print view -> set all elements to FALSE! + // 2.0 Print view -> set all elements to false! if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { $do_display['edit_lnk'] = 'nn'; // no edit link $do_display['del_lnk'] = 'nn'; // no delete link @@ -156,7 +158,7 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total) $the_total = $unlim_num_rows; } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') && (isset($db) && strlen($db) && !empty($table))) { - $the_total = PMA_countRecords($db, $table, TRUE); + $the_total = PMA_Table::countRecords($db, $table, true); } // 4. If navigation bar or sorting fields names urls should be @@ -344,7 +346,7 @@ function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query) if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) { echo '' . "\n"; // no backquote around this message - $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], FALSE) . '\')"'; + $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"'; } ?> @@ -495,7 +497,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ $prev_index = ''; foreach ($ret_keys as $row) { - if ($row['Key_name'] != $prev_index ){ + if ($row['Key_name'] != $prev_index){ $indexes[] = $row['Key_name']; $prev_index = $row['Key_name']; } @@ -562,7 +564,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ echo ''; echo "\n"; } - echo ''; + echo ''; echo "\n"; echo '' . "\n"; echo ''; @@ -580,7 +582,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ // Start of form for multi-rows delete - if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp' ) { + if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') { echo '
' . "\n"; echo PMA_generate_common_hidden_inputs($db, $table, 1); echo '' . "\n"; @@ -616,7 +618,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ . '&goto=' . $goto . '&dontlimitchars=' . (($dontlimitchars) ? 0 : 1); $text_message = '' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . ''; - $text_link = PMA_linkOrButton( $text_url, $text_message, array(), false ); + $text_link = PMA_linkOrButton($text_url, $text_message, array(), false); // ... before the result table if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn') @@ -687,16 +689,16 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ } if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { - require_once('./libraries/transformations.lib.php'); + require_once './libraries/transformations.lib.php'; $GLOBALS['mime_map'] = PMA_getMIME($db, $table); } if ($is_display['sort_lnk'] == '1') { //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt); - $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ?TRUE:FALSE); + $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ? true : false); $select_expr = $analyzed_sql[0]['select_expr_clause']; } else { - $is_join = FALSE; + $is_join = false; } // garvin: See if we have to highlight any header fields of a WHERE query. @@ -742,11 +744,11 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ if (($is_join && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts)) - || ( isset($analyzed_sql[0]['select_expr'][$i]['expr']) + || (isset($analyzed_sql[0]['select_expr'][$i]['expr']) && isset($analyzed_sql[0]['select_expr'][$i]['column']) && $analyzed_sql[0]['select_expr'][$i]['expr'] != $analyzed_sql[0]['select_expr'][$i]['column'] - && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) ) { + && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) { $sort_tbl = PMA_backquote($fields_meta[$i]->table) . ' . '; } else { $sort_tbl = ''; @@ -754,15 +756,15 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ // 2.1.2 Checks if the current column is used to sort the // results if (empty($sort_expression)) { - $is_in_sort = FALSE; + $is_in_sort = false; } else { // field name may be preceded by a space, or any number // of characters followed by a dot (tablename.fieldname) // so do a direct comparison // for the sort expression (avoids problems with queries // like "SELECT id, count(id)..." and clicking to sort - // on id or on count(id) ) - $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? TRUE : FALSE); + // on id or on count(id)) + $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false); } // 2.1.3 Check the field name for backquotes. // If it contains some, it's probably a function column @@ -820,13 +822,13 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; } } - if ( $disp_direction == 'horizontalflipped' - && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ) { + if ($disp_direction == 'horizontalflipped' + && $GLOBALS['cfg']['HeaderFlipType'] == 'css') { $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;'; } $order_link_params['title'] = $GLOBALS['strSort']; $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "
\n") : htmlspecialchars($fields_meta[$i]->name)); - $order_link = PMA_linkOrButton( $order_url, $order_link_content . $order_img, $order_link_params, false, true ); + $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true); if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> @@ -904,7 +906,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ ' . "\n"; - if ( $vertical_display['emptypre'] > 0 ) { + if ($vertical_display['emptypre'] > 0) { echo ' ' . "\n" .'  ' . "\n"; } - foreach ( $vertical_display['desc'] as $val ) { + foreach ($vertical_display['desc'] as $val) { echo $val; } - if ( $vertical_display['emptyafter'] > 0 ) { + if ($vertical_display['emptyafter'] > 0) { echo ' ' . "\n" .'  ' . "\n"; } @@ -1025,13 +1027,13 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { // loic1: pointer code part - echo ' ' . "\n"; + echo ' ' . "\n"; $odd_row = ! $odd_row; $bgcolor = ''; } elseif (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) { $bgcolor = ' bgcolor="#ffffff" '; } else { - $bgcolor = ' bgcolor="' . ($row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'] ) . '" '; + $bgcolor = ' bgcolor="' . ($row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']) . '" '; } @@ -1066,7 +1068,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . '&primary_key=' . $uva_condition . '&sql_query=' . urlencode($url_sql_query) . '&goto=' . urlencode($lnk_goto); - if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) { + if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $edit_str = $GLOBALS['strEdit']; } else { $edit_str = $iconic_spacer . '' . $GLOBALS['strEdit'] . ''; @@ -1085,7 +1087,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . '&SQL=' . $GLOBALS['strExecuteBookmarked'] .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">'; - if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) { + if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $bookmark_go .= $GLOBALS['strExecuteBookmarked']; } else { $bookmark_go .= $iconic_spacer . '' . $GLOBALS['strExecuteBookmarked'] . ''; @@ -1113,9 +1115,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . urlencode($lnk_goto); $js_conf = 'DELETE FROM ' . PMA_jsFormat($table) - . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE)) + . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), false)) . ' LIMIT 1'; - if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) { + if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $del_str = $GLOBALS['strDelete']; } else { $del_str = $iconic_spacer . '' . $GLOBALS['strDelete'] . ''; @@ -1134,7 +1136,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . '&goto=' . urlencode($lnk_goto); $del_query = urlencode('KILL ' . $row[0]); $js_conf = 'KILL ' . $row[0]; - if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) { + if ($GLOBALS['cfg']['PropertiesIconic'] === false) { $del_str = $GLOBALS['strKill']; } else { $del_str = $iconic_spacer . '' . $GLOBALS['strKill'] . ''; @@ -1148,7 +1150,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { $doWriteModifyAt = 'left'; - require('./libraries/display_tbl_links.lib.php'); + require './libraries/display_tbl_links.lib.php'; } // end if (1.3) } // end if (1) @@ -1168,11 +1170,11 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) { - if ($GLOBALS['cfg']['BrowsePointerColor'] == TRUE) { + if ($GLOBALS['cfg']['BrowsePointerColor'] == true) { $column_style .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');" '; } - if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) { + if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { $column_style .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" '; } else { $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" '; @@ -1192,7 +1194,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (file_exists('./libraries/transformations/' . $include_file)) { $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']); - require_once('./libraries/transformations/' . $include_file); + require_once './libraries/transformations/' . $include_file; if (function_exists('PMA_transformation_' . $transformfunction_name)) { $transform_function = 'PMA_transformation_' . $transformfunction_name; @@ -1282,7 +1284,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { // b l o b - } elseif ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) { + } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type, 'BLOB')) { // loic1 : PMA_mysql_fetch_fields returns BLOB in place of // TEXT fields type, however TEXT fields must be displayed // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type @@ -1416,7 +1418,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { $doWriteModifyAt = 'right'; - require('./libraries/display_tbl_links.lib.php'); + require './libraries/display_tbl_links.lib.php'; } // end if (3) if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { @@ -1434,12 +1436,12 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } $column_style_vertical = ''; - if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) { + if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) { $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'; } $column_marker_vertical = ''; - if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) { + if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) { $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');'; } @@ -1455,7 +1457,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (isset($edit_url)) { $vertical_display['edit'][$row_no] .= ' ' . "\n" - . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE) + . PMA_linkOrButton($edit_url, $edit_str, array(), false) . $bookmark_go . ' ' . "\n"; } else { @@ -1464,7 +1466,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (isset($del_url)) { $vertical_display['delete'][$row_no] .= ' ' . "\n" - . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE) + . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false) . ' ' . "\n"; } else { unset($vertical_display['delete'][$row_no]); @@ -1478,7 +1480,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $GLOBALS['url_query'] = $url_query; } - return TRUE; + return true; } // end of the 'PMA_displayTableBody()' function @@ -1623,7 +1625,7 @@ function PMA_displayVerticalTable() echo '' . "\n"; } - return TRUE; + return true; } // end of the 'PMA_displayVerticalTable' function @@ -1716,8 +1718,8 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total) ? $total - 1 : $pos_next - 1; - PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber( $total, 0 ) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')'); - if (PMA_tableIsView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCount']) { + PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber($total, 0) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')'); + if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCount']) { echo '
' . "\n"; echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n"; echo '
' . "\n"; @@ -1763,7 +1765,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) if ($cfgRelation['displaywork']) { if (! isset($table) || ! strlen($table)) { - $exist_rel = FALSE; + $exist_rel = false; } else { $exist_rel = PMA_getForeigners($db, $table, '', 'both'); if ($exist_rel) { @@ -1812,16 +1814,16 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) . '&dontlimitchars=' . $dontlimitchars; $checkall_url = $uncheckall_url . '&checkall=1'; - if ( $disp_direction == 'vertical' ) { - $checkall_params['onclick'] = 'if ( setCheckboxes(\'rowsDeleteForm\', true) ) return false;'; - $uncheckall_params['onclick'] = 'if ( setCheckboxes(\'rowsDeleteForm\', false) ) return false;'; + if ($disp_direction == 'vertical') { + $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;'; + $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;'; } else { - $checkall_params['onclick'] = 'if ( markAllRows(\'rowsDeleteForm\') ) return false;'; - $uncheckall_params['onclick'] = 'if ( unMarkAllRows(\'rowsDeleteForm\') ) return false;'; + $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;'; + $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;'; } - $checkall_link = PMA_linkOrButton( $checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false ); - $uncheckall_link = PMA_linkOrButton( $uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false ); - if ( $disp_direction != 'vertical' ) { + $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false); + $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false); + if ($disp_direction != 'vertical') { echo '' . $GLOBALS['strWithChecked'] . ''; @@ -1831,7 +1833,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) .$uncheckall_link . "\n" .'' . $GLOBALS['strWithChecked'] . '' . "\n"; - if ( $GLOBALS['cfg']['PropertiesIconic'] ) { + if ($GLOBALS['cfg']['PropertiesIconic']) { PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png'); PMA_buttonOrImage('submit_mult', 'mult_submit', diff --git a/libraries/get_foreign.lib.php b/libraries/get_foreign.lib.php index c934e6e79..b4bb7d6a4 100644 --- a/libraries/get_foreign.lib.php +++ b/libraries/get_foreign.lib.php @@ -3,6 +3,8 @@ // vim: expandtab sw=4 ts=4 sts=4: +require_once './libraries/Table.class.php'; + /** * Gets foreign keys in preparation for a drop-down selector * Thanks to @@ -25,7 +27,7 @@ if ($foreigners && isset($foreigners[$field])) { // We could also do the SELECT anyway, with a LIMIT, and ensure that // the current value of the field is one of the choices. - $the_total = PMA_countRecords($foreign_db, $foreign_table, TRUE); + $the_total = PMA_Table::countRecords($foreign_db, $foreign_table, TRUE); if ((isset($override_total) && $override_total == true) || $the_total < $cfg['ForeignKeyMaxLimit']) { // foreign_display can be FALSE if no display field defined: diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index ba1e531c2..a187d5b78 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -2,6 +2,8 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: +require_once './libraries/Table.class.php'; + /** * Set of functions used with the relation and pdf feature */ @@ -582,7 +584,7 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut // native mode is only for column comments so we need a table name if ($mode == 'native' && isset($table) && strlen($table)) { $query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' - . PMA_generateAlterTable($col, $col, '', '', '', '', FALSE, '', FALSE, '', $comment, '', ''); + . PMA_Table::generateAlter($col, $col, '', '', '', '', FALSE, '', FALSE, '', $comment, '', ''); PMA_DBI_try_query($query, null, PMA_DBI_QUERY_STORE); return TRUE; } diff --git a/libraries/tbl_properties_table_info.inc.php b/libraries/tbl_properties_table_info.inc.php index 345dff1cf..94063a2d6 100644 --- a/libraries/tbl_properties_table_info.inc.php +++ b/libraries/tbl_properties_table_info.inc.php @@ -2,6 +2,8 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: +require_once './libraries/Table.class.php'; + /** * extracts table properties from create statement * @@ -75,7 +77,7 @@ if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) { : $showtable['Collation']; if ( null === $showtable['Rows'] ) { - $showtable['Rows'] = PMA_countRecords( $GLOBALS['db'], + $showtable['Rows'] = PMA_Table::countRecords( $GLOBALS['db'], $showtable['Name'], true, true ); } $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0; diff --git a/sql.php b/sql.php index 394cf4239..54a2cc2b8 100644 --- a/sql.php +++ b/sql.php @@ -6,6 +6,7 @@ * Gets some core libraries */ require_once './libraries/common.lib.php'; +require_once './libraries/Table.class.php'; require_once './libraries/tbl_indexes.lib.php'; require_once './libraries/check_user_privileges.lib.php'; require_once './libraries/bookmark.lib.php'; @@ -83,7 +84,7 @@ if (!defined('PMA_CHK_DROP') */ if (isset($find_real_end) && $find_real_end) { - $unlim_num_rows = PMA_countRecords($db, $table, true, true); + $unlim_num_rows = PMA_Table::countRecords($db, $table, true, true); $pos = @((ceil($unlim_num_rows / $session_max_rows) - 1) * $session_max_rows); } /** @@ -453,7 +454,7 @@ else { ) { // "j u s t b r o w s i n g" - $unlim_num_rows = PMA_countRecords($db, $table, true); + $unlim_num_rows = PMA_Table::countRecords($db, $table, true); } else { // n o t " j u s t b r o w s i n g " diff --git a/tbl_alter.php b/tbl_alter.php index 1999574d3..cc92eab89 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -2,6 +2,8 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: +require_once './libraries/Table.class.php'; + /** * Gets some core libraries */ @@ -58,7 +60,7 @@ if (isset($do_save_data)) { $query .= ', CHANGE '; } - $query .= PMA_generateAlterTable($field_orig[$i], $field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], isset($field_collation[$i]) ? $field_collation[$i] : '', $field_null[$i], $field_default[$i], isset($field_default_current_timestamp[$i]), $field_extra[$i], (isset($field_comments[$i]) ? $field_comments[$i] : ''), $field_default_orig[$i]); + $query .= PMA_Table::generateAlter($field_orig[$i], $field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], isset($field_collation[$i]) ? $field_collation[$i] : '', $field_null[$i], $field_default[$i], isset($field_default_current_timestamp[$i]), $field_extra[$i], (isset($field_comments[$i]) ? $field_comments[$i] : ''), $field_default_orig[$i]); } // end for // To allow replication, we first select the db to use and then run queries