The branch, master has been updated via 76fe197e4badaae7bd0dad905f5dd57815b61176 (commit) via e86a65d0c2d0bcefec6b4eb15ca81578d0b7004e (commit) via 183c0f437b87d01e155602ed5a724b860465d7de (commit) via 5adf2fb35275ddcb4f64be39d4387928b931af89 (commit) via 57dcfb780a9076d11a1157aa2dc99391ce559d3f (commit) via b604a67c50bf720509e9d3cb26b9c54075a0951f (commit) via 04c5a81b8c9f7e58e459447eda4e1d820fc4399c (commit) via 42df62c050d4f6c186b78a8c0b641f13d2929d61 (commit) via 11acfe2651b59dd48a7248cefa7d1e8df03d60d3 (commit) via cbcde38db1d9c29f58bc86436f8b6f3bbe0717e8 (commit) via 1c356718eaa24f474d43f49c56412d6db79b08c4 (commit) via b231ab407281750ceecc759d748ad5842c9cca9e (commit) via c63474bde1864a01cc6ab307e3728bef5abeec44 (commit) via 398d5abbda60007eb1f291e78cee5c515eb686bf (commit) via bd526dd94e8aa77483a574d598255d73a7198bbe (commit) from 9fd0baaad28f987a12ab92e8036cfc035ad46908 (commit)
- Log ----------------------------------------------------------------- commit 76fe197e4badaae7bd0dad905f5dd57815b61176 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:26:10 2011 +0200
Use PMA_DBI_get_columns
commit e86a65d0c2d0bcefec6b4eb15ca81578d0b7004e Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:26:03 2011 +0200
Whitespace cleanup
commit 183c0f437b87d01e155602ed5a724b860465d7de Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:23:17 2011 +0200
Use PMA_DBI_get_columns
commit 5adf2fb35275ddcb4f64be39d4387928b931af89 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:21:47 2011 +0200
Processing of varbinary fields
commit 57dcfb780a9076d11a1157aa2dc99391ce559d3f Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:20:04 2011 +0200
Fater processing
- use preg_replace return value instead going through string again - use strpos instead of strstr, which is faster and consumes less memory according to PHP docs
commit b604a67c50bf720509e9d3cb26b9c54075a0951f Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:15:13 2011 +0200
Optimize matching
- avoid calling twice same preg_match - do case sensitive match as we have the string in lower case
commit 04c5a81b8c9f7e58e459447eda4e1d820fc4399c Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:09:38 2011 +0200
Make short type also always lowercase
commit 42df62c050d4f6c186b78a8c0b641f13d2929d61 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:09:17 2011 +0200
Make type lowercase everytime
commit 11acfe2651b59dd48a7248cefa7d1e8df03d60d3 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:08:34 2011 +0200
Add testcase for varchar
commit cbcde38db1d9c29f58bc86436f8b6f3bbe0717e8 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:07:13 2011 +0200
Add more testcases
commit 1c356718eaa24f474d43f49c56412d6db79b08c4 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 16:03:56 2011 +0200
Add test case for PMA_extractFieldSpec
commit b231ab407281750ceecc759d748ad5842c9cca9e Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 15:56:56 2011 +0200
Factor out some type matching
commit c63474bde1864a01cc6ab307e3728bef5abeec44 Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 15:47:07 2011 +0200
Use PMA_DBI_get_columns
commit 398d5abbda60007eb1f291e78cee5c515eb686bf Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 15:43:07 2011 +0200
Use PMA_DBI_get_columns
commit bd526dd94e8aa77483a574d598255d73a7198bbe Author: Michal Čihař mcihar@suse.cz Date: Thu Aug 4 15:40:55 2011 +0200
Use PMA_DBI_get_columns
-----------------------------------------------------------------------
Summary of changes: db_datadict.php | 9 +- libraries/common.lib.php | 34 ++++++- tbl_operations.php | 11 +-- tbl_relation.php | 18 ++-- tbl_structure.php | 39 ++------- .../libraries/common/PMA_extractFieldSpec_test.php | 92 ++++++++++++++++++++ 6 files changed, 146 insertions(+), 57 deletions(-) create mode 100644 test/libraries/common/PMA_extractFieldSpec_test.php
diff --git a/db_datadict.php b/db_datadict.php index 531fbe0..04a63df 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -119,8 +119,8 @@ while ($row = PMA_DBI_fetch_row($rowset)) { /** * Gets columns properties */ - $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); - $fields_cnt = PMA_DBI_num_rows($result); + $columns = PMA_DBI_get_columns($db, $table); + $fields_cnt = count($columns);
if (PMA_MYSQL_INT_VERSION < 50025) { // We need this to correctly learn if a TIMESTAMP is NOT NULL, since @@ -181,7 +181,7 @@ while ($row = PMA_DBI_fetch_row($rowset)) { </tr> <?php $odd_row = true; - while ($row = PMA_DBI_fetch_assoc($result)) { + foreach ($columns as $row) {
if ($row['Null'] == '') { $row['Null'] = 'NO'; @@ -284,8 +284,7 @@ while ($row = PMA_DBI_fetch_row($rowset)) { ?> </tr> <?php - } // end while - PMA_DBI_free_result($result); + } // end foreach $count++; ?> </table> diff --git a/libraries/common.lib.php b/libraries/common.lib.php index bdbd124..d566128 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2573,7 +2573,7 @@ function PMA_extractFieldSpec($fieldspec) { // convert to lowercase just to be sure $type = strtolower(chop(substr($fieldspec, 0, $first_bracket_pos))); } else { - $type = $fieldspec; + $type = strtolower($fieldspec); $spec_in_brackets = ''; }
@@ -2624,14 +2624,40 @@ function PMA_extractFieldSpec($fieldspec) { // Increment character index $index++; } // end while + $shorttype = $type; + $binary = false; + $unsigned = false; + $zerofill = false; } else { $enum_set_values = array(); + + /* Create short type name */ + $shorttype = strtolower($fieldspec); + + // strip the "BINARY" attribute, except if we find "BINARY(" because + // this would be a BINARY or VARBINARY field type + if (!preg_match('@binary[(]@', $shorttype)) { + $binary = strpos($shorttype, 'blob') !== false || strpos($shorttype, 'binary') !== false; + $shorttype = preg_replace('@binary@', '', $shorttype); + } else { + $binary = false; + } + $shorttype = preg_replace('@zerofill@', '', $shorttype, -1, $zerofill_cnt); + $zerofill = ($zerofill_cnt > 0); + $shorttype = preg_replace('@unsigned@', '', $shorttype, -1, $unsigned_cnt); + $unsigned = ($unsigned_cnt > 0); + $shorttype = trim($shorttype); + }
return array( 'type' => $type, 'spec_in_brackets' => $spec_in_brackets, - 'enum_set_values' => $enum_set_values + 'enum_set_values' => $enum_set_values, + 'short_type' => $shorttype, + 'binary' => $binary, + 'unsigned' => $unsigned, + 'zerofill' => $zerofill, ); }
@@ -2756,9 +2782,7 @@ function PMA_expandUserString($string, $escape = null, $updates = array()) {
/* Fetch fields list if required */ if (strpos($string, '@FIELDS@') !== false) { - $fields_list = PMA_DBI_fetch_result( - 'SHOW COLUMNS FROM ' . PMA_backquote($GLOBALS['db']) - . '.' . PMA_backquote($GLOBALS['table'])); + $fields_list = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
$field_names = array(); foreach ($fields_list as $field) { diff --git a/tbl_operations.php b/tbl_operations.php index 3e9bdeb..a5a9eef 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -254,12 +254,7 @@ $url_params['back'] = 'tbl_operations.php'; /** * Get columns names */ -$local_query = ' - SHOW COLUMNS - FROM ' . PMA_backquote($GLOBALS['table']) . ' - FROM ' . PMA_backquote($GLOBALS['db']); -$columns = PMA_DBI_fetch_result($local_query, null, 'Field'); -unset($local_query); +$columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
/** * Displays the page @@ -274,8 +269,8 @@ unset($local_query); <select name="order_field"> <?php foreach ($columns as $fieldname) { - echo ' <option value="' . htmlspecialchars($fieldname) . '">' - . htmlspecialchars($fieldname) . '</option>' . "\n"; + echo ' <option value="' . htmlspecialchars($fieldname['Field']) . '">' + . htmlspecialchars($fieldname['Field']) . '</option>' . "\n"; } unset($columns); ?> diff --git a/tbl_relation.php b/tbl_relation.php index e204c80..dcaf323 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -72,9 +72,9 @@ function PMA_generate_dropdown($dropdown_question, $select_name, $choices, $sele }
/** - * Split a string on backquote pairs + * Split a string on backquote pairs * - * @param string original string + * @param string original string * @return array containing the elements (and their surrounding backquotes) * * @access public @@ -97,7 +97,7 @@ function PMA_backquote_split($text) } $elements[] = substr($text, $first_backquote, $second_backquote - $first_backquote + 1); $pos = $second_backquote + 1; - } + } return($elements); }
@@ -376,7 +376,7 @@ if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) { && isset($curr_table[1]) && strtoupper($curr_table[1]) == $tbl_type) { // explicitely ask for non-quoted list of indexed columns - // need to obtain backquoted values to support dots inside values + // need to obtain backquoted values to support dots inside values $selectboxall_foreign = array_merge($selectboxall_foreign, $current_table->getIndexedColumns($backquoted = true)); } } // end while over tables @@ -384,10 +384,10 @@ if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
// Now find out the columns of our $table // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli -$col_rs = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); +$columns = PMA_DBI_get_columns($db, $table);
-if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { - while ($row = PMA_DBI_fetch_assoc($col_rs)) { +if (count($columns) > 0) { + foreach($columns as $row) { $save_row[] = $row; } $saved_row_cnt = count($save_row); @@ -506,9 +506,9 @@ if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { </span> <span class="formelement"> <?php - // For ON DELETE and ON UPDATE, the default action + // For ON DELETE and ON UPDATE, the default action // is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE - // won't display the clause if it's set as RESTRICT. + // won't display the clause if it's set as RESTRICT. PMA_generate_dropdown('ON DELETE', 'on_delete[' . $myfield_md5 . ']', $options_array, diff --git a/tbl_structure.php b/tbl_structure.php index 77e9b39..cce1d46 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -123,10 +123,8 @@ foreach (PMA_Index::getFromTable($table, $db) as $index) { unset($index, $columns, $column_name, $dummy);
// 3. Get fields -$fields_rs = PMA_DRIZZLE - ? PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE) - : PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); -$fields_cnt = PMA_DBI_num_rows($fields_rs); +$fields = PMA_DBI_get_columns($db, $table, !PMA_DRIZZLE); +$fields_cnt = count($fields);
// Get more complete field information // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options @@ -243,7 +241,7 @@ $aryFields = array(); $checked = (!empty($checkall) ? ' checked="checked"' : ''); $save_row = array(); $odd_row = true; -while ($row = PMA_DBI_fetch_assoc($fields_rs)) { +foreach ($fields as $row) { $save_row[] = $row; $rownum++; $aryFields[] = $row['Field']; @@ -262,31 +260,12 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { }
$type_nowrap = ''; - - $binary = 0; - $unsigned = 0; - $zerofill = 0; } else { $type_nowrap = ' nowrap="nowrap"'; - // strip the "BINARY" attribute, except if we find "BINARY(" because - // this would be a BINARY or VARBINARY field type - if (!preg_match('@BINARY[(]@i', $type)) { - $type = preg_replace('@BINARY@i', '', $type); - } - $type = preg_replace('@ZEROFILL@i', '', $type); - $type = preg_replace('@UNSIGNED@i', '', $type); + $type = $extracted_fieldspec['short_type']; if (empty($type)) { $type = ' '; } - - if (!preg_match('@BINARY[(]@i', $row['Type'])) { - $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary'); - } else { - $binary = false; - } - - $unsigned = stristr($row['Type'], 'unsigned'); - $zerofill = stristr($row['Type'], 'zerofill'); }
unset($field_charset); @@ -298,7 +277,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { || substr($type, 0, 8) == 'longtext' || substr($type, 0, 3) == 'set' || substr($type, 0, 4) == 'enum' - ) && !$binary) { + ) && !$extracted_fieldspec['binary']) { if (strpos($type, ' character set ')) { $type = substr($type, 0, strpos($type, ' character set ')); } @@ -319,13 +298,13 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { }
$attribute = ' '; - if ($binary) { + if ($extracted_fieldspec['binary']) { $attribute = 'BINARY'; } - if ($unsigned) { + if ($extracted_fieldspec['unsigned']) { $attribute = 'UNSIGNED'; } - if ($zerofill) { + if ($extracted_fieldspec['zerofill']) { $attribute = 'UNSIGNED ZEROFILL'; }
@@ -575,7 +554,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { </tr> <?php unset($field_charset); -} // end while +} // end foreach
echo '</tbody>' . "\n" .'</table>' . "\n"; diff --git a/test/libraries/common/PMA_extractFieldSpec_test.php b/test/libraries/common/PMA_extractFieldSpec_test.php new file mode 100644 index 0000000..dc3c90d --- /dev/null +++ b/test/libraries/common/PMA_extractFieldSpec_test.php @@ -0,0 +1,92 @@ + +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Test for PMA_checkParameters from common.lib.php + * + * @package phpMyAdmin-test + * @version $Id: PMA_checkParameters_test.php + * @group common.lib-tests + */ + +/* + * Include to test. + */ +require_once 'libraries/common.lib.php'; + +class PMA_extractFieldSpec_test extends PHPUnit_Extensions_OutputTestCase +{ + /** + * @dataProvider provider + */ + public function testParsing($in, $out) + { + $this->assertEquals($out, PMA_extractFieldSpec($in)); + } + + public function provider() + { + return array( + array( + "SET('a', 'b')", + array( + 'type' => 'set', + 'short_type' => 'set', + 'binary' => false, + 'unsigned' => false, + 'zerofill' => false, + 'spec_in_brackets' => "'a', 'b'", + 'enum_set_values' => array('a', 'b'), + ), + ), + array( + "SET(''a', 'b')", + array( + 'type' => 'set', + 'short_type' => 'set', + 'binary' => false, + 'unsigned' => false, + 'zerofill' => false, + 'spec_in_brackets' => "''a', 'b'", + 'enum_set_values' => array("'a", 'b'), + ), + ), + array( + "INT UNSIGNED zerofill", + array( + 'type' => 'int unsigned zerofill', + 'short_type' => 'int', + 'binary' => false, + 'unsigned' => true, + 'zerofill' => true, + 'spec_in_brackets' => '', + 'enum_set_values' => array(), + ), + ), + array( + "VARCHAR(255)", + array( + 'type' => 'varchar', + 'short_type' => 'varchar(255)', + 'binary' => false, + 'unsigned' => false, + 'zerofill' => false, + 'spec_in_brackets' => '255', + 'enum_set_values' => array(), + ), + ), + array( + "VARBINARY(255)", + array( + 'type' => 'varbinary', + 'short_type' => 'varbinary(255)', + 'binary' => false, + 'unsigned' => false, + 'zerofill' => false, + 'spec_in_brackets' => '255', + 'enum_set_values' => array(), + ), + ), + ); + } +}
hooks/post-receive