diff options
-rwxr-xr-x | GradeBook_lib.tcl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 963f3a5..e31dd6c 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -355,6 +355,48 @@ proc GetDefaultGradesTableColumn {} { return $l } +proc ModifyWeightForGradesCategory {db category weight} { + if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} { + dbg "Category: $category already does not exists in the GradesCategoryTable, creating it" 3 + AddGradesCategory db $category + } + set eval_str [concat UPDATE GradesCategoryTable SET \"CategoryWeight\"='$weight' WHERE \"CategoryName\"=\'$category\'] + puts $eval_str + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + +proc AddGradesCategory {db category} { + if {[db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} { + dbg "Category: $category already exists in the GradesCategoryTable" 3 + return + } + set eval_str [concat INSERT INTO GradesCategoryTable (CategoryName) VALUES('$category')] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + +proc CreateGradesCategoryTable {db} { + # construct sql string for table creation + set sql_str {CREATE TABLE GradesCategoryTable(CategoryName text, CategoryWeight float)} + set err [catch {db eval $sql_str } errStat] + + if { $err && ($errStat ne "table GradesCategoryTable already exists") } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 1 + } + + foreach category [default_grades_category] { + AddGradesCategory db $category + } +} + proc CreateGradesTable {db} { # construct sql string for table creation set sql_str {CREATE TABLE GradesTable(} |