SclInsert
Overview
This command creates a new insert operation for a database table. This allows you to create one new row in a database table.
Synopsis
$DatabaseHandle SclInsert InsertHandle $TableName
Description
Create a new insert operation for the specified table and assign the insert handle to a variable for later use.
Arguments
- DatabaseHandle
- InsertHandle
- TableName
The variable must contain a valid database handle.
Passed by reference. The variable to which the insert handle will be assigned.
Passed by value. The name of the database table into which the new row of data is to be inserted. Ideally all columns should have a value explicitly assigned using SclSetValueByName. Any column which is not explicitly assigned a value will be assumed to have a NULL value. If the database table does not permit NULL values for any columns that are not explicitly assigend a value the insert operation will throw a TCL error.
Returns
Returns $SCL_TRUE on successful execution. Throws a TCL error if there is no database connected or if the specified table does not exist in the database.
Examples
#
# Get the handle to an existing database and a new row in the collar table
#
if {[sclDatabases SclCountItems] < 1} {
error "No databases are connected"
}
sclDatabases SclGetItem DatabaseHandle 0
#
# create an insert operation for the collar table
#
$DatabaseHandle SclInsert InsertHandle "collar"
$InsertHandle SclSetValueByName date_drilled "2003-11-11"
$InsertHandle SclSetValueByName drilling_co "My company"
$InsertHandle SclSetValueByName geologist "Tony"
$InsertHandle SclSetValueByName hole_id "ZZZ"
$InsertHandle SclSetValueByName hole_path "curved"
$InsertHandle SclSetValueByName hole_type "RC"
$InsertHandle SclSetValueByName max_depth "100.0"
$InsertHandle SclSetValueByName prospect "Tony's Folly"
$InsertHandle SclSetValueByName x "100.123"
$InsertHandle SclSetValueByName y "200.456"
$InsertHandle SclSetValueByName z "10.5"
$InsertHandle SclProcess
SclDestroy InsertHandle
# now check that the row actually made it into the table
$DatabaseHandle SclQuery QueryHandle "collar"
$QueryHandle SclConstraint "hole_id == ZZZ"
# 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
|