Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

set

(To be removed) Set properties for database or cursor object

set will be removed in a future release. To set database data to read-only or automatically commit updates, use the ReadOnly and AutoCommit properties of the connection object instead.

drivermanager has been removed.

Syntax

set(object,'property',value)
set(object)

Description

set(object,'property',value) sets the value of property to value for the specified object.

set(object) displays all properties for object.

Valid values for object are:

Not all databases support all the properties. When you try to set a property that your database does not support, you receive an error message.

For connection objects and cursor objects, you can use the native ODBC interface with set. For details about establishing a connection using the native ODBC interface, see database.

connection Objects

Valid values for the property and value arguments for a connection object are as follows.

PropertyValueDescription

'AutoCommit'

'on'

The software writes and automatically commits database data when you run datainsert, fastinsert, insert, or update. You cannot use rollback to reverse this process.

'off'

The software does not automatically commit database data when you run datainsert, fastinsert, insert, or update. Use rollback to reverse this process. When you are sure that your data is correct, use the commit function to commit it to the database. Alternatively, use exec to roll back or commit data to the database.

'ReadOnly'

'off'

Not read-only; that is, writable

'on'

Read-only

Note

For some databases, if you insert data and close the database connection without committing the data to the database, then the data gets committed automatically. Your database administrator can tell you whether your database behaves this way.

cursor Objects

Valid values for the property and value arguments for a cursor object are as follows.

PropertyValueDescription

'RowLimit'

positive integer

Set the RowLimit for fetch. Specify this property instead of passing RowLimit as an argument to the fetch function. When you define RowLimit for fetch by using set, then fetch behaves differently depending on what type of database you are using.

Examples

Example 1 — Set RowLimit for cursor Object

Establish a JDBC connection to a data source. Run fetch to retrieve data from the table EMP, and then set the row limit to 5.

conn = database('orcl','scott','tiger',...
	'oracle.jdbc.driver.OracleDriver',...
	'jdbc:oracle:thin:@144.212.123.24:1822:');
curs = exec(conn,'SELECT * FROM EMP');
set(curs,'RowLimit',5)
curs = fetch(curs)
curs =

  cursor with properties:

     Attributes: []
           Data: {5x8 cell}
 DatabaseObject: [1x1 database]
       RowLimit: 5
       SQLQuery: 'SELECT * FROM EMP'
        Message: []
           Type: 'Database Cursor Object'
      ResultSet: [1x1 oracle.jdbc.driver.OracleResultSet]
         Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
      Statement: [1x1 oracle.jdbc.driver.OracleStatement]
          Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]

The RowLimit property of curs is 5 and the Data property is 5x8 cell, indicating that fetch returned five rows of data.

In this example, RowLimit limits the maximum number of rows you can retrieve. Therefore, rerunning the fetch function returns no data.

Example 2 — Set the AutoCommit Flag to On

Run datainsert on a database whose AutoCommit flag is set to on.

  1. Determine the status of the AutoCommit flag for the database connection conn.

    get(conn,'AutoCommit')
    
    ans =
    off
    

    The flag is off.

  2. Set the flag status to on and verify its value.

    set(conn,'AutoCommit','on');
    get(conn,'AutoCommit')
    
    ans =
    on
    
  3. Insert a cell array exdata into column names colnames in the table Growth.

    datainsert(conn,'Growth',colnames,exdata)
    

    The software inserts the data and commits the inserted data to the database.

Example 3 — Set the AutoCommit Flag to Off and Commit Data

Insert and commit data into a database whose AutoCommit flag is off.

  1. First set the AutoCommit flag to off for database connection conn.

    set(conn,'AutoCommit','off');
    
  2. Insert a cell array exdata into the column names colnames in the table Avg_Freight_Cost.

    datainsert(conn,'Avg_Freight_Cost',colnames,exdata)
    
  3. Commit the data to the database.

    commit(conn)
    

Example 4 — Set the AutoCommit Flag to Off and Roll Back Data

Update data in a database whose AutoCommit flag is off. Then use rollback to roll back the data.

  1. Set the AutoCommit flag to off for database connection conn.

    set(conn,'AutoCommit','off');
    
  2. Update the data in colnames in the Avg_Freight_Weight table, for the record selected by whereclause, with data from the cell array exdata.

    update(conn,'Avg_Freight_Weight',colnames,exdata,...
           whereclause)
    

    The software updates the data in the table but does not commit the data to the database.

  3. Roll back the data.

    rollback(conn)
    

    The database contains the original data present before running update.

Introduced before R2006a

Was this topic helpful?