Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

sqlite

SQLite connection

Description

The sqlite function creates a sqlite object. You can use this object to connect to a SQLite database file using the MATLAB® interface to SQLite. The MATLAB interface to SQLite lets you work with SQLite database files without installing and administering a database or driver. For details, see Working with MATLAB Interface to SQLite.

Creation

Syntax

conn = sqlite(dbfile)
conn = sqlite(dbfile,mode)

Description

example

conn = sqlite(dbfile) connects to an existing SQLite database file dbfile.

example

conn = sqlite(dbfile,mode) also can create a database file depending on the mode type mode.

Input Arguments

expand all

SQLite database file, specified as a character vector or string scalar. You can use the database file to store data and import and export it to MATLAB.

Data Types: char | string

SQLite database file mode, specified as one of these values.

ValueDescription

'connect'

Connect to an existing SQLite database file.

'readonly'

Create a read-only connection to an existing SQLite database file.

'create'

Create and connect to a new SQLite database file.

The file mode determines whether you connect to an existing SQLite database file or create a new one. For existing database files, the file mode determines whether the database connection is read-only.

Properties

expand all

SQLite database file name, specified as a character vector that contains the full path to the SQLite database file. To specify the SQLite database file name, use dbfile.

Example: 'C:\tutorial.db'

Data Types: char

Database connection indicator, specified as a logical 0 when the database connection is closed or invalid or a logical 1 when the database connection is open.

Data Types: logical

Read-only database file, specified as a logical 0 when the SQLite database file can be modified or logical 1 when the database file is read-only. To specify a read-only database file, use mode.

Data Types: logical

Object Functions

insertAdd MATLAB data to database tables
execExecute SQL statement and open cursor
fetchImport data into MATLAB workspace from database cursor or from execution of SQL statement
closeClose and invalidate database and driver resource utilizer

Examples

expand all

Create a SQLite connection to the MATLAB® interface to SQLite using the existing database file tutorial.db. Specify the file name in the current working folder.

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

conn = sqlite(dbfile)
conn = 

  sqlite with properties:

      Database: '/tmp/Bdoc17b_705616_27597/publish_examples0/tpdc794a7b/ex96650978/tutorial.db'
        IsOpen: 1
    IsReadOnly: 0

conn is a sqlite object with these properties:

  • Database -- SQLite database file name.

  • IsOpen -- SQLite connection is open.

  • IsReadOnly -- SQLite connection is writable.

Close the SQLite connection.

close(conn)

Create a SQLite connection to the MATLAB® interface to SQLite using a new database file tutorial.db. Specify the file name in the current working folder.

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

conn = sqlite(dbfile,'create')
conn = 

  sqlite with properties:

      Database: '/tmp/Bdoc17b_705616_27597/publish_examples0/tpdc794a7b/ex61952421/tutorial.db'
        IsOpen: 1
    IsReadOnly: 0

conn is a sqlite object with these properties:

  • Database -- SQLite database file name.

  • IsOpen -- SQLite connection is open.

  • IsReadOnly -- SQLite connection is writable.

Close the SQLite connection.

close(conn)

Create a read-only SQLite connection to the MATLAB® interface to SQLite using the existing database file tutorial.db. Specify the file name in the current working folder.

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

conn = sqlite(dbfile,'readonly')
conn = 

  sqlite with properties:

      Database: '/tmp/Bdoc17b_705616_27597/publish_examples0/tpdc794a7b/ex41829813/tutorial.db'
        IsOpen: 1
    IsReadOnly: 1

conn is a sqlite object with these properties:

  • Database -- SQLite database file name.

  • IsOpen -- SQLite connection is open.

  • IsReadOnly -- SQLite connection is read-only.

Close the SQLite connection.

close(conn)

Alternative Functionality

A sqlite object is one of the two available database connection types. The other creates a connection object using the database function. This object lets you connect to various relational databases using ODBC and JDBC drivers that you install and administer.

The sqlite object provides limited Database Toolbox™ functionality. For full functionality, create a database connection to the SQLite database file using the JDBC driver. To use the JDBC driver, close the SQLite connection and create a database connection using the URL string. For details, see these links depending on your platform.

Introduced in R2016a

Was this topic helpful?