shit doesn't work yet
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / NoBindVars.pm
CommitLineData
6b1f5ef7 1package DBIx::Class::Storage::DBI::Sybase::NoBindVars;
5608593e 2
b7505130 3use Class::C3;
5608593e 4use base qw/
5 DBIx::Class::Storage::DBI::NoBindVars
6 DBIx::Class::Storage::DBI::Sybase
7/;
b55e97a7 8use List::Util ();
5608593e 9
6b1f5ef7 10sub _dbh_last_insert_id {
11 my ($self, $dbh, $source, $col) = @_;
12
13 # @@identity works only if not using placeholders
14 # Should this query be cached?
15 return ($dbh->selectrow_array('select @@identity'))[0];
16}
17
b55e97a7 18my %noquote = (
19 int => sub { /^ -? \d+ \z/x },
0c1bedfc 20 # TODO maybe need to add float/real/etc
b55e97a7 21);
0c1bedfc 22
23sub should_quote_data_type {
24 my $self = shift;
25 my ($type, $value) = @_;
26
27 return $self->next::method(@_) if not defined $value;
28
b55e97a7 29 if (my $key = List::Util::first { $type =~ /^$_/i } keys %noquote) {
30 local $_ = $value;
31 return 0 if $noquote{$key}->();
0c1bedfc 32 }
33
34 return $self->next::method(@_);
35}
36
5608593e 371;
7e8cecc1 38
39=head1 NAME
40
41DBIx::Class::Storage::DBI::Sybase::NoBindVars - Storage::DBI subclass for Sybase
42without placeholder support
43
44=head1 DESCRIPTION
45
46If you're using this driver than your version of Sybase does not support
47placeholders. You can check with:
48
49 $dbh->{syb_dynamic_supported}
50
51You can also enable this driver explicitly using:
52
53 my $schema = SchemaClass->clone;
54 $schema->storage_type('::DBI::Sybase::NoBindVars');
55 $schema->connect($dsn, $user, $pass, \%opts);
56
57See the discussion in L<< DBD::Sybase/Using ? Placeholders & bind parameters to
58$sth->execute >> for details on the pros and cons of using placeholders.
59
60One advantage of not using placeholders is that C<select @@identity> will work
61for obtainging the last insert id of an C<IDENTITY> column, instead of having to
62do C<select max(col)> as the base Sybase driver does.
63
64When using this driver, bind variables will be interpolated (properly quoted of
65course) into the SQL query itself, without using placeholders.
66
67The caching of prepared statements is also explicitly disabled, as the
68interpolation renders it useless.
69
70=head1 AUTHORS
71
72See L<DBIx::Class/CONTRIBUTORS>.
73
74=head1 LICENSE
75
76You may distribute this code under the same terms as Perl itself.
77
78=cut
79# vim:sts=2 sw=2: