table/field counts are held per-object, not globally
Peter Rabbitson [Mon, 4 May 2009 07:17:36 +0000 (07:17 +0000)]
Tests adjusted (no idea why they were initially written this way...)

lib/SQL/Translator/Schema.pm
lib/SQL/Translator/Schema/Table.pm
t/17sqlfxml-producer.t
t/18ttschema-producer.t
t/24yaml.t
t/39-filter-globals.t

index 926cf7c..eebb185 100644 (file)
@@ -54,12 +54,27 @@ use SQL::Translator::Schema::View;
 use SQL::Translator::Utils 'parse_list_arg';
 
 use base 'SQL::Translator::Schema::Object';
-use vars qw[ $VERSION $TABLE_ORDER $VIEW_ORDER $TRIGGER_ORDER $PROC_ORDER ];
+use vars qw[ $VERSION ];
 
 $VERSION = '1.59';
 
 __PACKAGE__->_attributes(qw/name database translator/);
 
+sub new {
+  my $class = shift;
+  my $self = $class->SUPER::new (@_)
+    or return;
+
+  $self->{_order} = { map { $_ => 0 } qw/
+    table
+    view
+    trigger
+    proc
+  /};
+
+  return $self;
+}
+
 # ----------------------------------------------------------------------
 sub as_graph {
 
@@ -143,7 +158,7 @@ not be created.
           or return $self->error( $table_class->error );
     }
 
-    $table->order( ++$TABLE_ORDER );
+    $table->order( ++$self->{_order}{table} );
 
     # We know we have a name as the Table->new above errors if none given.
     my $table_name = $table->name;
@@ -237,7 +252,7 @@ procedure will not be created.
           or return $self->error( $procedure_class->error );
     }
 
-    $procedure->order( ++$PROC_ORDER );
+    $procedure->order( ++$self->{_order}{proc} );
     my $procedure_name = $procedure->name
       or return $self->error('No procedure name');
 
@@ -323,7 +338,7 @@ not be created.
           or return $self->error( $trigger_class->error );
     }
 
-    $trigger->order( ++$TRIGGER_ORDER );
+    $trigger->order( ++$self->{_order}{trigger} );
 
     my $trigger_name = $trigger->name or return $self->error('No trigger name');
     if ( defined $self->{'triggers'}{$trigger_name} ) {
@@ -405,7 +420,7 @@ not be created.
         $view = $view_class->new( \%args ) or return $view_class->error;
     }
 
-    $view->order( ++$VIEW_ORDER );
+    $view->order( ++$self->{_order}{view} );
     my $view_name = $view->name or return $self->error('No view name');
 
     if ( defined $self->{'views'}{$view_name} ) {
index fff4799..01fb965 100644 (file)
@@ -47,7 +47,7 @@ use Data::Dumper;
 
 use base 'SQL::Translator::Schema::Object';
 
-use vars qw( $VERSION $FIELD_ORDER );
+use vars qw( $VERSION );
 
 $VERSION = '1.59';
 
@@ -77,6 +77,20 @@ Object constructor.
 
 =cut
 
+sub new {
+  my $class = shift;
+  my $self = $class->SUPER::new (@_)
+    or return;
+
+  $self->{_order} = { map { $_ => 0 } qw/
+    field
+  /};
+
+  return $self;
+}
+
+
+
 # ----------------------------------------------------------------------
 sub add_constraint {
 
@@ -320,7 +334,7 @@ existing field, you will get an error and the field will not be created.
             $self->error( $field_class->error );
     }
 
-    $field->order( ++$FIELD_ORDER );
+    $field->order( ++$self->{_order}{field} );
     # We know we have a name as the Field->new above errors if none given.
     my $field_name = $field->name;
 
index e909673..050bc42 100644 (file)
@@ -172,7 +172,7 @@ $ans = <<EOXML;
 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
   <extra />
   <tables>
-    <table name="Basic" order="2">
+    <table name="Basic" order="1">
       <extra />
       <fields></fields>
       <indices></indices>
@@ -290,10 +290,10 @@ $ans = <<EOXML;
 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
   <extra />
   <tables>
-    <table name="Basic" order="3">
+    <table name="Basic" order="1">
       <extra />
       <fields>
-        <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="5">
+        <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="1">
           <extra ZEROFILL="1" />
           <comments></comments>
         </field>
index 7b5d5b9..2df7891 100644 (file)
@@ -293,7 +293,7 @@ Fields
         is_foreign_key:        0
         foreign_key_reference: 
         is_valid:              1
-        order:                 10
+        order:                 1
         table:                 Another
     
 
index 8955bce..9f9f2c7 100644 (file)
@@ -153,7 +153,7 @@ schema:
           is_primary_key: 0
           is_unique: 0
           name: age
-          order: 10
+          order: 4
           size:
             - 0
         name:
@@ -164,7 +164,7 @@ schema:
           is_primary_key: 0
           is_unique: 0
           name: name
-          order: 9
+          order: 3
           size:
             - 30
         person_id:
@@ -175,7 +175,7 @@ schema:
           is_primary_key: 1
           is_unique: 0
           name: person_id
-          order: 8
+          order: 2
           size:
             - 0
         pet_id:
@@ -186,7 +186,7 @@ schema:
           is_primary_key: 1
           is_unique: 0
           name: pet_id
-          order: 7
+          order: 1
           size:
             - 0
       indices: []
index 68fd98d..2a7636d 100644 (file)
@@ -74,7 +74,7 @@ schema:
           is_primary_key: 0
           is_unique: 0
           name: created
-          order: 3
+          order: 2
           size:
             - 0
         first_name:
@@ -85,7 +85,7 @@ schema:
           is_primary_key: 0
           is_unique: 0
           name: first_name
-          order: 2
+          order: 1
           size:
             - 0
         modified:
@@ -96,7 +96,7 @@ schema:
           is_primary_key: 0
           is_unique: 1
           name: modified
-          order: 4
+          order: 3
           size:
             - 0
       indices: