SHOW CREATE TABLE doesn't show default values

Bug #316232 reported by Stewart Smith
2
Affects Status Importance Assigned to Milestone
Drizzle
Fix Released
Medium
Toru Maesaka

Bug Description

drizzle> CREATE TABLE t1 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL);
Query OK, 0 rows affected (0.02 sec)

drizzle> SHOW CREATE TABLE t1;
+-------+-----------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
  `col1` int NOT NULL,
  `col2` varchar(6) NOT NULL
) ENGINE=InnoDB |
+-------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

See also strict test (result will need to be changed when this is fixed)

Revision history for this message
Jay Pipes (jaypipes) wrote :

Confirmed, on both MyISAM and InnoDB:

drizzle> CREATE TABLE t10 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL);
Query OK, 0 rows affected (0.02 sec)

drizzle> SHOW CREATE TABLE t10\g
+-------+------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------+
| t10 | CREATE TABLE `t10` (
  `col1` int NOT NULL,
  `col2` varchar(6) NOT NULL
) ENGINE=InnoDB |
+-------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

drizzle> CREATE TABLE t11 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL)engine=MyISAM;
Query OK, 0 rows affected (0.05 sec)

drizzle> SHOW CREATE TABLE t11\g
+-------+------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------+
| t11 | CREATE TABLE `t11` (
  `col1` int NOT NULL,
  `col2` varchar(6) NOT NULL
) ENGINE=MyISAM |
+-------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Changed in drizzle:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Toru Maesaka (tmaesaka) wrote :

Started looking into this. So far I've found this crazy evaluation in drizzled/show.cc / get_field_default_value():

has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
field->unireg_check != Field::NEXT_NUMBER
&& has_now_default);

to evaluate to false when it needs to be true for further processing. If I manage to fix this I'll rewrite it to be more readable ;)

Revision history for this message
Toru Maesaka (tmaesaka) wrote :

Found the problem, will write the patch and push shortly.

Changed in drizzle:
assignee: nobody → tmaesaka
Revision history for this message
Toru Maesaka (tmaesaka) wrote :

Fixed in my tree and it is proposed for merge at the moment. Here's my result with MyISAM and InnoDB:

drizzle> CREATE TABLE myisam_tbl (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL)engine=MyISAM;
Query OK, 0 rows affected (0.01 sec)

drizzle> show create table myisam_tbl;
+------------+--------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------+--------------------------------------------------------------------------------------------------------------+
| myisam_tbl | CREATE TABLE `myisam_tbl` (
  `col1` int NOT NULL DEFAULT '99',
  `col2` varchar(6) NOT NULL
) ENGINE=MyISAM |
+------------+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

drizzle> CREATE TABLE innodb_tbl (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL)engine=InnoDB;
Query OK, 0 rows affected (0.02 sec)

drizzle> show create table innodb_tbl;
+------------+--------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------+--------------------------------------------------------------------------------------------------------------+
| innodb_tbl | CREATE TABLE `innodb_tbl` (
  `col1` int NOT NULL DEFAULT '99',
  `col2` varchar(6) NOT NULL
) ENGINE=InnoDB |
+------------+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Changed in drizzle:
status: Confirmed → Fix Committed
Changed in drizzle:
milestone: none → cirrus
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.