From e0505694165266017b901ee5e956869851f6c509 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 5 Sep 2001 16:20:03 +0000 Subject: [PATCH] documentation for %typemap, preliminary Sybase driver --- DBSchema.pm | 17 +++++--- DBSchema/DBD.pm | 18 ++++++++ DBSchema/DBD/Sybase.pm | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ README | 10 +++-- 4 files changed, 150 insertions(+), 10 deletions(-) create mode 100755 DBSchema/DBD/Sybase.pm diff --git a/DBSchema.pm b/DBSchema.pm index 418fadf..420d44f 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -14,7 +14,7 @@ use DBIx::DBSchema::ColGroup::Index; #@ISA = qw(Exporter); @ISA = (); -$VERSION = "0.18"; +$VERSION = "0.19"; =head1 NAME @@ -58,9 +58,10 @@ schema from an existing database. You can save the schema to disk and restore it a different process. Most importantly, DBIx::DBSchema can write SQL CREATE statements statements for different databases from a single source. -Currently supported databases are MySQL and PostgreSQL. DBIx::DBSchema will -attempt to use generic SQL syntax for other databases. Assistance adding -support for other databases is welcomed. +Currently supported databases are MySQL and PostgreSQL. Sybase support is +partially implemented. DBIx::DBSchema will attempt to use generic SQL syntax +for other databases. Assistance adding support for other databases is +welcomed. See L, "Driver Writer's Guide and Base Class". =head1 METHODS @@ -329,6 +330,9 @@ sub _tables_from_dbh { Ivan Kohler +Charles Shapiro and Mitchell Friedman + contributed the start of a Sybase driver. + =head1 COPYRIGHT Copyright (c) 2000 Ivan Kohler @@ -351,8 +355,9 @@ qw(:sql_types) here instead of externally. L, L, L, L, -L, L, L, -L, L, L +L, L, +L, L, L, +L =cut diff --git a/DBSchema/DBD.pm b/DBSchema/DBD.pm index c0a8652..2f386b2 100644 --- a/DBSchema/DBD.pm +++ b/DBSchema/DBD.pm @@ -69,6 +69,24 @@ L. =back +=head1 TYPE MAPPING + +You can define a %typemap array for your driver to map "standard" data +types to database-specific types. For example, the MySQL TIMESTAMP field +has non-standard auto-updating semantics; the MySQL DATETIME type is +what other databases and the ODBC standard call TIMESTAMP, so on of the +entries in the MySQL %typemap is: + + 'TIMESTAMP' => 'DATETIME', + +Another example is the Pg %typemap which maps the standard types BLOB and +LONG VARBINARY to the Pg-specific BYTEA: + + 'BLOB' => 'BYTEA', + 'LONG VARBINARY' => 'BYTEA', + +Make sure you use all uppercase-keys. + =head1 AUTHOR Ivan Kohler diff --git a/DBSchema/DBD/Sybase.pm b/DBSchema/DBD/Sybase.pm new file mode 100755 index 0000000..95e2d1a --- /dev/null +++ b/DBSchema/DBD/Sybase.pm @@ -0,0 +1,115 @@ +package DBIx::DBSchema::DBD::Sybase; + +use strict; +use vars qw($VERSION @ISA %typemap); +use DBIx::DBSchema::DBD; + +$VERSION = '0.02'; +@ISA = qw(DBIx::DBSchema::DBD); + +%typemap = ( +# 'empty' => 'empty' +); + +# +# Return this from uncompleted driver calls. +# + +=head1 NAME + +DBIx::DBSchema::DBD::Sybase - Sybase database driver for DBIx::DBSchema + +=head1 SYNOPSIS + +use DBI; +use DBIx::DBSchema; + +$dbh = DBI->connect('dbi:Sybase:dbname=database', 'user', 'pass'); +$schema = new_native DBIx::DBSchema $dbh; + +=head1 DESCRIPTION + +This module implements a Sybase driver for DBIx::DBSchema. + +=cut + +sub columns { + + my($proto, $dbh, $table) = @_; + + my $sth = $dbh->prepare("sp_columns \@table_name=$table") + or die $dbh->errstr; + + $sth->execute or die $sth->errstr; + map { + [ + $_->{'COLUMN_NAME'}, + $_->{'TYPE_NAME'}, + ($_->{'NULLABLE'} ? 1 : ''), + $_->{'LENGTH'}, + '', #default + '' #local + ] + } @{ $sth->fetchall_arrayref({}) }; + +} + +sub primary_key { + return("StubbedPrimaryKey"); +} + + +sub unique { + + my %stubList = ( + 'stubfirstUniqueIndex' => ['stubfirstUniqueIndex'], + 'stubtwostUniqueIndex' => ['stubtwostUniqueIndex'] + ); + + return ( { %stubList } ); + +} + +sub index { + + my %stubList = ( + 'stubfirstIndex' => ['stubfirstUniqueIndex'], + 'stubtwostIndex' => ['stubtwostUniqueIndex'] + ); + + return ( { %stubList } ); + +} + +=head1 AUTHOR + +Charles Shapiro +(courtesy of Ivan Kohler ) + +Mitchell Friedman + +=head1 COPYRIGHT + +Copyright (c) 2001 Charles Shapiro, Mitchell J. Friedman +Copyright (c) 2001 nuMethods LLC. +All rights reserved. +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +=head1 BUGS + +Yes. + +Most of this is not implemented. + +the "columns" method works; primary key, unique and index do not yet. Please +send any patches to all three addresses listed above. + +=head1 SEE ALSO + +L, L, L, L + +=cut + +1; + diff --git a/README b/README index ee9a798..67d434a 100644 --- a/README +++ b/README @@ -12,9 +12,11 @@ schema from an existing database. You can save the schema to disk and restore it from different process. Most importantly, DBIx::DBSchema can write SQL CREATE statements for different databases from a single source. -Currently supported databases are MySQL and PostgreSQL. DBIx::DBSchema will -attempt to use generic SQL syntax for other databases. Assistance adding -support for other databases is welcomed. +Currently supported databases are MySQL and PostgreSQL. Sybase support is +partially implemented. DBIx::DBSchema will attempt to use generic SQL syntax +for other databases. Assistance adding support for other databases is +welcomed. See the DBIx::DBSchema::DBD> manpage, "Driver Writer's Guide and +Base Class". To install: perl Makefile.PL @@ -38,4 +40,4 @@ A mailing list is available. Send a blank message to Homepage: -$Id: README,v 1.5 2001-07-08 00:57:17 ivan Exp $ +$Id: README,v 1.6 2001-09-05 16:20:03 ivan Exp $ -- 2.11.0