From 6526ed8ec7d6ef2f696fbced58aa6e7baa040537 Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Tue, 18 Jan 2011 23:40:08 -0500 Subject: added UpdateColumn procedure Ignore-this: 4a3e617966e78ac66f8772dbbb7a5d55 darcs-hash:20110119044008-067c0-481f4747cf5ce49d1e044f7a34b541f51336b2d5.gz --- GradeBook.tcl | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/GradeBook.tcl b/GradeBook.tcl index 69154e6..921da17 100755 --- a/GradeBook.tcl +++ b/GradeBook.tcl @@ -284,7 +284,9 @@ proc ChoseAction {action permission_list user} { } renamecolumn { } changecolumn { ChangeColumn $permission_list $user } - updatecolumn { UpdateColumn $permission_list $user } + updatecolumn { UpdateColumn $permission_list $user + htmlDefaultView $permission_list $user + } showcontrols { ShowControls $permission_list $user } showgrades { htmlGradesTable db $permission_list $user } defaultview { htmlDefaultView $permission_list $user } @@ -359,6 +361,52 @@ proc ChangeColumn { permission_list user } { puts {} } +proc UpdateColumn { permission_list user } { + set oldcolumnname [::ncgi::value oldcolumnname {}] + set newcolumnname [::ncgi::value newcolumnname {}] + set column_category [::ncgi::value category {}] + set maxpointpossible [::ncgi::value maxpointpossible {}] + + # first we update category and maxpointpossible values of the old columnname + set sql_str [concat UPDATE GradesTable SET \"$oldcolumnname\"=\'$column_category\' where UserName=\"_Col_Category_\"] + set err [catch {db eval $sql_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + set sql_str [concat UPDATE GradesTable SET \"$oldcolumnname\"=\'$maxpointpossible\' where UserName=\"_Max_Points_\"] + set err [catch {db eval $sql_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + if { $newcolumnname eq $oldcolumnname } { + # no need to mess with renaming + return + } + if { $newcolumnname == "" } { + htmlErrorMsg "empty column names are not permitted" + return + } + set eval_str [concat SELECT * FROM GradesTable ] + set err [catch {db eval $eval_str v {} } errStat] + set old_column_list $v(*) + # check if column with the suggested new name is already exist + foreach cname $old_column_list { + if { $cname eq $newcolumnname } { + htmlErrorMsg "The column name $newcolumnname is already exist" + return + } + } + # sqlite does not allow rename columns + # I will first create new column identical to the old one + AddColumnNonWeb $newcolumnname $column_category $maxpointpossible + set sql_str [concat UPDATE GradesTable SET \"$newcolumnname\"=\"$oldcolumnname\"] + set err [catch {db eval $sql_str } errStat] + # then delete the old one + DeleteColumnNonWeb $oldcolumnname +} + proc UpdateGrades { permission_list user } { global script_name set subaction [::ncgi::value subaction {}] -- cgit v1.2.3