use DBD::Pg 1.32;
use DBIx::DBSchema::DBD;
-$VERSION = '0.15';
+$VERSION = '0.16';
@ISA = qw(DBIx::DBSchema::DBD);
die "DBD::Pg version 1.32 or 1.41 (or later) required--".
map {
+ my $type = $_->{'typname'};
+ $type = 'char' if $type eq 'bpchar';
+
+ my $len = '';
+ if ( $_->{attlen} == -1 && $_->{atttypmod} != -1
+ && $_->{typname} ne 'text' ) {
+ $len = $_->{atttypmod} - 4;
+ if ( $_->{typname} eq 'numeric' ) {
+ $len = ($len >> 16). ','. ($len & 0xffff);
+ }
+ }
+
my $default = '';
if ( $_->{atthasdef} ) {
my $attnum = $_->{attnum};
$d_sth->execute or die $d_sth->errstr;
$default = $d_sth->fetchrow_arrayref->[0];
- };
- my $len = '';
- if ( $_->{attlen} == -1 && $_->{atttypmod} != -1
- && $_->{typname} ne 'text' ) {
- $len = $_->{atttypmod} - 4;
- if ( $_->{typname} eq 'numeric' ) {
- $len = ($len >> 16). ','. ($len & 0xffff);
+ if ( _type_needs_quoting($type) ) {
+ $default =~ s/::([\w ]+)$//; #save typecast info?
+ if ( $default =~ /^'(.*)'$/ ) {
+ $default = $1;
+ $default = \"''" if $default eq '';
+ } else {
+ my $value = $default;
+ $default = \$value;
+ }
+ } elsif ( $default =~ /^[a-z]/i ) { #sloppy, but it'll do
+ $default = \$default;
}
- }
- my $type = $_->{'typname'};
- $type = 'char' if $type eq 'bpchar';
+ }
[
$_->{'attname'},
}
-sub _column_value_needs_quoting {
+sub column_value_needs_quoting {
my($proto, $col) = @_;
- $col->type !~ m{^(
- int(?:2|4|8)?
- | smallint
- | integer
- | bigint
- | (?:numeric|decimal)(?:\(\d+(?:\s*\,\s*\d+\))?)?
- | real
- | double\s+precision
- | float(?:\(\d+\))?
- | serial(?:4|8)?
- | bigserial
- )$}ix;
+ _type_needs_quoting($col->type);
+}
+
+sub _type_needs_quoting {
+ my $type = shift;
+ $type !~ m{^(
+ int(?:2|4|8)?
+ | smallint
+ | integer
+ | bigint
+ | (?:numeric|decimal)(?:\(\d+(?:\s*\,\s*\d+\))?)?
+ | real
+ | double\s+precision
+ | float(?:\(\d+\))?
+ | serial(?:4|8)?
+ | bigserial
+ )$}ix;
}
Copyright (c) 2000 Ivan Kohler
Copyright (c) 2000 Mail Abuse Prevention System LLC
-Copyright (c) 2009 Freeside Internet Services, Inc.
+Copyright (c) 2009-2010 Freeside Internet Services, Inc.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.