Programming Guide



@dmserial

Contains a serial column value after performing INSERT

Description

Some engines supply the data type serial to assist applications that need to assign a unique numeric value to each row in a table. When an application inserts a row in a table with a serial column, the engine generates a serial number, inserts the row with the number, and returns the number to the application. Refer to the Database Drivers for information about support for this on your engine.

Before executing a new DBMS command, Panther writes a 0 to @dmserial. If the statement is an INSERT and the engine returns a serial value, Panther writes the value to @dmserial. Since this variable is cleared before executing a new DBMS command, you must copy its value to another location if you want to use the value in subsequent commands.

Example

proc new_order
vars i(3), order_id(5)
DBMS BEGIN
# First INSERT row into invoices table.
# Column order_id in table invoices is a SERIAL.
DBMS RUN INSERT INTO invoices \
(order_id, order_date, cust_num) VALUES \
(0, :+today, :+cust_num)
# Copy the serial value to a JPL variable for use with
# subsequent INSERTS.
order_id = @dmserial
# Use order number to insert new rows to the orders
# table. Column order_id in table orders is an INT.
for i=1 while i<=max step 1
	DBMS RUN INSERT INTO orders \
(order_id, part_id, quant, u_cost) VALUES \
(:order_id, :+part_id[i], :+quant[i], :+u_cost[i])
DBMS COMMIT
msg emsg "Order completed. Invoice number is " order_id
return