SQL/MP Programming Manual for C
Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for C—429847-008
4-11
Updating a Single Row
NonStop SQL/MP returns these values to sqlcode after an UPDATE statement.
The UPDATE statement updates rows in sequence. If an error occurs, NonStop
SQL/MP returns an error code to sqlcode and terminates the UPDATE operation.
The SQLCA structure contains the number of rows that have been updated. (If the
UPDATE statement fails, do not rely on the SQLCA structure for an accurate count of
the number of updated rows.) To return the contents of the SQLCA structure, use the
SQLCADISPLAY or SQLCATOBUFFER procedure.
For more information, see Section 5, SQL/MP System Procedures and Section 9, Error
and Status Reporting.
Updating a Single Row
This example updates a single row of the ORDERS table that contains information
about the order number specified by update_ordernum. In a typical application, a
user enters the values for update_date and update_ordernum.
EXEC SQL BEGIN DECLARE SECTION;
struct orders_type
{
long ordernum;
long order_date;
long deliv_date;
short salesrep;
short custnum;
} orders;
long newdate;
EXEC SQL END DECLARE SECTION;
...
...
void update_orders(void)
{ ...
newdate = update_date;
orders.ordernum = update_ordernum;
EXEC SQL UPDATE sales.orders SET deliv_date = :newdate
WHERE ordernum = :orders.ordernum
STABLE ACCESS;
...
}
sqlcode Value Description
0 The UPDATE statement was successful.
100 No rows were found on a search condition.
<0 An error occurred;
sqlcode contains the error number.
>0 (¦100) A warning occurred;
sqlcode contains the first warning number.