use vars qw($VERSION @ISA %typemap);
use DBIx::DBSchema::DBD;
-$VERSION = '0.02';
+$VERSION = '0.03';
@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
=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 {
+ my @cols = map {
[
- $_->{'COLUMN_NAME'},
- $_->{'TYPE_NAME'},
- ($_->{'NULLABLE'} ? 1 : ''),
- $_->{'LENGTH'},
+ $_->{'column_name'},
+ $_->{'type_name'},
+ ($_->{'nullable'} ? 1 : ''),
+ $_->{'length'},
'', #default
'' #local
]
} @{ $sth->fetchall_arrayref({}) };
+ $sth->finish;
+ @cols;
}
sub primary_key {
sub unique {
+ my($proto, $dbh, $table) = @_;
+ my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $table, $_ ) ] }
+ grep { $proto->_is_unique($dbh, $_ ) }
+ $proto->_all_indices($dbh, $table)
+ };
+}
- my %stubList = (
- 'stubfirstUniqueIndex' => ['stubfirstUniqueIndex'],
- 'stubtwostUniqueIndex' => ['stubtwostUniqueIndex']
- );
+sub index {
+ my($proto, $dbh, $table) = @_;
+ my $gratuitous = { map { $_ => [ $proto->_index_fields($dbh, $table, $_ ) ] }
+ grep { ! $proto->_is_unique($dbh, $_ ) }
+ $proto->_all_indices($dbh, $table)
+ };
+}
- return ( { %stubList } );
+sub _all_indices {
+ my($proto, $dbh, $table) = @_;
+ my $sth = $dbh->prepare_cached(<<END) or die $dbh->errstr;
+ SELECT name
+ FROM sysindexes
+ WHERE id = object_id('$table') and indid between 1 and 254
+END
+ $sth->execute or die $sth->errstr;
+ my @indices = map { $_->[0] } @{ $sth->fetchall_arrayref() };
+ $sth->finish;
+ $sth = undef;
+ @indices;
}
-sub index {
+sub _index_fields {
+ my($proto, $dbh, $table, $index) = @_;
+
+ my @keys;
+
+ my ($indid) = $dbh->selectrow_array("select indid from sysindexes where id = object_id('$table') and name = '$index'");
+ for (1..30) {
+ push @keys, $dbh->selectrow_array("select index_col('$table', $indid, $_)") || ();
+ }
- my %stubList = (
- 'stubfirstIndex' => ['stubfirstUniqueIndex'],
- 'stubtwostIndex' => ['stubtwostUniqueIndex']
- );
+ return @keys;
+}
+
+sub _is_unique {
+ my($proto, $dbh, $table, $index) = @_;
- return ( { %stubList } );
+ my ($isunique) = $dbh->selectrow_array("select status & 2 from sysindexes where id = object_id('$table') and name = '$index'");
+ return $isunique;
}
=head1 AUTHOR
Mitchell Friedman <mitchell.friedman@numethods.com>
+Bernd Dulfer <bernd@widd.de>
+
=head1 COPYRIGHT
Copyright (c) 2001 Charles Shapiro, Mitchell J. Friedman
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.
+The B<primary_key> method does not yet work.
=head1 SEE ALSO
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. 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".
+Currently supported databases are MySQL, PostgreSQL and Sybase.
+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
Homepage: <http://www.420.am/dbix-dbschema>
-$Id: README,v 1.8 2002-03-04 13:01:55 ivan Exp $
+$Id: README,v 1.9 2002-11-29 23:03:04 ivan Exp $