Database Toolbox    
setdbprefs

Set preferences for data retrieval format, error notification, and NULL values

Graphical Interface

As an alternative to the setdbprefs function, you can select Preferences from the Visual Query Builder File menu and use the Preferences dialog box.

Syntax

Description

setdbprefs returns the current values for database action preferences.

setdbprefs('property') returns the current preference value for the specified property.

setdbprefs('property', 'value') sets the preference to value for the specified property for the current session.

setdbprefs({'property1'; ... }, {'value1'; ... }) for the properties starting with property1, sets the preference values starting with value1, for the current session.

Allowable properties are listed in the following table.

Allowable Properties
Allowable Values
Description  
'DataReturnFormat'

Format for data imported into MATLAB. Select a value based on the type of data you are importing, memory considerations, and your preferred method of working with retrieved data. Set the value before using fetch.

'cellarray' (default)
Imports data into MATLAB cell arrays. Use for non-numeric data types. Requires substantial system memory when retrieving large amounts of data. Has slower performance than numeric format. To address memory problems, use the RowLimit option with fetch. For more information about cell arrays, see Working with Cell Arrays in MATLAB.

'numeric'
Imports data into a MATLAB matrix of doubles. Non-numeric data types are considered to be NULL numbers and are shown as specified for the NullNumberRead property. Uses less system memory and offers better performance than the cellarray format. Use only when data to be retrieved is in numeric format, or when the nonnumeric data retrieved is not relevant.

'structure'
Imports data as a MATLAB structure. Can use for all data types. Makes it easy to work with returned columns. Requires substantial system memory when retrieving large amounts of data. Has slower performance than numeric format. To address memory problems, use the RowLimit option with fetch. For more information on using structures, see Structures and Cell Arrays" in the MATLAB documentation.
'ErrorHandling'

Behavior for handling errors when importing data. Set the value before running exec.

'store' (default)
Any errors from running database are stored in the Message field of the returned connection object. Any errors from running exec are stored in the Message field of the returned cursor object.

'report'
Any errors from running database or exec display immediately in the Command Window.

'empty'
Any errors from running database are stored in the Message field of the returned connection object. Any errors from running exec are stored in the Message field of the returned cursor object. Objects that cannot be created are returned as empty handles, [ ].
'NullNumberRead'
User-specified, for example, '0'
How NULL numbers in a database are represented when imported into MATLAB. NaN is the default value. Cannot specify a string value, such as 'NULL', if 'DataReturnFormat' is set to 'numeric'. Set the value before using fetch.
'NullNumberWrite'
User-specified, for example, 'NaN'
How NULL numbers in MATLAB are represented when exported to a database. NaN is the default value.
'NullStringRead'
User-specified, for example, 'null'
How NULL strings in a database are represented when imported into MATLAB. NaN is the default value. Set the value before using fetch.
'NullStringWrite'
User-specified, for example, 'NULL'
How NULL strings in MATLAB are represented when exported to a database. NaN is the default value.

Examples

Example 1--Display Current Values

Type setdbprefs and MATLAB returns

which means

Example 2--Change a Value

Type setdbprefs ('NullNumberRead') and MATLAB returns

which means that any NULL number in the database is read into MATLAB as NaN.

To change the value to 0, type

which means that any NULL number in the database is read into MATLAB as 0.

Example 3--Change the DataReturnFormat

Cell array: To specify the cellarray format, type

which means that data is imported into MATLAB cell arrays. The following illustrates a subsequent import.

Numeric: Specify the numeric format by typing

Performing the same set of import functions results in

In the database, the values for ProductName are all character strings, as seen in the previous results when DataReturnFormat is set to cellarray. The ProductName values cannot be read when they are imported using the numeric format. Therefore, MATLAB treats them as NULL numbers and assigns them as NaN, which is the current value for the NullNumberRead property of setdbprefs in this example.

Structure: Specify the structure format by typing

Performing the same set of import functions results in

View the contents of the structure to see the data.

Example 4--Change the ErrorHandling

Store: To specify the store format, type

which means that any errors from running database or exec are stored in the Message field of the returned connection or cursor object.

The following illustrates an example of trying to fetch from a closed cursor.

The error indication appears in the Message field.

Report: To specify the report format, type

which means that any errors from running database or exec display immediately in the Command Window.

The following illustrates the same example as above when trying to fetch from a closed cursor.

The error indication appears immediately in the Command Window.

Empty: To specify the empty format, type

which means that any errors from running database or exec are stored in the Message field of the returned connection or cursor object. In addition, objects that cannot be created are returned as empty handles, [ ].

The following illustrates the same example as above when trying to fetch from a closed cursor.

The error indication appears in the cursor object Message field. In addition, the Attributes field returned empty handles since no attributes could be created.

Example 5--Change Multiple Settings

Type

which means any NULL string in the database is read into MATLAB as 'NaN', and data is retrieved into a matrix of doubles.


  set sql2native