From: Rafael Kitover Date: Mon, 10 May 2010 14:14:51 +0000 (-0400) Subject: rewrite "CURRENT_TIMESTAMP" to "current_timestamp" for SQLite X-Git-Tag: 0.07000~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=007e35115cb7dd95dd4205cebb4dee1c8af2a744;p=dbsrgits%2FDBIx-Class-Schema-Loader.git rewrite "CURRENT_TIMESTAMP" to "current_timestamp" for SQLite --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 9ebeede..f77dc4c 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -49,11 +49,15 @@ sub rescan { $self->next::method($schema); } -sub _extra_column_info { - my ($self, $table, $col_name, $info, $dbi_info) = @_; - my %extra_info; +sub _columns_info_for { + my $self = shift; + my ($table) = @_; + + my $result = $self->next::method(@_); my $dbh = $self->schema->storage->dbh; + local $dbh->{FetchHashKeyName} = 'NAME_lc'; + my $has_autoinc = eval { my $get_seq = $self->{_cache}{sqlite_sequence} ||= $dbh->prepare(q{SELECT count(*) FROM sqlite_sequence WHERE name = ?}); @@ -69,12 +73,21 @@ sub _extra_column_info { ); $sth->execute; my $cols = $sth->fetchall_hashref('name'); - if ($cols->{$col_name}{pk}) { - $extra_info{is_auto_increment} = 1; + + while (my ($col_name, $info) = each %$result) { + if ($cols->{$col_name}{pk}) { + $info->{is_auto_increment} = 1; + } + } + } + + while (my ($col, $info) = each %$result) { + if (eval { ${ $info->{default_value} } eq 'CURRENT_TIMESTAMP' }) { + ${ $info->{default_value} } = 'current_timestamp'; } } - return \%extra_info; + return $result; } sub _table_fk_info { diff --git a/t/10sqlite_common.t b/t/10sqlite_common.t index 03145a4..523bd0c 100644 --- a/t/10sqlite_common.t +++ b/t/10sqlite_common.t @@ -51,7 +51,7 @@ my $tester = dbixcsl_common_tests->new( # Date and Time Types 'date' => { data_type => 'date' }, 'timestamp DEFAULT CURRENT_TIMESTAMP' - => { data_type => 'timestamp', default_value => \'CURRENT_TIMESTAMP' }, + => { data_type => 'timestamp', default_value => \'current_timestamp' }, 'time' => { data_type => 'time' }, # String Types