comparison 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
comparison
equal deleted inserted replaced
267:bbc0da7ef90e 269:dacfe7c0311a
113 if $index < 0 || $index >= ($this->{$columns} ? scalar(@{$this->{$columns}}) : 0); 113 if $index < 0 || $index >= ($this->{$columns} ? scalar(@{$this->{$columns}}) : 0);
114 114
115 return $this->{$columns}[$index]; 115 return $this->{$columns}[$index];
116 } 116 }
117 117
118 sub SetColumnPosition {
119 my ($this,$nameOrColumn,$pos) = @_;
120
121 my $colName;
122 if (is($nameOrColumn,'IMPL::SQL::Schema::Column')) {
123 $colName = $nameOrColumn->name;
124 } elsif (not ref $nameOrColumn) {
125 $colName = $nameOrColumn;
126 } else {
127 die IMPL::InvalidArgumentException->new(column => 'The specified column isn\'t found in the table');
128 }
129
130 die IMPL::InvalidArgumentException->new( 'pos' => 'The specified position is invalid')
131 if not defined $pos || $pos < 0 || $pos >= $this->columnsCount;
132
133 my $index = 0;
134 foreach my $column(@{$this->{$columns}}) {
135 last if $column->name eq $colName;
136 $index++;
137 }
138
139 if ($pos != $index) {
140 #position needs to be changed;
141
142 my ($column) = splice @{$this->{$columns}}, $index, 1;
143 splice @{$this->{$columns}}, $pos, 0, $column;
144 }
145
146 return;
147 }
148
149 sub columnsCount {
150 my ($this) = @_;
151
152 return scalar(@{$this->{$columns}});
153 }
154
118 sub ColumnsCount { 155 sub ColumnsCount {
119 my ($this) = @_; 156 goto &columnsCount;
120
121 return scalar(@{$this->{$columns}});
122 } 157 }
123 158
124 sub AddConstraint { 159 sub AddConstraint {
125 my $this = shift; 160 my $this = shift;
126 if (@_ == 1) { 161 if (@_ == 1) {