Commits changes made to a buffered row, a buffered table, cursor, or cursor adapter.
TABLEUPDATE( [nRows [, lForce]] [, cTableAlias | nWorkArea] [, cErrorArray] )
Specifies which changes made to the table or cursor should be committed.
The following table describes the values for nRows.
Note: Visual FoxPro enables Optimistic Row Buffering by default for those cursors associated with a CursorAdapter object.
For compatibility with previous Visual FoxPro applications, the nRows parameter also accepts False (.F.) and True (.T.) instead of 0 and 1 respectively. When specifying 0 or 1 for nRows, the record pointer remains on the record where changes could not be committed. To determine why the changes could not be committed, use the AERROR(В ) function. When working with CursorAdapter objects and specifying 1 or 2 for nRows, all changes made to the cursor in the following CursorAdapter events must be committed during the same call to TABLEUPDATE( ) unless an error occurs:
If row or table buffering is enabled, commit only the changes made to the current row in the cursor. (Default)
If table buffering is enabled, commit changes made to all records to the table or cursor.
If row buffering is enabled, commit only changes made to the current record in the table or cursor.
When working with CursorAdapter objects, Visual FoxPro executes the appropriate commands in the InsertCmd, UpdateCmd, and DeleteCmd properties for each affected row.
Commit changes made to the table or cursor in the same manner as when nRows = 1. However, an error does not occur when a change cannot be committed. Visual FoxPro continues to process any remaining records in the table or cursor.
If cErrorArray is included, an array containing error information is created when an error occurs.
Determines whether Visual FoxPro overwrites changes made to the table or cursor by another user on a network.
The following table describes the values for lForce.
When working with CursorAdapter objects, Visual FoxPro passes the value of lForce to the following CursorAdapter events:
Commits changes to the table or cursor, starting with the first record and continuing towards the end of the table or cursor. (Default)
Overwrites any changes made to the table or cursor by another user on a network. The WHERE clause uses only key fields.
- Specifies the alias of the table or cursor in which the changes are committed. If you include a table or cursor alias, you must include the lForce argument.
- Specifies the work area of the table or cursor in which the changes are committed. If you include a work area, you must include the lForce argument.
Specifies the name of an array created when nRows = 2 and changes to a record cannot be committed. The array contains a single column containing the record numbers of the records for which changes could not be committed. If you include an array name, you must include either a table or cursor alias cTableAlias or a work area number nWorkArea.
Visual FoxPro passes the value of cErrorArray, when it exists, to the CursorAdapterAfterCursorUpdate event.
Note: If an error other than a simple commit error occurs while updating records, the first element of cErrorArray will contain вЂ“1, and you can then use AERROR(В ) to determine the why the changes could not be committed.
Logical data type. TABLEUPDATE(В ) returns True (.T.) if changes to all records are committed.
Otherwise, TABLEUPDATE(В ) returns False (.F.) indicating a failure. An ON ERROR routine isn't executed. The AERROR(В ) function can be used to retrieve information about the cause of the failure.
|TABLEUPDATE(В ) always returns True (.T.) when you are updating data, using Table Buffering, and updating the table or tables in the data source from multiple clients when setting BatchUpdateCount to a value greater than 1. Therefore, avoid setting BatchUpdateCount to a value greater than 1 in these scenarios.|
TABLEUPDATE(В ) cannot commit changes made to a table or cursor that does not have row or table buffering enabled. If you issue TABLEUPDATE(В ) and row or table buffering is not enabled, Visual FoxPro generates an error message. However, TABLEUPDATE(В ) can still commit changes to a table or cursor that has validation rules. To enable or disable row and table buffering, use CURSORSETPROP(В ).
Changes are committed to the table or cursor open in the currently selected work area if TABLEUPDATE(В ) is issued without the optional cTableAlias or nWorkArea arguments.
If table buffering is used and multiple records are updated, TABLEUPDATE(В ) moves the record pointer to the last record updated.
|Calling TABLEUPDATE(В ) for a local table or view that does not use key fields generates a long WHERE clause to find the update row. The default number of fields supported in the WHERE clause is 40. If you receive the error SQL: Statement too long (Error 1812), you should either use a key field for the update or increase the complexity of the WHERE clause with SYS(3055). If you use the SYS(3055) function, increase its value to a number that is eight times the number of fields in the table as shown in the following example:|
SYS(3055, 8 * MIN(40, FCOUNT( ))
When performing a batched TABLEUPDATE( ) operation, due to the way that Open Database Connectivity (ODBC) behaves, Visual FoxPro is unable to detect conflicts when no error is generated by the server, yet nothing is updated, for example, no row matches the WHERE clause. This can occur when you use WhereType set to DB_KEYANDUPDATABLE, DB_KEYANDMODIFIED, or DB_KEYANDTIMESTAMP, and another user has changed one of the underlying values in the WHERE clause such that the row is not found by the update statement.
Interaction with CursorAdapter ObjectsВ В В The following behaviors apply when working with CursorAdapter objects:
TABLEUPDATE( ) operates only on the cursor associated with the CursorAdapter object.
TABLEUPDATE( ) executes commands according to the data source type and those stored in the CursorAdapterInsertCmd, UpdateCmd, or DeleteCmd properties against the current cursor row or rows as appropriate.
TABLEUPDATE( ) passes the value of
GETFLDSTATE(1)to the following CursorAdapter events of each row affected:
GETFLDSTATE(В ) Function.
The successful completion of TABLEUPDATE( ) resets the field states according to usual TABLEUPDATE( )behavior.
When table buffering is enabled, you can move away from the current record in the following CursorAdapter events:
In Visual FoxPro 9.0, you cannot issue the TABLEREVERT( ) Function when a TABLEUPDATE(В ) is in operation.
Typically, the CursorAdapter object uses the transaction management functionality provided by the ADO or ODBC API's and Visual FoxPro closes transactions when the TABLEUPDATE(В ) function completes successfully. However, if you want to send transaction management commands directly to the backend, you can set the UseTransactions property of the CursorAdaptor object to False (.F.) and the CursorAdapter does not use transactions to send Insert, Update, or Delete commands.
The following example demonstrates how you can use TABLEUPDATE(В ) to commit changes made to a buffered table. A table named
employees is created, and a SQL INSERT statement inserts the value "Smith" into the
MULTILOCKS is set to
ON, which is a requirement for table buffering. CURSORSETPROP(В ) is used to set the buffering mode to Optimistic Table Buffering (5).
The original value of the
cLastName field (Smith) is displayed, and the
cLastName field is modified with REPLACE. The new value of the
cLastName field (Jones) is displayed. TABLEUPDATE(В )is used to commit changes to the table (TABLEREVERT(В ) could be issued instead to discard the changes). The updated value of the
cLastName field (Jones) is then displayed.
CLOSE DATABASES CREATE TABLE employee (cLastName C(10)) SET MULTILOCKS ON && Must turn on for table buffering. = CURSORSETPROP('Buffering', 5, 'employee' ) && Enable table buffering. INSERT INTO employee (cLastName) VALUES ('Smith') CLEAR ? 'Original cLastName value: ' ?? cLastName && Displays current cLastName value (Smith). REPLACE cLastName WITH 'Jones' ? 'New cLastName value: ' ?? cLastName && Displays new cLastName value (Jones). = TABLEUPDATE(.T.) && Commits changes. ? 'Updated cLastName value: ' ?? cLastName && Displays current cLastName value (Jones).