Commit | Line | Data |
c9373b79 |
1 | package DBIx::Class::Schema::Loader::DBI::Sybase::Common; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Carp::Clan qw/^DBIx::Class/; |
6 | use Class::C3; |
7 | |
c3fb509f |
8 | our $VERSION = '0.04999_09'; |
c9373b79 |
9 | |
10 | =head1 NAME |
11 | |
12 | DBIx::Class::Schema::Loader::DBI::Sybase::Common - Common functions for Sybase |
13 | and MSSQL |
14 | |
15 | =head1 DESCRIPTION |
16 | |
17 | See L<DBIx::Class::Schema::Loader::Base>. |
18 | |
19 | =cut |
20 | |
21 | # DBD::Sybase doesn't implement get_info properly |
22 | sub _build_quoter { '"' } |
23 | sub _build_namesep { '.' } |
24 | |
25 | sub _set_quote_char_and_name_sep { |
26 | my $self = shift; |
27 | |
28 | $self->schema->storage->sql_maker->quote_char([qw/[ ]/]) |
29 | unless $self->schema->storage->sql_maker->quote_char; |
30 | |
31 | $self->schema->storage->sql_maker->name_sep('.') |
32 | unless $self->schema->storage->sql_maker->name_sep; |
33 | } |
34 | |
35 | sub _build_db_schema { |
36 | my $self = shift; |
37 | my $dbh = $self->schema->storage->dbh; |
38 | |
39 | local $dbh->{FetchHashKeyName} = 'NAME_lc'; |
40 | |
41 | my $test_table = "_loader_test_$$"; |
42 | |
43 | my $db_schema = 'dbo'; # default |
44 | |
45 | eval { |
46 | $dbh->do("create table $test_table (id integer)"); |
47 | my $sth = $dbh->prepare('sp_tables'); |
48 | $sth->execute; |
49 | while (my $row = $sth->fetchrow_hashref) { |
50 | next unless $row->{table_name} eq $test_table; |
51 | |
52 | $db_schema = $row->{table_owner}; |
53 | last; |
54 | } |
55 | $sth->finish; |
56 | $dbh->do("drop table $test_table"); |
57 | }; |
58 | my $exception = $@; |
59 | eval { $dbh->do("drop table $test_table") }; |
60 | carp "Could not determine db_schema, defaulting to $db_schema : $exception" |
61 | if $exception; |
62 | |
63 | return $db_schema; |
64 | } |
65 | |
66 | =head1 SEE ALSO |
67 | |
68 | L<DBIx::Class::Schema::Loader::DBI::Sybase>, |
69 | L<DBIx::Class::Schema::Loader::DBI::MSSQL>, |
70 | L<DBIx::Class::Schema::Loader::DBI> |
71 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, |
72 | |
73 | =head1 AUTHOR |
74 | |
75 | Rafael Kitover <rkitover@cpan.org> |
76 | |
77 | =cut |
78 | |
79 | 1; |