$dbh->quote some things
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / Sybase / Common.pm
CommitLineData
c9373b79 1package DBIx::Class::Schema::Loader::DBI::Sybase::Common;
2
3use strict;
4use warnings;
5use Carp::Clan qw/^DBIx::Class/;
6use Class::C3;
7
b1ad1a84 8our $VERSION = '0.04999_10';
c9373b79 9
10=head1 NAME
11
12DBIx::Class::Schema::Loader::DBI::Sybase::Common - Common functions for Sybase
13and MSSQL
14
15=head1 DESCRIPTION
16
17See L<DBIx::Class::Schema::Loader::Base>.
18
19=cut
20
21# DBD::Sybase doesn't implement get_info properly
22sub _build_quoter { '"' }
23sub _build_namesep { '.' }
24
25sub _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
35sub _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
68L<DBIx::Class::Schema::Loader::DBI::Sybase>,
69L<DBIx::Class::Schema::Loader::DBI::MSSQL>,
70L<DBIx::Class::Schema::Loader::DBI>
71L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
72
73=head1 AUTHOR
74
75Rafael Kitover <rkitover@cpan.org>
76
77=cut
78
791;