Main Content

exec

Execute SQL statement using SQLite connection

The exec function will be removed in a future release. Use the execute function to manage the SQLite database instead.

Description

exec(conn,sqlquery) performs database operations on an SQLite database file by executing the SQL statement sqlquery for the SQLite connection conn using the MATLAB® interface to SQLite. For example, use this syntax to create database tables in the SQLite database file. To import data into MATLAB from the SQLite database file, use the fetch function.

example

Examples

collapse all

Using the MATLAB® Interface to SQLite, create a table in a new SQLite database file.

Create the SQLite connection conn to the new SQLite database file tutorial.db. Specify the file name in the current folder.

dbfile = fullfile(pwd,'tutorial.db');

conn = sqlite(dbfile,'create');

Create the table inventoryTable using exec.

createInventoryTable = ['create table inventoryTable ' ...
    '(productNumber NUMERIC, Quantity NUMERIC, ' ...
    'Price NUMERIC, inventoryDate VARCHAR)'];

exec(conn,createInventoryTable)

inventoryTable is an empty table in tutorial.db.

To insert data into the database file, use the insert function.

Close the SQLite connection.

close(conn)

Input Arguments

collapse all

SQLite database connection, specified as an sqlite object created using the sqlite function.

SQL query, specified as a string scalar or character vector. You can specify the SQL query as a nested query or as a stored procedure.

For information about the SQL query language, see the SQL Tutorial on the W3Schools website.

Example: {CALL getSupplierInfo('New York")}

Data Types: string | char

Version History

Introduced in R2016a