The branch, master has been updated
via d29cf3227dd8d2827f55b0661dfd505345f49df3 (commit)
via 236eb052bc40450d6e45e3aa5d0c7933db2059a4 (commit)
via 542738dd8807f6a3e01afd0286213f02e07406bb (commit)
from 76fe197e4badaae7bd0dad905f5dd57815b61176 (commit)
- Log -----------------------------------------------------------------
commit d29cf3227dd8d2827f55b0661dfd505345f49df3
Author: Michal Čihař <mcihar(a)suse.cz>
Date: Thu Aug 4 16:38:42 2011 +0200
Use PMA_extractFieldSpec instead of own code in export plugins
commit 236eb052bc40450d6e45e3aa5d0c7933db2059a4
Author: Michal Čihař <mcihar(a)suse.cz>
Date: Thu Aug 4 16:36:23 2011 +0200
Use PMA_extractFieldSpec instead of own code
commit 542738dd8807f6a3e01afd0286213f02e07406bb
Author: Michal Čihař <mcihar(a)suse.cz>
Date: Thu Aug 4 16:33:34 2011 +0200
Export print_type and make it usable for set/enum as well
-----------------------------------------------------------------------
Summary of changes:
db_datadict.php | 25 +++-----------
libraries/common.lib.php | 20 ++++++------
libraries/export/htmlword.php | 34 +------------------
libraries/export/latex.php | 26 +--------------
libraries/export/odt.php | 31 +-----------------
tbl_structure.php | 23 ++++++-------
.../libraries/common/PMA_extractFieldSpec_test.php | 18 +++++-----
7 files changed, 41 insertions(+), 136 deletions(-)
diff --git a/db_datadict.php b/db_datadict.php
index 04a63df..1c46cbb 100644
--- a/db_datadict.php
+++ b/db_datadict.php
@@ -186,37 +186,24 @@ while ($row = PMA_DBI_fetch_row($rowset)) {
if ($row['Null'] == '') {
$row['Null'] = 'NO';
}
- $type = $row['Type'];
+ $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
// reformat mysql query output
// set or enum types: slashes single quotes inside options
- if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
- $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
- $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
+ if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
$type_nowrap = '';
- $binary = 0;
- $unsigned = 0;
- $zerofill = 0;
} else {
- $binary = stristr($row['Type'], 'binary');
- $unsigned = stristr($row['Type'], 'unsigned');
- $zerofill = stristr($row['Type'], 'zerofill');
$type_nowrap = ' nowrap="nowrap"';
- $type = preg_replace('@BINARY@i', '', $type);
- $type = preg_replace('@ZEROFILL@i', '', $type);
- $type = preg_replace('@UNSIGNED@i', '', $type);
- if (empty($type)) {
- $type = ' ';
- }
}
+ $type = htmlspecialchars($extracted_fieldspec['print_type']);
$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';
}
if (! isset($row['Default'])) {
diff --git a/libraries/common.lib.php b/libraries/common.lib.php
index d566128..352446b 100644
--- a/libraries/common.lib.php
+++ b/libraries/common.lib.php
@@ -2624,29 +2624,29 @@ function PMA_extractFieldSpec($fieldspec) {
// Increment character index
$index++;
} // end while
- $shorttype = $type;
+ $printtype = $type . '(' . str_replace("','", "', '", $spec_in_brackets) . ')';
$binary = false;
$unsigned = false;
$zerofill = false;
} else {
$enum_set_values = array();
- /* Create short type name */
- $shorttype = strtolower($fieldspec);
+ /* Create printable type name */
+ $printtype = 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);
+ if (!preg_match('@binary[\(]@', $printtype)) {
+ $binary = strpos($printtype, 'blob') !== false || strpos($printtype, 'binary') !== false;
+ $printtype = preg_replace('@binary@', '', $printtype);
} else {
$binary = false;
}
- $shorttype = preg_replace('@zerofill@', '', $shorttype, -1, $zerofill_cnt);
+ $printtype = preg_replace('@zerofill@', '', $printtype, -1, $zerofill_cnt);
$zerofill = ($zerofill_cnt > 0);
- $shorttype = preg_replace('@unsigned@', '', $shorttype, -1, $unsigned_cnt);
+ $printtype = preg_replace('@unsigned@', '', $printtype, -1, $unsigned_cnt);
$unsigned = ($unsigned_cnt > 0);
- $shorttype = trim($shorttype);
+ $printtype = trim($printtype);
}
@@ -2654,7 +2654,7 @@ function PMA_extractFieldSpec($fieldspec) {
'type' => $type,
'spec_in_brackets' => $spec_in_brackets,
'enum_set_values' => $enum_set_values,
- 'short_type' => $shorttype,
+ 'print_type' => $printtype,
'binary' => $binary,
'unsigned' => $unsigned,
'zerofill' => $zerofill,
diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php
index 707bc77..5c7a84e 100644
--- a/libraries/export/htmlword.php
+++ b/libraries/export/htmlword.php
@@ -273,40 +273,10 @@ if (isset($plugin_list)) {
foreach ($columns as $column) {
$schema_insert = '<tr class="print-category">';
- $type = $column['Type'];
- // reformat mysql query output
- // set or enum types: slashes single quotes inside options
- if (preg_match('/^(set|enum)\((.+)\)$/i', $type, $tmp)) {
- $tmp[2] = substr(preg_replace('/([^,])\'\'/', '\\1\\\'', ',' . $tmp[2]), 1);
- $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
- $type_nowrap = '';
-
- $binary = 0;
- $unsigned = 0;
- $zerofill = 0;
- } else {
- $type_nowrap = ' nowrap="nowrap"';
- $type = preg_replace('/BINARY/i', '', $type);
- $type = preg_replace('/ZEROFILL/i', '', $type);
- $type = preg_replace('/UNSIGNED/i', '', $type);
- if (empty($type)) {
- $type = ' ';
- }
- $binary = preg_match('/BINARY/i', $column['Type']);
- $unsigned = preg_match('/UNSIGNED/i', $column['Type']);
- $zerofill = preg_match('/ZEROFILL/i', $column['Type']);
- }
- $attribute = ' ';
- if ($binary) {
- $attribute = 'BINARY';
- }
- if ($unsigned) {
- $attribute = 'UNSIGNED';
- }
- if ($zerofill) {
- $attribute = 'UNSIGNED ZEROFILL';
- }
+ $extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
+ $type = $extracted_fieldspec['print_type'];
+
if (! isset($column['Default'])) {
if ($column['Null'] != 'NO') {
$column['Default'] = 'NULL';
diff --git a/libraries/export/latex.php b/libraries/export/latex.php
index cbf5141..54ee504 100644
--- a/libraries/export/latex.php
+++ b/libraries/export/latex.php
@@ -391,30 +391,8 @@ if (isset($plugin_list)) {
$fields = PMA_DBI_get_columns($db, $table);
foreach ($fields as $row) {
- $type = $row['Type'];
- // reformat mysql query output
- // set or enum types: slashes single quotes inside options
- if (preg_match('/^(set|enum)\((.+)\)$/i', $type, $tmp)) {
- $tmp[2] = substr(preg_replace('/([^,])\'\'/', '\\1\\\'', ',' . $tmp[2]), 1);
- $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
- $type_nowrap = '';
-
- $binary = 0;
- $unsigned = 0;
- $zerofill = 0;
- } else {
- $type_nowrap = ' nowrap="nowrap"';
- $type = preg_replace('/BINARY/i', '', $type);
- $type = preg_replace('/ZEROFILL/i', '', $type);
- $type = preg_replace('/UNSIGNED/i', '', $type);
- if (empty($type)) {
- $type = ' ';
- }
-
- $binary = preg_match('/BINARY/i', $row['Type']);
- $unsigned = preg_match('/UNSIGNED/i', $row['Type']);
- $zerofill = preg_match('/ZEROFILL/i', $row['Type']);
- }
+ $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
+ $type = $extracted_fieldspec['print_type'];
if (!isset($row['Default'])) {
if ($row['Null'] != 'NO') {
$row['Default'] = 'NULL';
diff --git a/libraries/export/odt.php b/libraries/export/odt.php
index e02f8a6..16867a6 100644
--- a/libraries/export/odt.php
+++ b/libraries/export/odt.php
@@ -317,36 +317,9 @@ if (isset($plugin_list)) {
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
+ $extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
+ $type = $extracted_fieldspec['print_type'];
- $field_name = $column['Field'];
- $GLOBALS['odt_buffer'] .= '<table:table-row>';
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
- . '</table:table-cell>';
- // reformat mysql query output
- // set or enum types: slashes single quotes inside options
- $type = $column['Type'];
- if (preg_match('/^(set|enum)\((.+)\)$/i', $type, $tmp)) {
- $tmp[2] = substr(preg_replace('/([^,])\'\'/', '\\1\\\'', ',' . $tmp[2]), 1);
- $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
- $type_nowrap = '';
-
- $binary = 0;
- $unsigned = 0;
- $zerofill = 0;
- } else {
- $type_nowrap = ' nowrap="nowrap"';
- $type = preg_replace('/BINARY/i', '', $type);
- $type = preg_replace('/ZEROFILL/i', '', $type);
- $type = preg_replace('/UNSIGNED/i', '', $type);
- if (empty($type)) {
- $type = ' ';
- }
-
- $binary = preg_match('/BINARY/i', $column['Type']);
- $unsigned = preg_match('/UNSIGNED/i', $column['Type']);
- $zerofill = preg_match('/ZEROFILL/i', $column['Type']);
- }
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($type) . '</text:p>'
. '</table:table-cell>';
diff --git a/tbl_structure.php b/tbl_structure.php
index cce1d46..b104e79 100644
--- a/tbl_structure.php
+++ b/tbl_structure.php
@@ -250,22 +250,19 @@ foreach ($fields as $row) {
$extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
- $type = $extracted_fieldspec['type'] . '(' .
- str_replace("','", "', '", $extracted_fieldspec['spec_in_brackets']) . ')';
-
- // for the case ENUM('–','“')
- $type = htmlspecialchars($type);
- if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {
- $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
- }
-
$type_nowrap = '';
} else {
$type_nowrap = ' nowrap="nowrap"';
- $type = $extracted_fieldspec['short_type'];
- if (empty($type)) {
- $type = ' ';
- }
+ }
+ $type = $extracted_fieldspec['print_type'];
+ if (empty($type)) {
+ $type = ' ';
+ }
+ // for the case ENUM('–','“')
+ $type = htmlspecialchars($type);
+ // in case it is too long
+ if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {
+ $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
}
unset($field_charset);
diff --git a/test/libraries/common/PMA_extractFieldSpec_test.php b/test/libraries/common/PMA_extractFieldSpec_test.php
index dc3c90d..622a754 100644
--- a/test/libraries/common/PMA_extractFieldSpec_test.php
+++ b/test/libraries/common/PMA_extractFieldSpec_test.php
@@ -28,26 +28,26 @@ class PMA_extractFieldSpec_test extends PHPUnit_Extensions_OutputTestCase
{
return array(
array(
- "SET('a', 'b')",
+ "SET('a','b')",
array(
'type' => 'set',
- 'short_type' => 'set',
+ 'print_type' => "set('a', 'b')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
- 'spec_in_brackets' => "'a', 'b'",
+ 'spec_in_brackets' => "'a','b'",
'enum_set_values' => array('a', 'b'),
),
),
array(
- "SET('\'a', 'b')",
+ "SET('\'a','b')",
array(
'type' => 'set',
- 'short_type' => 'set',
+ 'print_type' => "set('\'a', 'b')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
- 'spec_in_brackets' => "'\'a', 'b'",
+ 'spec_in_brackets' => "'\'a','b'",
'enum_set_values' => array("'a", 'b'),
),
),
@@ -55,7 +55,7 @@ class PMA_extractFieldSpec_test extends PHPUnit_Extensions_OutputTestCase
"INT UNSIGNED zerofill",
array(
'type' => 'int unsigned zerofill',
- 'short_type' => 'int',
+ 'print_type' => 'int',
'binary' => false,
'unsigned' => true,
'zerofill' => true,
@@ -67,7 +67,7 @@ class PMA_extractFieldSpec_test extends PHPUnit_Extensions_OutputTestCase
"VARCHAR(255)",
array(
'type' => 'varchar',
- 'short_type' => 'varchar(255)',
+ 'print_type' => 'varchar(255)',
'binary' => false,
'unsigned' => false,
'zerofill' => false,
@@ -79,7 +79,7 @@ class PMA_extractFieldSpec_test extends PHPUnit_Extensions_OutputTestCase
"VARBINARY(255)",
array(
'type' => 'varbinary',
- 'short_type' => 'varbinary(255)',
+ 'print_type' => 'varbinary(255)',
'binary' => false,
'unsigned' => false,
'zerofill' => false,
hooks/post-receive
--
phpMyAdmin