summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2011-04-15 19:56:42 -0400
committerEugeniy Mikhailov <evgmik@gmail.com>2011-04-15 19:56:42 -0400
commit2d31d52191ace6bbeccf4cfede8734d6bb494da4 (patch)
tree135681bcab6c81e48a55f7d34cef67f5cbedc686
parentcb78005bcae1d81b57f5506e03625d4db414edb8 (diff)
downloadGradeBook-2d31d52191ace6bbeccf4cfede8734d6bb494da4.tar.gz
GradeBook-2d31d52191ace6bbeccf4cfede8734d6bb494da4.zip
added low level sql table operations
Ignore-this: eb9e4fb5df02543752466696be0f3657 darcs-hash:20110415235642-067c0-94cb9059e483ca3db96863c7a1fc055112716956.gz
-rwxr-xr-xGradeBook_lib.tcl67
1 files changed, 46 insertions, 21 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index a101eca..cc455da 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -107,6 +107,26 @@ proc SelectColvalueFromTable { table column_of_interest col row_value } {
return $value
}
+proc existsColumnWithRowvalueInTable { table column row_value } {
+ set sql_str [concat SELECT 1 FROM \'$table\' WHERE \"$column\"=\"$row_value\"]
+ if {![db exists $sql_str]} {
+ dbg "Column \'$column\' does not have row with value \'$row_value\' in table \'$table\'" 3
+ return false
+ } else {
+ return true
+ }
+}
+
+proc UpdateColumnWithValueInTableWhere { table column val where_column row_value } {
+ set eval_str [concat UPDATE \'$table\' SET \"$column\"='$val' WHERE \"$where_column\"=\'$row_value\']
+ set err [catch {db eval $eval_str } errStat]
+ if { $err } {
+ set msg_str "Unable to update column $column in the table $table where $where_column=$row_value. The following error happen: $errStat"
+ htmlErrorMsg $msg_str
+ dbg $msg_str 3
+ }
+}
+
proc doesColumnExists {col table} {
if { $col in [getColListFromTable $table] } {
return true;
@@ -391,33 +411,23 @@ proc GetDefaultGradesTableColumn {} {
}
proc ModifyNeedsTotalForGradesCategory {db category flag} {
- if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
- dbg "Category: $category already does not exists in the GradesCategoryTable, creating it" 3
+ if {![existsColumnWithRowvalueInTable GradesCategoryTable CategoryName $category ]} {
+ dbg "Category: $category does not exists in the GradesCategoryTable, creating it" 3
AddGradesCategory db $category
}
- set eval_str [concat UPDATE GradesCategoryTable SET \"NeedsTotal\"='$flag' WHERE \"CategoryName\"=\'$category\']
- set err [catch {db eval $eval_str } errStat]
- if { $err } {
- htmlErrorMsg $errStat
- dbg "the following error happen: $errStat" 3
- }
+ UpdateColumnWithValueInTableWhere GradesCategoryTable NeedsTotal $flag CategoryName $category
}
proc ModifyWeightForGradesCategory {db category weight} {
- if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
+ if {![existsColumnWithRowvalueInTable GradesCategoryTable 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\']
- set err [catch {db eval $eval_str } errStat]
- if { $err } {
- htmlErrorMsg $errStat
- dbg "the following error happen: $errStat" 3
- }
+ UpdateColumnWithValueInTableWhere GradesCategoryTable CategoryWeight $weight CategoryName $category
}
proc AddGradesCategory {db category} {
- if {[db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
+ if {[existsColumnWithRowvalueInTable GradesCategoryTable CategoryName $category ]} {
dbg "Category: $category already exists in the GradesCategoryTable" 3
return
}
@@ -458,8 +468,12 @@ proc UpdateGradesCategores { db permission_list user } {
set eval_str "SELECT CategoryName FROM GradesCategoryTable"
set err [catch {
db eval $eval_str v {
- if { [info exist colval($v(CategoryName))] } {
- ModifyWeightForGradesCategory db $v(CategoryName) $colval($v(CategoryName))
+ if { [info exist colval($v(CategoryName)_weight)] } {
+ ModifyWeightForGradesCategory db $v(CategoryName) $colval($v(CategoryName)_weight)
+ }
+ if { [info exist colval($v(CategoryName)_needs_total)] } {
+ # check box existance means it set to true
+ ModifyNeedsTotalForGradesCategory db $v(CategoryName) true
}
}
} errStat ]
@@ -497,11 +511,22 @@ proc EditGradesCategories { db permission_list user } {
}
foreach index $v(*) {
if { $index != "*" } {
- if { $index eq "CategoryWeight" } {
- puts "<th><input type=\"text\" name=\"$v(CategoryName)\" value=\"$v(CategoryWeight)\" size=5></th>"
- } else {
+ switch $index {
+ "CategoryWeight" {
+ puts "<th><input type=\"text\" name=\"$v(CategoryName)_weight\" value=\"$v(CategoryWeight)\" size=5></th>"
+ }
+ "NeedsTotal" {
+ if { $v(NeedsTotal) eq "true" } {
+ set checkbox_flag "checked"
+ } else {
+ set checkbox_flag ""
+ }
+ puts "<th><input type=\"checkbox\" name=\"$v(CategoryName)_needs_total\" value=\"\" $checkbox_flag></th>"
+ }
+ default {
puts -nonewline "<td>$v($index)</td>"
}
+ }
}
}
puts "</tr>"