shit doesn't work yet
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / NoBindVars.pm
1 package DBIx::Class::Storage::DBI::Sybase::NoBindVars;
2
3 use Class::C3;
4 use base qw/
5   DBIx::Class::Storage::DBI::NoBindVars
6   DBIx::Class::Storage::DBI::Sybase
7 /;
8 use List::Util ();
9
10 sub _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
18 my %noquote = (
19     int => sub { /^ -? \d+ \z/x },
20     # TODO maybe need to add float/real/etc
21 );
22
23 sub should_quote_data_type {
24   my $self = shift;
25   my ($type, $value) = @_;
26
27   return $self->next::method(@_) if not defined $value;
28
29   if (my $key = List::Util::first { $type =~ /^$_/i } keys %noquote) {
30     local $_ = $value;
31     return 0 if $noquote{$key}->();
32   }
33
34   return $self->next::method(@_);
35 }
36
37 1;
38
39 =head1 NAME
40
41 DBIx::Class::Storage::DBI::Sybase::NoBindVars - Storage::DBI subclass for Sybase
42 without placeholder support
43
44 =head1 DESCRIPTION
45
46 If you're using this driver than your version of Sybase does not support
47 placeholders. You can check with:
48
49   $dbh->{syb_dynamic_supported}
50
51 You 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
57 See 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
60 One advantage of not using placeholders is that C<select @@identity> will work
61 for obtainging the last insert id of an C<IDENTITY> column, instead of having to
62 do C<select max(col)> as the base Sybase driver does.
63
64 When using this driver, bind variables will be interpolated (properly quoted of
65 course) into the SQL query itself, without using placeholders.
66
67 The caching of prepared statements is also explicitly disabled, as the
68 interpolation renders it useless.
69
70 =head1 AUTHORS
71
72 See L<DBIx::Class/CONTRIBUTORS>.
73
74 =head1 LICENSE
75
76 You may distribute this code under the same terms as Perl itself.
77
78 =cut
79 # vim:sts=2 sw=2: