[Bast-commits] r4245 - in DBIx-Class/0.08/branches/bindtype_ensure_connected: lib/DBIx/Class/Storage t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Fri Mar 28 12:52:08 GMT 2008


Author: jnapiorkowski
Date: 2008-03-28 12:52:08 +0000 (Fri, 28 Mar 2008)
New Revision: 4245

Modified:
   DBIx-Class/0.08/branches/bindtype_ensure_connected/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/bindtype_ensure_connected/t/bindtype_columns.t
Log:
- if the base bind parameter method is called, that means we are not connected.  So connect and then dispatch the the storage method.

Modified: DBIx-Class/0.08/branches/bindtype_ensure_connected/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/bindtype_ensure_connected/lib/DBIx/Class/Storage/DBI.pm	2008-03-27 02:35:48 UTC (rev 4244)
+++ DBIx-Class/0.08/branches/bindtype_ensure_connected/lib/DBIx/Class/Storage/DBI.pm	2008-03-28 12:52:08 UTC (rev 4245)
@@ -1135,7 +1135,7 @@
   foreach my $column ($source->columns) {
   
     my $data_type = $source->column_info($column)->{data_type} || '';
-    $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type)
+    $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type, $source)
      if $data_type;
   }
 
@@ -1299,7 +1299,12 @@
 =cut
 
 sub bind_attribute_by_data_type {
-    return;
+  my ($self, $data_type, $source) = @_;return;
+  if($source) {
+    $source->storage->ensure_connected;
+    return $source->storage->bind_attribute_by_data_type($data_type)
+  }
+  return;
 }
 
 =head2 create_ddl_dir

Modified: DBIx-Class/0.08/branches/bindtype_ensure_connected/t/bindtype_columns.t
===================================================================
--- DBIx-Class/0.08/branches/bindtype_ensure_connected/t/bindtype_columns.t	2008-03-27 02:35:48 UTC (rev 4244)
+++ DBIx-Class/0.08/branches/bindtype_ensure_connected/t/bindtype_columns.t	2008-03-28 12:52:08 UTC (rev 4245)
@@ -1,8 +1,8 @@
 use strict;
 use warnings;  
+use lib qw(t/lib);
 
 use Test::More;
-use lib qw(t/lib);
 use DBICTest;
 
 my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
@@ -10,20 +10,25 @@
 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $dbuser);
   
-plan tests => 3;
+plan tests => 8;
 
-my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+ok my $schema = DBICTest::Schema
+	->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 }) => 'Good Schema';
 
-my $dbh = $schema->storage->dbh;
+ok my $dbh = $schema->storage->dbh => "got good database handle";
 
-$dbh->do(qq[
+$dbh->do(qq[drop table artist])
+ if $dbh->selectrow_array(qq[select count(*) from pg_class where relname = 'artist']);
 
+$schema->storage->dbh->do(qq[
+
 	CREATE TABLE artist
 	(
 		artistid		serial	NOT NULL	PRIMARY KEY,
 		media			bytea	NOT NULL,
 		name			varchar NULL
 	);
+	
 ],{ RaiseError => 1, PrintError => 1 });
 
 
@@ -41,10 +46,9 @@
 		is_nullable => 0,
 	},
 );
-
 # test primary key handling
-my $big_long_string	= 'abcd' x 250000;
-
+my $big_long_string	= 'abcd' x 500000;
+ok $schema->storage->bind_attribute_by_data_type('bytea') => 'got correct bindtype.';
 my $new = $schema->resultset('Artist')->create({ media => $big_long_string });
 
 ok($new->artistid, "Created a blob row");
@@ -54,7 +58,26 @@
 
 is($rs->get_column('media'), $big_long_string, "Created the blob correctly.");
 
-$dbh->do("DROP TABLE artist");
+## Test bug where if we are calling a blob first, it fails
 
+$schema->storage->disconnect;
 
 
+CANT_BE_FIRST: {
+
+	my $schema1 = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+	
+	my $new = $schema->resultset('Artist')->create({media => $big_long_string });
+	
+	ok $schema->storage->bind_attribute_by_data_type('bytea') => 'got correct bindtype.';	
+
+	my $rs = $schema1->resultset('Artist')->find({artistid=>$new->artistid});
+
+	is($rs->get_column('media'), $big_long_string, "Created the blob correctly.");	
+	
+	$schema1->storage->dbh->do("DROP TABLE artist");
+}
+
+
+
+




More information about the Bast-commits mailing list