From 2dcd502529c7e58c2df11df9cf87b9797671484f Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Wed, 19 Jan 2011 22:43:20 -0500 Subject: added column names helper functions Ignore-this: 95dabe680321b971f3cca054398b274f darcs-hash:20110120034320-067c0-0a483d27537351a5dad2829bf7a151234c0ba41a.gz --- GradeBook.tcl | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'GradeBook.tcl') diff --git a/GradeBook.tcl b/GradeBook.tcl index f75d910..24aa194 100755 --- a/GradeBook.tcl +++ b/GradeBook.tcl @@ -506,18 +506,30 @@ proc ChangeGrades { permission_list user } { } } -proc DeleteColumnNonWeb { columnname } { - if { $columnname != "" } { - set eval_str [concat SELECT * FROM GradesTable ] +proc getColListFromTable { table } { + set eval_str [concat SELECT * FROM \'$table\' ] set err [catch {db eval $eval_str v {} } errStat] set old_column_list $v(*) - # removing the column name to be deleted from total list - set new_column_list {} - foreach cname $old_column_list { - if { $cname ne $columnname } { - lappend new_column_list \"$cname\" - } + return $old_column_list +} + +proc removeElementFromList { element2remove old_list } { + set new_list {} + foreach element $old_list { + if { $element2remove ne $element } { + lappend new_list \"$element\" } + } + return $new_list +} + +proc DeleteColumnNonWeb { columnname } { + if { $columnname != "" } { + + # removing the column name to be deleted from total list + + set old_column_list [getColListFromTable GradesTable] + set new_column_list [removeElementFromList $columnname $old_column_list] set sql_new_column_list [join $new_column_list ","] set eval_str "BEGIN TRANSACTION; CREATE TEMPORARY TABLE GradesTable_backup($sql_new_column_list); -- cgit v1.2.3