First of all – I apoligize for hijacking this thread – it was about sqlite, not SQL Server.
But – if anyone’s interested, here’s a code snippet I wrote today (and tested) that loops through rows and processes each row. I’ve cut out some error handling for brevity.
==============================================
set sql “select LWMRN, FacilityCode from lwOpenAccounts'”
if {$debug} { echo “sqlstmt->”$sql”” }
# allocate a handle for the SQL statement
set errno [catch {odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt} result]
# execute the query
set errno [catch { odbc SQLExecDirect $hstmt $sql SQL_NTS } result]
# bind the data
set errno [catch
{ odbc SQLBindCol $hstmt 1 SQL_C_CHAR mrn 10 mrnlen } result]
set errno [catch
{ odbc SQLBindCol $hstmt 2 SQL_C_CHAR fac 10 faclen } result]
set i 1
# process row data until no rows left
while { 1 } {
# fetch a row
set errno [catch { odbc SQLFetch $hstmt } result]
if {![cequal $result “SQL_SUCCESS”] &&
![cequal $result “SQL_SUCCESS_WITH_INFO”]} {
break;
}
# process each row
echo “MRN = $mrn $mrnlen Facility = $fac $faclen $i”
incr i
}