trigger and sequence (SOLUTION)

jvd

New Member
Hi,all,

When converting from MSAccess to Progress91d, the problem arised that the 'autonumber' type from MSAccess doesn't exist within Progress (SQL).

Because only the database was converted to Progress and the MSAccess 'clients' will connect via ODBC to the Progress database, the autonumber function had to be executed by Progress.

So, the idea was to use a sequence and a trigger, that when a record is inserted with the MSAccess client, the recordid could automatically be filled by the trigger and sequence.

This can be done with the code (from Progress support) hereunder:

DROP TRIGGER increaseCustNum;
CREATE TRIGGER increaseCustNum
AFTER INSERT ON pub.customer
IMPORT
import java.sql.*;
BEGIN

Integer max = new Integer(0);

SQLCursor sqlc = new SQLCursor("SELECT pub.nextcustnum.nextval FROM sysprogress.sysdbauth");


sqlc.open();
sqlc.fetch();

if ( sqlc.found () ) {
max = (Integer) sqlc.getValue(1, INTEGER); }

sqlc.close();

int maxv = 0;
maxv = max.intValue();


String stmt = "UPDATE pub.customer SET custNum = " + maxv + " WHERE custNum = 0"; SQLIStatement update_stmt = new SQLIStatement( stmt );
update_stmt.execute();

END;
commit;
 
Top