From: ivan Date: Tue, 24 Oct 2000 09:56:43 +0000 (+0000) Subject: serial datatype emulation for mysql X-Git-Tag: DBIx_DBSchema_0_14~1 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=60b32316649e05847bfdd18d286a532cca8acba4;p=DBIx-DBSchema.git serial datatype emulation for mysql --- diff --git a/DBSchema/Column.pm b/DBSchema/Column.pm index d036965..8ae062d 100644 --- a/DBSchema/Column.pm +++ b/DBSchema/Column.pm @@ -241,7 +241,8 @@ sub line { #this should be a callback into the driver if ( $driver eq 'mysql' ) { #yucky mysql hack - $null ||= "NOT NULL" + $null ||= "NOT NULL"; + $self->local('AUTO_INCREMENT') if uc($self->type) eq 'SERIAL'; } elsif ( $driver eq 'Pg' ) { #yucky Pg hack $null ||= "NOT NULL"; $null =~ s/^NULL$//; diff --git a/DBSchema/DBD/mysql.pm b/DBSchema/DBD/mysql.pm index 63877f7..9fa7f80 100644 --- a/DBSchema/DBD/mysql.pm +++ b/DBSchema/DBD/mysql.pm @@ -9,6 +9,7 @@ $VERSION = '0.02'; %typemap = ( 'TIMESTAMP' => 'DATETIME', + 'SERIAL' => 'INTEGER', ); =head1 NAME diff --git a/DBSchema/Table.pm b/DBSchema/Table.pm index 1c2577e..7e8e35c 100644 --- a/DBSchema/Table.pm +++ b/DBSchema/Table.pm @@ -297,13 +297,11 @@ a DBI connection will be opened and the quoting and type mapping will be more reliable. If passed a DBI data source (or handle) such as `DBI:mysql:database', will use -MySQL-specific syntax. PostgreSQL is also supported (requires no special -syntax). Non-standard syntax for other engines (if applicable) may also be -supported in the future. +MySQL- or PostgreSQL-specific syntax. Non-standard syntax for other engines +(if applicable) may also be supported in the future. =cut - sub sql_create_table { my($self, $dbh) = (shift, shift); @@ -325,9 +323,21 @@ sub sql_create_table { } #eofalse +# if ( $driver eq 'Pg' && $self->primary_key ) { +# my $pcolumn = $self->column( ( +# grep { $self->column($_)->name eq $self->primary_key } $self->columns +# )[0] ); +# $pcolumn->type('serial') if lc($pcolumn->type) eq 'integer'; +## $pcolumn->local( $pcolumn->local. ' PRIMARY KEY' ); +## $self->primary_key(''); +# #prolly shoudl change it back afterwords :/ +# } + my(@columns)=map { $self->column($_)->line($dbh) } $self->columns; + push @columns, "PRIMARY KEY (". $self->primary_key. ")" - if $self->primary_key; + if $self->primary_key && $driver ne 'Pg'; + if ( $driver eq 'mysql' ) { #yucky mysql hack push @columns, map "UNIQUE ($_)", $self->unique->sql_list; push @columns, map "INDEX ($_)", $self->index->sql_list; @@ -379,6 +389,9 @@ the same terms as Perl itself. sql_create_table() has database-specific foo that probably ought to be abstracted into the DBIx::DBSchema::DBD:: modules. +sql_create_table may change or destroy the object's data. If you need to use +the object after sql_create_table, make a copy beforehand. + Some of the logic in new_odbc might be better abstracted into Column.pm etc. =head1 SEE ALSO