[Rt-commit] r3014 - in DBIx-SearchBuilder: . trunk/SearchBuilder trunk/ex trunk/t

glasser at bestpractical.com glasser at bestpractical.com
Wed Jun 1 18:01:52 EDT 2005


Author: glasser
Date: Wed Jun  1 18:01:51 2005
New Revision: 3014

Modified:
   DBIx-SearchBuilder/   (props changed)
   DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm
   DBIx-SearchBuilder/trunk/ex/create_tables.pl
   DBIx-SearchBuilder/trunk/t/10schema.t
Log:
 r33649 at tin-foil:  glasser | 2005-06-01 13:44:45 -0400
 Branch CreateTableSQL into a single-text-blob returning method and a list-of-statements
 method.


Modified: DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm	Wed Jun  1 18:01:51 2005
@@ -73,17 +73,30 @@
   1;
 }
 
-=for public_doc CreateTableSQL
+=for public_doc CreateTableSQLStatements
 
-Returns a SQL string to create tables for all of the models added
-to the SchemaGenerator.
+Returns a list of SQL statements (as strings) to create tables for all of
+the models added to the SchemaGenerator.
 
 =cut
 
-sub CreateTableSQL {
+sub CreateTableSQLStatements {
   my $self = shift;
   # The sort here is to make it predictable, so that we can write tests.
-  return join "\n", map { "$_ ;\n" } sort $self->_db_schema->sql($self->handle->dbh);
+  return sort $self->_db_schema->sql($self->handle->dbh);
+}
+
+=for public_doc CreateTableSQLText
+
+Returns a string containg a sequence of SQL statements to create tables for all of
+the models added to the SchemaGenerator.
+
+=cut
+
+sub CreateTableSQLText {
+  my $self = shift;
+
+  return join "\n", map { "$_ ;\n" } $self->CreateTableSQLStatements;
 }
 
 =for private_doc _DBSchemaTableFromModel MODEL

Modified: DBIx-SearchBuilder/trunk/ex/create_tables.pl
==============================================================================
--- DBIx-SearchBuilder/trunk/ex/create_tables.pl	(original)
+++ DBIx-SearchBuilder/trunk/ex/create_tables.pl	Wed Jun  1 18:01:51 2005
@@ -55,4 +55,4 @@
   $ret or die "couldn't add model $model: ".$ret->error_message;
 }
 
-print $SG->CreateTableSQL;
+print $SG->CreateTableSQLText;

Modified: DBIx-SearchBuilder/trunk/t/10schema.t
==============================================================================
--- DBIx-SearchBuilder/trunk/t/10schema.t	(original)
+++ DBIx-SearchBuilder/trunk/t/10schema.t	Wed Jun  1 18:01:51 2005
@@ -4,7 +4,7 @@
 use warnings;
 use Test::More;
 
-use constant TESTS_PER_DRIVER => 13;
+use constant TESTS_PER_DRIVER => 14;
 our @AvailableDrivers;
 
 BEGIN {
@@ -27,7 +27,7 @@
 foreach my $d ( @AvailableDrivers ) {
   SKIP: {
     unless ($d eq 'Pg') {
-      skip "first goal is to work on Pg, not $d", TESTS_PER_DRIVER;
+      skip "first goal is to work on Pg", TESTS_PER_DRIVER;
     }
     
     unless( should_test( $d ) ) {
@@ -45,7 +45,7 @@
 
     isa_ok($SG->_db_schema, 'DBIx::DBSchema');
 
-    is($SG->CreateTableSQL, '', "no tables means no sql");
+    is($SG->CreateTableSQLText, '', "no tables means no sql");
 
     my $ret = $SG->AddModel('Sample::This::Does::Not::Exist');
 
@@ -54,13 +54,13 @@
     like($ret->error_message, qr/Error making new object from Sample::This::Does::Not::Exist/, 
       "couldn't add model from nonexistent class");
 
-    is($SG->CreateTableSQL, '', "no tables means no sql");
+    is($SG->CreateTableSQLText, '', "no tables means no sql");
 
     $ret = $SG->AddModel('Sample::Address');
 
     ok($ret != 0, "added model from real class");
 
-    is_ignoring_space($SG->CreateTableSQL, <<END_SCHEMA, "got the right schema");
+    is_ignoring_space($SG->CreateTableSQLText, <<END_SCHEMA, "got the right schema");
     CREATE TABLE Addresses ( 
       id serial NOT NULL , 
       Name varchar ,
@@ -77,7 +77,7 @@
 
     ok($ret != 0, "added model from an instantiated object");
 
-    is_ignoring_space($SG->CreateTableSQL, <<END_SCHEMA, "got the right schema");
+    is_ignoring_space($SG->CreateTableSQLText, <<END_SCHEMA, "got the right schema");
     CREATE TABLE Addresses ( 
       id serial NOT NULL , 
       Name varchar ,
@@ -91,6 +91,9 @@
       PRIMARY KEY (id)
     ) ;
 END_SCHEMA
+    
+    my $manually_make_text = join ' ', map { "$_;" } $SG->CreateTableSQLStatements;
+    is_ignoring_space($SG->CreateTableSQLText, $manually_make_text, 'CreateTableSQLText is the statements in CreateTableSQLStatements')
 }}
 
 sub is_ignoring_space {


More information about the Rt-commit mailing list