1 package DBIx::DBSchema::DBD::Oracle;
4 use vars qw($VERSION @ISA %typemap);
5 use DBIx::DBSchema::DBD;
8 @ISA = qw(DBIx::DBSchema::DBD);
11 'VARCHAR' => 'VARCHAR2',
12 'SERIAL' => 'INTEGER',
13 'LONG VARBINARY' => 'BLOB',
14 'TIMESTAMP' => 'DATE',
20 DBIx::DBSchema::DBD::Oracle - Oracle native driver for DBIx::DBSchema
27 $dbh = DBI->connect('dbi:Oracle:tns_service_name', 'user','pass');
28 $schema = new_native DBIx::DBSchema $dbh;
32 This module implements a Oracle-native driver for DBIx::DBSchema.
36 Daniel Hanks <hanksdc@about-inc.com>
40 ### Return column name, column type, nullability, column length, column default,
41 ### and a field reserved for driver-specific use
43 my ($proto, $dbh, $table) = @_;
44 return $proto->_column_info($dbh, $table);
48 my ($proto, $dbh, $table, $column) = @_;
49 return $proto->_column_info($dbh, $table, $column);
53 my ($proto, $dbh, $table, $column) = @_;
54 my $sql = "SELECT column_name, data_type,
55 CASE WHEN nullable = 'Y' THEN 1
56 WHEN nullable = 'N' THEN 0
59 data_length, data_default, NULL AS reserved
61 WHERE table_name = ?";
62 $sql .= " AND column_name = ?" if defined($column);
63 if(defined($column)) {
64 return $dbh->selectrow_arrayref($sql, undef, $table, $column);
65 } else { ### Assume columns
66 return $dbh->selectall_arrayref($sql, undef, $table);
70 ### This is broken. Primary keys can be comprised of any subset of a tables
71 ### fields, not just one field, as this module assumes.
73 my ($proto, $dbh, $table) = @_;
74 my $sql = "SELECT column_name
75 FROM user_constraints uc, user_cons_columns ucc
76 WHERE uc.constraint_name = ucc.constraint_name
77 AND uc.constraint_type = 'P'
78 AND uc.table_name = ?";
79 my ($key) = $dbh->selectrow_array($sql, undef, $table);
83 ### Wraoper around _index_info
85 my ($proto, $dbh, $table) = @_;
86 return $proto->_index_info($dbh, $table, 'UNIQUE');
89 ### Wrapper around _index_info
91 my ($proto, $dbh, $table) = @_;
92 return $proto->_index_info($dbh, $table, 'NONUNIQUE');
95 ### Collect info about unique or non-unique indexes
96 ### $type must be 'UNIQUE' or 'NONUNIQUE'
98 my ($proto, $dbh, $table, $type) = @_;
101 die "\$type must be 'UNIQUE' or 'NONUNIQUE'"
102 unless $type =~ /^(NON)?UNIQUE$/;
105 my $sql = "SELECT ui.index_name, uic.column_name
106 FROM user_indexes ui, user_ind_columns uic
107 WHERE ui.index_name = uic.index_name
108 AND ui.uniqueness = ?
110 my $sth = $dbh->prepare($sql);
111 $sth->execute($table, $type);
113 ### Now collect the results
115 while(my ($idx, $col) = $sth->fetchrow_array()) {
116 if(!exists($results->{$idx})) {
117 $results->{$idx} = [];
119 push @{$results->{$idx}}, $col;