diff Lib/IMPL/SQL/Schema/Table.pm @ 270:3f59fd828d5f

merge
author cin
date Fri, 25 Jan 2013 00:25:02 +0400
parents dacfe7c0311a
children 56364d0c4b4f
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Table.pm	Mon Jan 21 02:08:17 2013 +0400
+++ b/Lib/IMPL/SQL/Schema/Table.pm	Fri Jan 25 00:25:02 2013 +0400
@@ -115,12 +115,47 @@
     return $this->{$columns}[$index];
 }
 
-sub ColumnsCount {
-    my ($this) = @_;
+sub SetColumnPosition {
+	my ($this,$nameOrColumn,$pos) = @_;
+	
+	my $colName;
+    if (is($nameOrColumn,'IMPL::SQL::Schema::Column')) {
+        $colName = $nameOrColumn->name;
+    } elsif (not ref $nameOrColumn) {
+        $colName = $nameOrColumn;
+    } else {
+    	die IMPL::InvalidArgumentException->new(column => 'The specified column isn\'t found in the table');
+    }
+    
+    die IMPL::InvalidArgumentException->new( 'pos' => 'The specified position is invalid')
+        if not defined $pos ||  $pos < 0 || $pos >= $this->columnsCount;
+	
+	my $index = 0;
+    foreach my $column(@{$this->{$columns}}) {
+        last if $column->name eq $colName;
+        $index++;
+    }
+    
+    if ($pos != $index) {
+    	#position needs to be changed;
+    	
+    	my ($column) = splice @{$this->{$columns}}, $index, 1;
+    	splice @{$this->{$columns}}, $pos, 0, $column; 
+    }
+    
+    return;
+}
+
+sub columnsCount {
+	my ($this) = @_;
     
     return scalar(@{$this->{$columns}});
 }
 
+sub ColumnsCount {
+    goto &columnsCount;
+}
+
 sub AddConstraint {
     my $this = shift;
     if (@_ == 1) {