Databases Reference
In-Depth Information
/* Execute a SELECT statement. A prepare is unnecessary
because it's executed only once. */
rc = SQLExecDirect((SQLHSTMT)hstmt, sqlStatement, SQL_NTS);
/* Fetch the first row */
rc = SQLFetch(hstmt);
while (rc != SQL_NO_DATA_FOUND) {
/* All rows are returned when fetch
returns SQL_NO_DATA_FOUND */
/* Get the data for each column in the result set row */
rc = SQLGetData (hstmt, 1, SQL_INTEGER, &id,
sizeof(id), NULL);
rc = SQLGetData (hstmt, 2, SQL_VARCHAR, &name,
sizeof(name), NULL);
rc = SQLGetData (hstmt, 3, SQL_INTEGER, &salary,
sizeof(salary), NULL);
printf("\nID: %d Name: %s Salary: %d", id, name, salary);
/* Fetch the next row of data */
rc = SQLFetch(hstmt);
}
/* Close the cursor */
rc = SQLFreeStmt ((SQLHSTMT)hstmt, SQL_CLOSE);
/* Whether a commit occurs after a SELECT statement
because auto-commit is on depends on the driver.
It's safest to assume a commit occurs here. */
/* Prepare the UPDATE statement for multiple executions */
strcpy (sqlStatement,
"UPDATE employees SET salary = salary * 1.05" +
"WHERE id = ?");
Search WWH ::




Custom Search