Alexander Hartmaier <alex_hartmaier@hotmail.com>
+Zbigniew Lukasiak
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
sub columns_info_for {
my ($self, $table) = @_;
- my $sth = $self->dbh->prepare("SELECT * FROM $table WHERE 1=0");
- $sth->execute;
my %result;
- my @columns = @{$sth->{NAME}};
- for my $i ( 0 .. $#columns ){
- my $type = $sth->{TYPE}->[$i];
- my $info = $self->dbh->type_info($type);
- my %column_info;
- if ( $info ){
+ if ( $self->dbh->can( 'column_info' ) ){
+ my $sth = $self->dbh->column_info( undef, undef, $table, '%' );
+ $sth->execute();
+ while ( my $info = $sth->fetchrow_hashref() ){
+ my %column_info;
$column_info{data_type} = $info->{TYPE_NAME};
$column_info{size} = $info->{COLUMN_SIZE};
$column_info{is_nullable} = $info->{NULLABLE};
- }else{
- $column_info{data_type} = $type;
+ $result{$info->{COLUMN_NAME}} = \%column_info;
+ }
+ }else{
+ my $sth = $self->dbh->prepare("SELECT * FROM $table WHERE 1=0");
+ $sth->execute;
+ my @columns = @{$sth->{NAME}};
+ for my $i ( 0 .. $#columns ){
+ $result{$columns[$i]}{data_type} = $sth->{TYPE}->[$i];
}
- $result{$columns[$i]} = \%column_info;
}
return \%result;
}
$dbh->do("DROP TABLE IF EXISTS artist;");
-$dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255));");
+$dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
my $test_type_info = {
'artistid' => {
- 'data_type' => 'integer',
- 'is_nullable' => 1,
- 'size' => 10
+ 'data_type' => 'INT',
+ 'is_nullable' => 0,
+ 'size' => 11
},
'name' => {
- 'data_type' => 'varchar',
+ 'data_type' => 'VARCHAR',
'is_nullable' => 1,
'size' => 255
- }
+ },
+ 'charfield' => {
+ 'data_type' => 'VARCHAR',
+ 'is_nullable' => 1,
+ 'size' => 10
+ },
};
my $dbh = PgTest->schema->storage->dbh;
-$dbh->do("CREATE TABLE artist (artistid serial PRIMARY KEY, name VARCHAR(255));");
+$dbh->do("CREATE TABLE artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
PgTest::Artist->load_components('PK::Auto::Pg');
my $test_type_info = {
'artistid' => {
- 'data_type' => 'int4',
- 'is_nullable' => 1,
- 'size' => 10
+ 'data_type' => 'integer',
+ 'is_nullable' => 0,
+ 'size' => 4
},
'name' => {
- 'data_type' => 'text',
+ 'data_type' => 'character varying',
+ 'is_nullable' => 1,
+ 'size' => 255
+ },
+ 'charfield' => {
+ 'data_type' => 'character',
'is_nullable' => 1,
- 'size' => 4096
- }
+ 'size' => 10
+ },
};
my $type_info = PgTest->schema->storage->columns_info_for('artist');