Database Toolbox User's Guide
  Go to function:
    Search    Help Desk 
set    Examples   See Also

Set autocommit flag for database or rowlimit for fetch

Syntax

Description

set(cursor, 'rowlimit', value) sets the rowlimit for fetch to value, where value is a positive integer. This is an alternative to setting the rowlimit as an argument of fetch. You can use set to define rowlimit for JDBC connections, but not for ODBC connections; for ODBC connections, define rowlimit as an argument of fetch.

set(conn, 'autocommit', 'value') assigns a value to the autocommit flag for the database accessed via the connection conn, where value is on or off.

For command line help on set, use the overloaded methods:

Limitations

Microsoft Access does not use SQL commands and therefore has no rollback option. Setting the autocommit flag for a connection has no effect when you use insert or update to export data to a Microsoft Access database. The autocommit flag is always reported as on, and the data is always automatically written and committed.

Examples

Example 1 - Set rowlimit

This example uses set to define the rowlimit. It establishes a JDBC connection, retrieves all data from the emp table, sets the rowlimit to one, and uses fetch with no arguments to retrieve the data. Only one row of data is returned by fetch as you can see from the result of the rows command.

Run fetch again without a rowlimit argument to retrieve the next row of data.

Example 2 - Set autocommit flag to on

This example shows a database update when the autocommit flag is on. First determine the status of the autocommit flag for the database connection conn1:

The flag is off. Set the flag status to on and verify it:

Insert data, cell array G, into the column names ColNames of the Growth table:

The data is inserted and committed.

Example 3 - Set autocommit flag to off and commit data

This example shows a database insert when the autocommit flag is off and the data is then committed. First set the autocommit flag to off for database connection connA:

Insert data, cell array A, into the column names ColNames of the Avg_Freight_Cost table:

Commit the data:

Example 4 - Set autocommit flag to off and roll back data

This example shows a database update when the autocommit flag is off and the data is then rolled back. First set the autocommit flag to off for database connection connB:

Update the data in the column names specified by ColNames of the Avg_Freight_Weight table for the record selected by whereClause using data contained in cell array B:

The data was written but not committed.

Roll back the data:

The data in the table is now the same as it was before update was run.

See Also

database, exec, fetch, get, insert, update

[ Previous | Help Desk | Next ]