Skip Menu |

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 72633
Status: open
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: 2011 [...] denny.me
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.11010
Fixed in: (no value)



Subject: strict mode breaks deployment of null timestamps
MySQL allows null timestamp columns. However, attempting to deploy these while strict mode is in place causes an error. Example code follows... # SQL: create table if not exists shop_item ( ... updated timestamp null default null, ... ); # MySQL: Show quoted text
mysql> desc shop_item;
+--------------+--------------+------+-----+-------------------+-------- --------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+-------------------+-------- --------+ ... | updated | timestamp | YES | | NULL | | ... +--------------+--------------+------+-----+-------------------+-------- --------+ # DBIC::S::L output: package ShinyCMS::Schema::Result::ShopItem; ... =head2 updated data_type: 'timestamp' datetime_undef_if_invalid: 1 is_nullable: 1 ... __PACKAGE__->add_columns( ... "updated", { data_type => "timestamp", datetime_undef_if_invalid => 1, is_nullable => 1, }, ... ); # Failure to ->deploy() : denny@serenity:~/code/ShinyCMS$ bin/database/deploy-schema DBIx::Class::Schema::deploy(): DBIx::Class::Schema::deploy(): DBI Exception: DBD::mysql::db do failed: Invalid default value for 'updated' [for Statement "CREATE TABLE `shop_item` ( `id` integer NOT NULL auto_increment, `product_type` integer NOT NULL, `name` varchar(200), `code` varchar(100), `description` text, `image` varchar(200), `price` decimal(9, 2) NOT NULL DEFAULT 0.00, `added` timestamp NOT NULL DEFAULT current_timestamp, `updated` timestamp, `hidden` tinyint DEFAULT 0, `discussion` integer, INDEX `shop_item_idx_discussion` (`discussion`), INDEX `shop_item_idx_product_type` (`product_type`), PRIMARY KEY (`id`), UNIQUE `product_code` (`code`), CONSTRAINT `shop_item_fk_discussion` FOREIGN KEY (`discussion`) REFERENCES `discussion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shop_item_fk_product_type` FOREIGN KEY (`product_type`) REFERENCES `shop_product_type` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB"] at bin/database/deploy-schema line 32 (running "CREATE TABLE `shop_item` ( `id` integer NOT NULL auto_increment, `product_type` integer NOT NULL, `name` varchar(200), `code` varchar(100), `description` text, `image` varchar(200), `price` decimal(9, 2) NOT NULL DEFAULT 0.00, `added` timestamp NOT NULL DEFAULT current_timestamp, `updated` timestamp, `hidden` tinyint DEFAULT 0, `discussion` integer, INDEX `shop_item_idx_discussion` (`discussion`), INDEX `shop_item_idx_product_type` (`product_type`), PRIMARY KEY (`id`), UNIQUE `product_code` (`code`), CONSTRAINT `shop_item_fk_discussion` FOREIGN KEY (`discussion`) REFERENCES `discussion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shop_item_fk_product_type` FOREIGN KEY (`product_type`) REFERENCES `shop_product_type` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB") at bin/database/deploy-schema line 32 # Note 1: the SQL in the above error message does not match the 'nullable' state seen in all the previous stages. Specifically, it doesn't include the desired 'null default null' for the 'updated' column. # Note 2: the SQL in the above error message, if pasted into the MySQL command-line client, does not throw an error - even if TRADITIONAL mode is enabled first. Nor does creating a null timestamp column as specified in the first SQL fragment.
On Tue Nov 22 19:24:23 2011, 2010@denny.me wrote: Show quoted text
> MySQL allows null timestamp columns. However, attempting to deploy > these while strict mode is in place causes an error. Example code > follows... > > > > # SQL: > > create table if not exists shop_item ( > ... > updated timestamp null default > null, > ... > ); > > > > # MySQL: >
> mysql> desc shop_item;
> +--------------+--------------+------+-----+------------------- > +-------- > --------+ > | Field | Type | Null | Key | Default | Extra > | > +--------------+--------------+------+-----+------------------- > +-------- > --------+ > ... > | updated | timestamp | YES | | NULL | > | > ... > +--------------+--------------+------+-----+------------------- > +-------- > --------+ > > > > # DBIC::S::L output: > > package ShinyCMS::Schema::Result::ShopItem; > ... > =head2 updated > > data_type: 'timestamp' > datetime_undef_if_invalid: 1 > is_nullable: 1 > ... > > __PACKAGE__->add_columns( > ... > "updated", > { > data_type => "timestamp", > datetime_undef_if_invalid => 1, > is_nullable => 1, > }, > ... > ); > > > > # Failure to ->deploy() : > > denny@serenity:~/code/ShinyCMS$ bin/database/deploy-schema > DBIx::Class::Schema::deploy(): DBIx::Class::Schema::deploy(): DBI > Exception: DBD::mysql::db do failed: Invalid default value for > 'updated' > [for Statement "CREATE TABLE `shop_item` ( > `id` integer NOT NULL auto_increment, > `product_type` integer NOT NULL, > `name` varchar(200), > `code` varchar(100), > `description` text, > `image` varchar(200), > `price` decimal(9, 2) NOT NULL DEFAULT 0.00, > `added` timestamp NOT NULL DEFAULT current_timestamp, > `updated` timestamp, > `hidden` tinyint DEFAULT 0, > `discussion` integer, > INDEX `shop_item_idx_discussion` (`discussion`), > INDEX `shop_item_idx_product_type` (`product_type`), > PRIMARY KEY (`id`), > UNIQUE `product_code` (`code`), > CONSTRAINT `shop_item_fk_discussion` FOREIGN KEY (`discussion`) > REFERENCES `discussion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `shop_item_fk_product_type` FOREIGN KEY (`product_type`) > REFERENCES `shop_product_type` (`id`) ON DELETE CASCADE ON UPDATE > CASCADE > ) ENGINE=InnoDB"] at bin/database/deploy-schema line 32 > (running "CREATE TABLE `shop_item` ( > `id` integer NOT NULL auto_increment, > `product_type` integer NOT NULL, > `name` varchar(200), > `code` varchar(100), > `description` text, > `image` varchar(200), > `price` decimal(9, 2) NOT NULL DEFAULT 0.00, > `added` timestamp NOT NULL DEFAULT current_timestamp, > `updated` timestamp, > `hidden` tinyint DEFAULT 0, > `discussion` integer, > INDEX `shop_item_idx_discussion` (`discussion`), > INDEX `shop_item_idx_product_type` (`product_type`), > PRIMARY KEY (`id`), > UNIQUE `product_code` (`code`), > CONSTRAINT `shop_item_fk_discussion` FOREIGN KEY (`discussion`) > REFERENCES `discussion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `shop_item_fk_product_type` FOREIGN KEY (`product_type`) > REFERENCES `shop_product_type` (`id`) ON DELETE CASCADE ON UPDATE > CASCADE > ) ENGINE=InnoDB") at bin/database/deploy-schema line 32 > > > > # Note 1: the SQL in the above error message does not match the > 'nullable' state seen in all the previous stages. Specifically, it > doesn't include the desired 'null default null' for the 'updated' > column. > > # Note 2: the SQL in the above error message, if pasted into the MySQL > command-line client, does not throw an error - even if TRADITIONAL > mode > is enabled first. Nor does creating a null timestamp column as > specified in the first SQL fragment.
I'm a bit confused by this report, so several questions: 1) Where are you turning on strict mode in MySQL, and why are you claiming its relevant, does deploy work fine if its not on? 2) Allowing "null" is the default state for columns, thus we only ever pass "not null" when is_nullable is 0, and otherwise leave the default, does this work differently under MySQL/strict? 3) Your Result class does not set the default value, with: default_value => \'NULL' so the deploy will also not send "DEFAULT NULL" in the create. If you still feel it is an SQLT bug, please create a smaller runnable example by hand that sets up as above and still causes a problem, and attach it to this bug report
Subject: Re: [rt.cpan.org #72633] strict mode breaks deployment of null timestamps
Date: Wed, 23 Nov 2011 13:54:39 +0000
To: bug-SQL-Translator [...] rt.cpan.org
From: Denny <2011 [...] denny.me>
Hi Jess, thanks for the swift reply... On Wed, 2011-11-23 at 08:34 -0500, Jess Robinson via RT wrote: Show quoted text
> 1) Where are you turning on strict mode in MySQL
In my Catalyst application config (set_strict_mode) which I think is a DBIx::Class setting or macro to enable various ANSI-compliance modes in MySQL. (I was told to file this bug against SQLT when I reported the problem I was seeing in the DBIC IRC channel, but my apologies if this turns out to be a problem elsewhere. I don't know much about what SQLT does, but I'm assuming it makes ->deploy work on various platforms.) Show quoted text
> and why are you claiming its relevant, does deploy work fine if its > not on?
Yes. Specifically, it's the MySQL TRADITIONAL mode that this deploy doesn't like, just setting that one mode is enough to break it. Show quoted text
> 2) Allowing "null" is the default state for columns, thus we only ever > pass "not null" when is_nullable is 0, and otherwise leave the default, > does this work differently under MySQL/strict?
Yeah, I think so. MySQL timestamps in general, rather than strict mode in particular: "TIMESTAMP columns are NOT NULL by default, cannot contain NULL values, and assigning NULL assigns the current timestamp. However, a TIMESTAMP column can be permitted to contain NULL by declaring it with the NULL attribute." (From http://dev.mysql.com/doc/refman/5.1/en/timestamp.html ) Show quoted text
> 3) Your Result class does not set the default value, with: > default_value => \'NULL' so the deploy will also not send "DEFAULT > NULL" in the create.
*nod* Is that (potentially) a problem in a different module? DBIC::S::L maybe? The Result class is autogenerated using the Catalyst create script. Show quoted text
> If you still feel it is an SQLT bug, please create a smaller runnable > example by hand that sets up as above and still causes a problem, and > attach it to this bug report
Does the above help isolate the problem, or would you still like me to build the example? Regards, Denny
On Wed Nov 23 08:54:56 2011, 2011@denny.me wrote: Show quoted text
> Does the above help isolate the problem, or would you still like me to > build the example? >
Not particularly no... Can you write a short script with a single-table deploy which illustrates the problem? Thanks!