Skip Menu |

This queue is for tickets about the DBIx-Class-Schema-Loader CPAN distribution.

Report information
The Basics
Id: 46412
Status: resolved
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: Nobody in particular
Requestors: kane [...] cpan.org
Cc:
AdminCc:

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



Subject: Schema::Loader can't tell the difference between strings and functions as default values
See the attached files; for a column that has CURRENT_TIMESTAMP as a default, it's being parsed as the string 'CURRENT_TIMESTAMP', which will fail upon insertion. This information is built up in S::L::DBI::->_columns_info_for. If the input is a function (detectable via SQL_DATA_TYPE perhaps), the value should be prepended with a \: $column_info{default_value} = $this_default_is_a_function ? \$info->{COLUMN_DEF} : $info->{COLUMN_DEF}; If i knew how to detect this portably, a patch would be attached :(
Subject: input.txt
mysql> show create table item; | item | CREATE TABLE `item` ( `item_id` int(10) unsigned NOT NULL auto_increment COMMENT 'The index for the item table', `created` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`item_id`), ) ENGINE=InnoDB AUTO_INCREMENT=5900 DEFAULT CHARSET=latin1 PACK_KEYS=0 |
Subject: output.txt
package My::Schema::Result::Item; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("InflateColumn::DateTime", "Core"); __PACKAGE__->table("item"); __PACKAGE__->add_columns( "item_id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, "created", { data_type => "TIMESTAMP", default_value => "CURRENT_TIMESTAMP", is_nullable => 0, size => 14, }, __PACKAGE__->set_primary_key("item_id");
FYI... The DBI's column_info method is based on the ODBC SQLColumns function. The description of the COLUMN_DEF field of the result of the ODBC SQLColumns function (as documented in http://web.archive.org/web/20070513203826/http://msdn.microsoft.com/library/en- us/odbc/htm/odbcsqlcolumns.asp) says: "The value in this column should be interpreted as a string if it is enclosed in quotation marks." So in theory that's what DBI drivers should return. I'll start a thread on dbi-dev@perl.org to see what the drivers do and discuss a way forward.
It's clear from the thread on dbi-dev: http://perl.markmail.org/search/?q=dbi-dev+column_def#query:dbi- dev%20column_def+page:1+mid:qywi2xaxbe7cxhas+state:results that the column_def value should always be injected literally into the sql.
Unfortunately the DBI column_info does not quote literals and there's no way to tell them apart. For MySQL I made a workaround to interpret CURRENT_TIMESTAMP as a function in current and the dev releases. I think I'll change the code to parse SHOW CREATE TABLE for the default in _extra_column_info instead of this hack, keeping the ticket open until then.
Fixed for all backends on 0.05001 .