You are here: Surpac Concepts > Macros > SCL > Database Commands > SclUpdate
GEOVIA Surpac

SclUpdate

Overview

This command permits you to update rows that comply with the constraint clause to have certain values for specific columns.

Synopsis

$DatabaseHandle SclUpdate $Tablename

Description

It is important to use constraints with this command to restrict the rows that are updated. Use of this function without constraints will cause all rows in the table to be updated with new values.

It is not permitted to update values in a column that has an index associated with it.

The columns and associated new values are defined for the update operation by using SclSetValueByName.

If no rows are updated because of the constraint condition, a TCL error is returned.

Arguments

  • DatabaseHandle
  • The variable must contain a valid database handle.

  • UpdateHandle
  • Passed by reference. The variable to which the update handle will be assigned.

  • TableName
  • Passed by value. The name of the database table to which the update operation will be applied.

Examples

#
# Get the handle to an existing database and update all rows
# whose hole_id is >= Z
#
if {[sclDatabases SclCountItems] < 1} {
  error "No databases are connected"
} 
sclDatabases SclGetItem DatabaseHandle 0
#
# create an insert operation for the collar table
#
$DatabaseHandle SclUpdate UpdateHandle "collar"
$UpdateHandle SclSetValueByName max_depth 234.567
$UpdateHandle SclConstraint "hole_id >= Z"
$UpdateHandle SclProcess
SclDestroy UpdateHandle
# now display the modified row
# now check that the row actually made it into the table
$DatabaseHandle SclQuery QueryHandle "collar"
$QueryHandle SclConstraint "hole_id >= Z"
# get handle to the collar table
$DatabaseHandle SclIterateFirst DatabaseIterator
while {[$DatabaseIterator SclIterateNext TableHandle]} {
  if {"[$TableHandle SclGetId]" == "collar"} {
    break
  }
}
# register all columns in the collar table
$TableHandle SclIterateFirst TableIterator
while {[$TableIterator SclIterateNext ColumnName]} {
  $QueryHandle SclQueryColumn $ColumnName
  lappend ColumnNames $ColumnName
}
puts "Column names = $ColumnNames"
$QueryHandle SclProcess
$QueryHandle SclGetIterator QueryIterator
while {[$QueryIterator SclIterateNext RowHandle] == $SCL_TRUE} {
  # iterate over all values in the row and append them for display purposes
  $RowHandle SclIterateFirst RowIterator
  while {[$RowIterator SclIterateNext ColumnValue]} {
      lappend values $ColumnValue
  }
  
  # now display the values for this row
  puts "Row values = $values"
  unset values
}
SclDestroy QueryHandle