| Database Toolbox™ | ![]() |
| On this page… |
|---|
Select Query > Generate M-File to create an M-file that contains the equivalent Database Toolbox functions required to run an existing query that was created in VQB. Edit the M-file to include MATLAB or related toolbox functions, as needed. To run the query, execute the M-file.
The following is an example of an M-file generated by VQB.
% Set preferences with setdbprefs.
s.DataReturnFormat = 'cellarray';
s.ErrorHandling = 'store';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.JDBCDataSourceFile = '';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = '';
setdbprefs(s)
% Make connection to database. Note that the password has been omitted.
% Using ODBC driver.
conn = database('dbtoolboxdemo','','password');
% Read data from database.
e = exec(conn,'SELECT ALL StockNumber,January,February FROM salesVolume');
e = fetch(e);
close(e)
% Close database connection.
close(conn)The following VQB query elements do not appear in generated M-files.
Generated M-files do not include MATLAB workspace variables to which you assigned query results in the VQB query. The M-file assigns the query results to e; access these results using the variable e.Data. For example, you can add a statement to the M-file that assigns a variable name to e.Data as follows:
myVar = e.Data
For security reasons, generated M-files do not include passwords required to connect to databases. Instead, the database statement includes the string 'password' as a placeholder. To run M-files to connect to databases that require passwords, substitute your password for the string password in the database statement.
![]() | Importing and Exporting BOOLEAN Data | Using Database Toolbox Functions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |