Merge 'sybase' into 'trunk'
Peter Rabbitson [Fri, 27 Feb 2009 00:00:53 +0000 (00:00 +0000)]
examples/Schema/MyDatabase/Main.pm
examples/Schema/MyDatabase/Main/Artist.pm [moved from examples/Schema/MyDatabase/Main/Result/Artist.pm with 65% similarity]
examples/Schema/MyDatabase/Main/Cd.pm [moved from examples/Schema/MyDatabase/Main/Result/Cd.pm with 51% similarity]
examples/Schema/MyDatabase/Main/Track.pm [moved from examples/Schema/MyDatabase/Main/Result/Track.pm with 65% similarity]
examples/Schema/testdb.pl
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/NoBindVars.pm
lib/DBIx/Class/Storage/DBI/Sybase.pm

index 42fae1b..6b9eef7 100644 (file)
@@ -1,5 +1,5 @@
 package MyDatabase::Main;
 use base qw/DBIx::Class::Schema/;
-__PACKAGE__->load_namespaces;
+__PACKAGE__->load_classes(qw/Artist Cd Track/);
 
 1;
similarity index 65%
rename from examples/Schema/MyDatabase/Main/Result/Artist.pm
rename to examples/Schema/MyDatabase/Main/Artist.pm
index ec78501..5f039e6 100644 (file)
@@ -1,10 +1,10 @@
-package MyDatabase::Main::Result::Artist;
+package MyDatabase::Main::Artist;
 use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/PK::Auto Core/);
 __PACKAGE__->table('artist');
 __PACKAGE__->add_columns(qw/ artistid name /);
 __PACKAGE__->set_primary_key('artistid');
-__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
+__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd');
 
 1;
 
similarity index 51%
rename from examples/Schema/MyDatabase/Main/Result/Cd.pm
rename to examples/Schema/MyDatabase/Main/Cd.pm
index 83fd21e..4579823 100644 (file)
@@ -1,10 +1,10 @@
-package MyDatabase::Main::Result::Cd;
+package MyDatabase::Main::Cd;
 use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/PK::Auto Core/);
 __PACKAGE__->table('cd');
 __PACKAGE__->add_columns(qw/ cdid artist title/);
 __PACKAGE__->set_primary_key('cdid');
-__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist');
-__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track');
+__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist');
+__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Track');
 
 1;
similarity index 65%
rename from examples/Schema/MyDatabase/Main/Result/Track.pm
rename to examples/Schema/MyDatabase/Main/Track.pm
index 23877bb..3710406 100644 (file)
@@ -1,9 +1,9 @@
-package MyDatabase::Main::Result::Track;
+package MyDatabase::Main::Track;
 use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/PK::Auto Core/);
 __PACKAGE__->table('track');
 __PACKAGE__->add_columns(qw/ trackid cd title/);
 __PACKAGE__->set_primary_key('trackid');
-__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
+__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Cd');
 
 1;
index 9ca3e39..b31773d 100644 (file)
@@ -26,6 +26,7 @@ sub get_tracks_by_cd {
         },
         {
             join     => [qw/ cd /],
+            prefetch => [qw/ cd /]
         }
     );
     while (my $track = $rs->next) {
@@ -78,6 +79,7 @@ sub get_cds_by_artist {
         },
         {
             join     => [qw/ artist /],
+            prefetch => [qw/ artist /]
         }
     );
     while (my $cd = $rs->next) {
index 99f860c..1b05615 100644 (file)
@@ -1239,7 +1239,7 @@ sub _query_end {
 
 sub _dbh_execute {
   my ($self, $dbh, $op, $extra_bind, $ident, $bind_attributes, @args) = @_;
-  
+
   my ($sql, $bind) = $self->_prep_for_execute($op, $extra_bind, $ident, \@args);
 
   $self->_query_start( $sql, @$bind );
index 80f367d..51ef7d5 100644 (file)
@@ -38,6 +38,9 @@ Manually subs in the values for the usual C<?> placeholders.
 
 sub _prep_for_execute {
   my $self = shift;
+
+  my ($op, $extra_bind, $ident) = @_;
+
   my ($sql, $bind) = $self->next::method(@_);
 
   # stringify args, quote via $dbh, and manually insert
@@ -46,12 +49,14 @@ sub _prep_for_execute {
   my $new_sql;
 
   foreach my $bound (@$bind) {
-    shift @$bound;
+    my $col = shift @$bound;
+    my $do_quote = $self->should_quote_data_type($col);
     foreach my $data (@$bound) {
         if(ref $data) {
             $data = ''.$data;
         }
-        $new_sql .= shift(@sql_part) . $self->_dbh->quote($data);
+        $data = $self->_dbh->quote($data) if $do_quote;
+        $new_sql .= shift(@sql_part) . $data;
     }
   }
   $new_sql .= join '', @sql_part;
@@ -59,6 +64,8 @@ sub _prep_for_execute {
   return ($new_sql);
 }
 
+sub should_quote_data_type { 1 }
+
 =head1 AUTHORS
 
 Brandon Black <blblack@gmail.com>
index 87acdde..f18de95 100644 (file)
@@ -5,6 +5,15 @@ use warnings;
 
 use base qw/DBIx::Class::Storage::DBI::NoBindVars/;
 
+my %noquote = map ($_ => 1), qw(int integer);
+
+sub should_quote_data_type {
+  my $self = shift;
+  my ($type) = @_;
+  return 0 if $noquote{$type};
+  return $self->next::method(@_);
+}
+
 1;
 
 =head1 NAME