Database Toolbox Previous page   Next Page
setdbprefs

Set preferences for retrieval format, errors, and NULLs

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 nonnumeric 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. Nonnumeric 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 MATLAB Data Types 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'
Any numbers in the specified format, for example, NaN are represented as NULL 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'
Any strings in the specified format, for example, NaN, are represented as NULL when exported to a database. NaN is the default value.

Remarks

When you run clear all, the setdbprefs values are cleared and return to default values. It is a good practice to set or verify the setdbprefs values before each fetch.

Examples

Example 1--Display Current Values

Type setdbprefs and MATLAB returns

This specifies that

Example 2--Change a Value

Type setdbprefs ('NullNumberRead') and MATLAB returns

This specifies that any NULL number in the database is read into MATLAB as NaN.

To change the value to 0, type

This specifies 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

This specifies 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 Write Format for NULL Numbers

To specify the NullNumberWrite format as NaN, type

This specifies that any numbers represented as NaN in MATLAB are exported to a database as NULL.

For example, the variable ex_data, contains a NaN

Executing an insert for ex_data will export the NaN as NULL as in

Change the NullNumberWrite value to Inf.

Attempt to insert ex_data, which contains a NaN. MATLAB does not recognize the NaN in ex_data and generates an error.

Example 5--Change the ErrorHandling

Store:.   To specify the store format, type

This specifies 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

This specifies 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

This specifies 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 because no attributes could be created.

Example 6--Change Multiple Settings

Type

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

See Also

clear, fetch


Previous page  set sql2native Next page

© 1994-2005 The MathWorks, Inc.