Commit | Line | Data |
6b1f5ef7 |
1 | package DBIx::Class::Storage::DBI::Sybase::NoBindVars; |
5608593e |
2 | |
b7505130 |
3 | use Class::C3; |
5608593e |
4 | use base qw/ |
5 | DBIx::Class::Storage::DBI::NoBindVars |
6 | DBIx::Class::Storage::DBI::Sybase |
7 | /; |
8 | |
6b1f5ef7 |
9 | sub _dbh_last_insert_id { |
10 | my ($self, $dbh, $source, $col) = @_; |
11 | |
12 | # @@identity works only if not using placeholders |
13 | # Should this query be cached? |
14 | return ($dbh->selectrow_array('select @@identity'))[0]; |
15 | } |
16 | |
0c1bedfc |
17 | my $noquote = { |
18 | int => qr/^ \-? \d+ $/x, |
19 | integer => qr/^ \-? \d+ $/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 $re = $noquote->{$type}) { |
30 | return 0 if $value =~ $re; |
31 | } |
32 | |
33 | return $self->next::method(@_); |
34 | } |
35 | |
36 | |
5608593e |
37 | 1; |
7e8cecc1 |
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: |