2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * extracts table properties from create statement
6 * @todo should be handled by class Table
7 * @todo this should be recoded as functions, to avoid messing with global variables
15 require_once './libraries/Table.class.php';
20 require_once './libraries/common.inc.php';
23 PMA_checkParameters(array('db', 'table'));
26 * Defining global variables, in case this script is included by a function.
27 * This is necessary because this script can be included by libraries/header.inc.php.
29 global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
30 $table_info_num_rows, $auto_increment;
33 * Gets table informations
35 // Seems we need to do this in MySQL 5.0.2,
36 // otherwise error #1046, no database selected
37 PMA_DBI_select_db($GLOBALS['db']);
39 // The 'show table' statement works correct since 3.23.03
40 $table_info_result = PMA_DBI_query(
41 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
42 null, PMA_DBI_QUERY_STORE
);
44 // need this test because when we are creating a table, we get 0 rows
45 // from the SHOW TABLE query
46 // and we don't want to mess up the $tbl_type coming from the form
48 if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
49 $showtable = PMA_DBI_fetch_assoc($table_info_result);
50 PMA_DBI_free_result($table_info_result);
51 unset($table_info_result);
53 if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
54 $showtable['Type'] =& $showtable['Engine'];
56 if (PMA_Table
::isView($GLOBALS['db'], $GLOBALS['table'])) {
58 $tbl_type = $GLOBALS['strView'];
62 $tbl_type = isset($showtable['Type'])
63 ?
strtoupper($showtable['Type'])
65 // a new comment could be coming from tbl_operations.php
66 // and we want to show it in the header
67 if (isset($submitcomment) && isset($comment)) {
68 $show_comment = $comment;
70 $show_comment = isset($showtable['Comment'])
71 ?
$showtable['Comment']
75 $tbl_collation = empty($showtable['Collation'])
77 : $showtable['Collation'];
79 if (null === $showtable['Rows']) {
80 $showtable['Rows'] = PMA_Table
::countRecords($GLOBALS['db'],
81 $showtable['Name'], true, true);
83 $table_info_num_rows = isset($showtable['Rows']) ?
$showtable['Rows'] : 0;
84 $auto_increment = isset($showtable['Auto_increment'])
85 ?
$showtable['Auto_increment']
88 $create_options = isset($showtable['Create_options'])
89 ?
explode(' ', $showtable['Create_options'])
92 // export create options by its name as variables into gloabel namespace
93 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
95 foreach ($create_options as $each_create_option) {
96 $each_create_option = explode('=', $each_create_option);
97 if (isset($each_create_option[1])) {
98 $
$each_create_option[0] = $each_create_option[1];
101 // we need explicit DEFAULT value here (different from '0')
102 $pack_keys = (!isset($pack_keys) ||
strlen($pack_keys) == 0) ?
'DEFAULT' : $pack_keys;
103 unset($create_options, $each_create_option);