diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-12-04 16:20:30 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-12-04 16:20:30 -0500 |
commit | 9ab8c9ec4c763d950bf166ec0646d2bff096c342 (patch) | |
tree | ce9ed099d06161e1b7418d92ca644076af27a397 | |
parent | de2a45af4940c5a0b9aa570743b8002c153b4d5f (diff) | |
download | GradeBook-9ab8c9ec4c763d950bf166ec0646d2bff096c342.tar.gz GradeBook-9ab8c9ec4c763d950bf166ec0646d2bff096c342.zip |
addded RenameColumnNonWeb
-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 |