The JDBC-bridge is one way of getting access to a MSSQL-server from a platform
that Microsoft doesn't deliver native client libraries for. (e.g. Linux)
+=head2 Setting quotes for the generated SQL.
+
+If the database contains columnames with spaces and/or reserved words, the
+SQL-query needs to be quoted. This is done using:
+
+ __PACKAGE__->storage->sql_maker->quote_char([ qw/[ ]/] );
+ __PACKAGE__->storage->sql_maker->name_sep('.');
+
+The first sets the quotesymbols. If the quote i "symmetric" as " or '
+
+ __PACKAGE__->storage->sql_maker->quote_char('"');
+
+is enough. If the left qoute differs form the right quote, the first
+notation should be used. name_sep needs to be set to allow the
+SQL generator to put the quotes the correct place.
+
=cut
sub _quote {
my ($self, $label) = @_;
return '' unless defined $label;
+ return "*" if $label eq '*';
return $label unless $self->{quote_char};
+ if(ref $self->{quote_char} eq "ARRAY"){
+ return $self->{quote_char}->[0] . $label . $self->{quote_char}->[1]
+ if !defined $self->{name_sep};
+ my $sep = $self->{name_sep};
+ return join($self->{name_sep},
+ map { $self->{quote_char}->[0] . $_ . $self->{quote_char}->[1] }
+ split(/\Q$sep\E/,$label));
+ }
return $self->SUPER::_quote($label);
}
return $self->{limit_dialect};
}
+sub quote_char {
+ my $self = shift;
+ $self->{quote_char} = shift if @_;
+ return $self->{quote_char};
+}
+
+sub name_sep {
+ my $self = shift;
+ $self->{name_sep} = shift if @_;
+ return $self->{name_sep};
+}
+
+
+
+
package DBIx::Class::Storage::DBI::DebugCallback;
sub print {
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 3 );
+ : ( tests => 4 );
}
use lib qw(t/lib);
use_ok('DBICTest::HelperRels');
-DBICTest->schema->storage->sql_maker->{'quote_char'} = q!'!;
-DBICTest->schema->storage->sql_maker->{'name_sep'} = '.';
+DBICTest->schema->storage->sql_maker->quote_char("'");
+DBICTest->schema->storage->sql_maker->name_sep('.');
my $rs = DBICTest::CD->search(
{ 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
cmp_ok( $rs->count, '==', 1, "join with fields quoted");
+DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]);
+DBICTest->schema->storage->sql_maker->name_sep('.');
+
+$rs = DBICTest::CD->search(
+ { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
+ { join => 'artist' });
+cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
+
+
+
+