diff Lib/IMPL/SQL/Schema/Table.pm @ 269:dacfe7c0311a

SQL schema updated (unstable)
author sergey
date Thu, 24 Jan 2013 20:00:27 +0400
parents 5c82eec23bb6
children 56364d0c4b4f
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Table.pm	Thu Jan 17 02:39:44 2013 +0400
+++ b/Lib/IMPL/SQL/Schema/Table.pm	Thu Jan 24 20:00:27 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) {