diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-04-15 15:08:31 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-04-15 15:08:31 -0400 |
commit | 9eac2c005b37dc41a25b14e8adea5af743d5e468 (patch) | |
tree | 4c902964d69dfd92dfe3fe1b9795797a7f91b21e /GradeBook_lib.tcl | |
parent | 3c3981c6be0f3c53a6acfc46dd290f71cb4bb96b (diff) | |
download | GradeBook-9eac2c005b37dc41a25b14e8adea5af743d5e468.tar.gz GradeBook-9eac2c005b37dc41a25b14e8adea5af743d5e468.zip |
added function for creation and modification of grades category and its weight
Ignore-this: 218b29b4a903d338ffa6460025da5de4
darcs-hash:20110415190831-067c0-ef4c851bbc9070da38beab3fc4f3c7fa70845a71.gz
Diffstat (limited to 'GradeBook_lib.tcl')
-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(} |