From 69beffffee402549d9c64916dac9912618bd9812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 9 May 2014 09:15:34 +0200 Subject: [PATCH] Simplify code for getting field flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's define array of flag names, so that we don't have to duplicate the code for each flag. Signed-off-by: Michal Čihař --- libraries/dbi/DBIMysqli.class.php | 71 ++++++++++++------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/libraries/dbi/DBIMysqli.class.php b/libraries/dbi/DBIMysqli.class.php index 2dc595e674..17da3f0703 100644 --- a/libraries/dbi/DBIMysqli.class.php +++ b/libraries/dbi/DBIMysqli.class.php @@ -46,6 +46,26 @@ if (! defined('MYSQLI_TYPE_VARCHAR')) { define('MYSQLI_TYPE_VARCHAR', 15); } +/** + * Names of field flags. + */ +$pma_flag_names = array( + MYSQLI_UNIQUE_KEY_FLAG => 'unique', + MYSQLI_NUM_FLAG => 'num', + MYSQLI_PART_KEY_FLAG => 'part_key', + MYSQLI_SET_FLAG => 'set', + MYSQLI_TIMESTAMP_FLAG => 'timestamp', + MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment', + MYSQLI_ENUM_FLAG => 'enum', + MYSQLI_ZEROFILL_FLAG => 'zerofill', + MYSQLI_UNSIGNED_FLAG => 'unsigned', + MYSQLI_BLOB_FLAG => 'blob', + MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key', + MYSQLI_UNIQUE_KEY_FLAG => 'unique_key', + MYSQLI_PRI_KEY_FLAG => 'primary_key', + MYSQLI_NOT_NULL_FLAG => 'not_null', +); + /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Interface to the improved MySQL extension (MySQLi) @@ -697,27 +717,11 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension $type = $f->type; $charsetnr = $f->charsetnr; $f = $f->flags; - $flags = ''; - if ($f & MYSQLI_UNIQUE_KEY_FLAG) { - $flags .= 'unique '; - } - if ($f & MYSQLI_NUM_FLAG) { - $flags .= 'num '; - } - if ($f & MYSQLI_PART_KEY_FLAG) { - $flags .= 'part_key '; - } - if ($f & MYSQLI_SET_FLAG) { - $flags .= 'set '; - } - if ($f & MYSQLI_TIMESTAMP_FLAG) { - $flags .= 'timestamp '; - } - if ($f & MYSQLI_AUTO_INCREMENT_FLAG) { - $flags .= 'auto_increment '; - } - if ($f & MYSQLI_ENUM_FLAG) { - $flags .= 'enum '; + $flags = array(); + foreach ($pma_flag_names as $flag => $name) { + if ($f & $flag) { + $flags[] = $name; + } } // See http://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html: // to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG @@ -730,30 +734,9 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension || $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING) && 63 == $charsetnr ) { - $flags .= 'binary '; + $flags[] = 'binary'; } - if ($f & MYSQLI_ZEROFILL_FLAG) { - $flags .= 'zerofill '; - } - if ($f & MYSQLI_UNSIGNED_FLAG) { - $flags .= 'unsigned '; - } - if ($f & MYSQLI_BLOB_FLAG) { - $flags .= 'blob '; - } - if ($f & MYSQLI_MULTIPLE_KEY_FLAG) { - $flags .= 'multiple_key '; - } - if ($f & MYSQLI_UNIQUE_KEY_FLAG) { - $flags .= 'unique_key '; - } - if ($f & MYSQLI_PRI_KEY_FLAG) { - $flags .= 'primary_key '; - } - if ($f & MYSQLI_NOT_NULL_FLAG) { - $flags .= 'not_null '; - } - return trim($flags); + return implode(' ', $flags); } } ?>