diff options
-rwxr-xr-x | GradeBook_lib.tcl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 9514263..fc5cce3 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -1668,6 +1668,36 @@ proc removeElementFromList { element2remove old_list } { return $new_list } +proc RenameColumnNonWeb { oldcolumnname newcolumnname } { + 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 <b>$newcolumnname</b> is already exist" + return + } + } + # sqlite does not allow rename columns + # I will first create new column identical to the old one + set maxpointpossible 0 + set column_category _dummy_ + 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 DeleteColumnNonWeb { columnname } { DeleteColumnFromTable GradesTable $columnname |