$column_number );
}
+# Make sure data_type's that don't need it don't have a 'size' column_info, and
+# set the correct precision for datetime types.
+sub _columns_info_for {
+ my $self = shift;
+ my ($table) = @_;
+
+ my $result = $self->next::method(@_);
+
+ foreach my $col (keys %$result) {
+ my $data_type = $result->{$col}{data_type};
+
+ # these types are fixed size
+ if ($data_type =~
+/^(?:bigint|int8|bigserial|serial8|bit|boolean|bool|box|bytea|cidr|circle|date|double precision|float8|inet|integer|int|int4|line|lseg|macaddr|money|path|point|polygon|real|float4|smallint|int2|serial|serial4|text)\z/i) {
+ delete $result->{$col}{size};
+ }
+
+ # for datetime types, check if it has a precision or not
+ if ($data_type =~ /^(?:interval|time|timestamp)\b/) {
+ my ($precision) = $self->schema->storage->dbh
+ ->selectrow_array(<<EOF, {}, $table, $col);
+SELECT datetime_precision
+FROM information_schema.columns
+WHERE table_name = ? and column_name = ?
+EOF
+
+ if ((not $precision) || $precision !~ /^\d/) {
+ delete $result->{$col}{size};
+ }
+ else {
+ $result->{$col}{size} = $precision;
+ }
+ }
+ }
+
+ return $result;
+}
+
sub _extra_column_info {
my ($self, $info) = @_;
my %extra_info;
use lib qw(t/lib);
use dbixcsl_common_tests;
use Test::More;
+use List::MoreUtils 'apply';
my $dsn = $ENV{DBICTEST_PG_DSN} || '';
my $user = $ENV{DBICTEST_PG_USER} || '';
q{
COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
},
+ # Test to make sure data_types that don't need a size => don't
+ # have one.
+ q{
+ CREATE TABLE pg_loader_test2 (
+ id SERIAL NOT NULL PRIMARY KEY,
+ a_bigint BIGINT,
+ an_int8 INT8,
+ a_bigserial BIGSERIAL,
+ a_serial8 SERIAL8,
+ a_bit BIT,
+ a_bit_varying_with_precision BIT VARYING(8),
+ a_boolean BOOLEAN,
+ a_bool BOOL,
+ a_box BOX,
+ a_bytea BYTEA,
+ a_cidr CIDR,
+ a_circle CIRCLE,
+ a_date DATE,
+ a_double_precision DOUBLE PRECISION,
+ a_float8 FLOAT8,
+ an_inet INET,
+ an_integer INTEGER,
+ an_int INT,
+ an_int4 INT4,
+ an_interval INTERVAL,
+ an_interval_with_precision INTERVAL(2),
+ a_line LINE,
+ an_lseg LSEG,
+ a_macaddr MACADDR,
+ a_money MONEY,
+ a_path PATH,
+ a_point POINT,
+ a_polygon POLYGON,
+ a_real REAL,
+ a_float4 FLOAT4,
+ a_smallint SMALLINT,
+ an_int2 INT2,
+ a_serial SERIAL,
+ a_serial4 SERIAL4,
+ a_text TEXT,
+ a_time TIME,
+ a_time_with_precision TIME(2),
+ a_time_without_time_zone TIME WITHOUT TIME ZONE,
+ a_time_without_time_zone_with_precision TIME(2) WITHOUT TIME ZONE,
+ a_time_with_time_zone TIME WITH TIME ZONE,
+ a_time_with_time_zone_with_precision TIME(2) WITH TIME ZONE,
+ a_timestamp TIMESTAMP,
+ a_timestamp_with_precision TIMESTAMP(2),
+ a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
+ a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
+ a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
+ a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE
+ )
+ },
],
- drop => [ qw/ pg_loader_test1 / ],
- count => 2,
+ drop => [ qw/ pg_loader_test1 pg_loader_test2 / ],
+ count => 49,
run => sub {
my ($schema, $monikers, $classes) = @_;
like $code, qr/^=head2 value\n\n(.+:.+\n)+\nThe Column\n\n/m,
'column comment and attrs';
+
+ my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
+ my @type_columns = grep !/^id\z/, $rsrc->columns;
+ my @without_precision = grep !/_with_precision\z/, @type_columns;
+ my @with_precision = grep /_with_precision\z/, @type_columns;
+ my %with_precision;
+ @with_precision{
+ apply { s/_with_precision\z// } @with_precision
+ } = ();
+
+ for my $col (@without_precision) {
+ my ($data_type) = $col =~ /^an?_(.*)/;
+ ($data_type = uc $data_type) =~ s/_/ /g;
+
+ ok((not exists $rsrc->column_info($col)->{size}),
+ "$data_type " .
+ (exists $with_precision{$col} ? 'without precision ' : '') .
+ "has no 'size' column_info");
+ }
+
+ for my $col (@with_precision) {
+ my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
+ ($data_type = uc $data_type) =~ s/_/ /g;
+
+ ok($rsrc->column_info($col)->{size},
+ "$data_type with precision has a 'size' column_info");
+ }
},
},
);