isopen - Determine if SQLite connection is open - MATLAB (original) (raw)
Connect to an SQLite database and verify the database connection. Then, import data from the database into MATLABĀ®. Determine the highest unit cost among the retrieved products in the table. Close the database connection.
Create the SQLite connection conn
to the existing SQLite database file tutorial.db
. The database file contains the table productTable
. The SQLite connection is an sqlite
object.
dbfile = "tutorial.db"; conn = sqlite(dbfile);
Determine if the database connection is open. The isopen
function returns the numeric scalar 1
, which means the database connection is open.
Select all the data from productTable
and sort it by the product number. data
is a table containing the imported data that results from executing the SQL SELECT
statement.
sqlquery = "SELECT * FROM productTable ORDER BY productNumber"; data = fetch(conn,sqlquery);
Display the first three rows of data.
productNumber stockNumber supplierNumber unitCost productDescription
_____________ ___________ ______________ ________ __________________
1 400345 1001 14 "Building Blocks"
2 400314 1002 9 "Painting Set"
3 400999 1009 17 "Slinky"
Determine the highest unit cost in the table.
Close the database connection.
Determine if the database connection is closed. The isopen
function returns the numeric scalar 0
, which means the database connection is closed. If the database connection is invalid, the isopen
function returns the same result.