Release 10.1A: OpenEdge Data Management:
DataServer for ODBC

> ## Record creation

> Record creation is handled differently for OpenEdge databases and ODBC data sources accessed through the DataServer. The difference occurs because Progress 4GL code run against an OpenEdge database follows different record-scoping rules than 4GL code run against an ODBC data source. The code fragments in this section illustrate these differences.

> Suppose that you have a table called cust with a field called `cust-num` that is defined as an indexed field, and you write the following procedure:

>     DO TRANSACTION:
>     		CREATE customer.
>     		name = "SMITH".
>     		cust-num = 10.
>     		address = "1 Main St".
>     END.

> When you run this procedure:

> - The OpenEdge database does not create the record at the `CREATE` statement. Instead, it is written to the database at the end of the record scope or when the index information is supplied, whichever occurs first. In this example, the OpenEdge application writes the record after executing the statement `cust-num = 10`.

> - The DataServer writes the record at the end of the record scope. In this example, it writes the record after executing the statement `END`.

> The following procedure also illustrates the differences between the OpenEdge database and DataServer record creation:

>     DEFINE BUFFER xcust FOR customer.
>     CREATE customer.
>     cust-num = 111.
>     FIND xcust WHERE xcust.cust-num = 111.
>     DISPLAY xcust.

> In this procedure, the code creates a `customer`, sets `cust-num` equal to 111, then finds and displays the `customer` record using `cust-num` (the unique index). In this case:

> - The application with an OpenEdge database displays the `customer` 111 record.

> - The DataServer fails to find `customer` 111 because it has not yet written the record for `customer` 111 to the data source.

> To get a consistent response from the DataServer, use this procedure instead:

>     DEFINE BUFFER xcust FOR customer.
>     CREATE customer.
>     cust-num = 111.
>     VALIDATE customer. /* or RELEASE customer. */
>     FIND xcust WHERE xcust.cust-num = 111.
>     DISPLAY xcust.

> The `VALIDATE` or `RELEASE` statement causes the DataServer to write the `customer` 111 record to the database before the `FIND` statement occurs.

> Note: If you set the default value when creating a record, you must change the value before you create another record with the default value if the field is part of a unique key. Otherwise, the second record will cause a duplicate key.

> Record updates are handled similarly to record creation. A record is updated in an ODBC data source at the end of record scope or at the end of a transaction, whichever comes first. For example, when you run the following procedure, the newly updated record is not found:

>     FIND customer WHERE cust-num = 12.
>     DO TRANSACTION.
>       ASSIGN address = "14 Oak Park".
>       FIND customer WHERE address = "14 Oak Park".
>     END.

> To send the record to the data source sooner, use the `VALIDATE` statement, as follows:

>     FIND customer WHERE cust-num = 12.
>     DO TRANSACTION:
>     		ASSIGN address = "14 Oak Park".
>     		VALIDATE customer.
>     		FIND customer WHERE address = "14 Oak Park".
>     END.

> For more information about record scoping and transaction behavior, see the OpenEdge Development: Progress 4GL Handbook .

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095