Last modified: 2012-12-5
Class SQLite
Max contains an implementation of the SQLite database engine (more info available @
http://sqlite.org).
This database engine is accessible through both the C-API and directly in Max through the JavaScript
interface. A tutorial on the Javascript interface written by Andrew Benson has been published on the
Cycling '74 website.
The Javascript interface is composed of two objects: SQLite and SQLResult. A SQLResult object is used
to represent the data returned by queries to the SQLite object. These objects are created in the same
manner as any object in Javascript, as shown below.
SQLite in Cycling '74 Reference
Constructor Attributes | Constructor Name and Description |
---|---|
SQLite()
Representation of a SQLite connection.
|
Method Attributes | Method Name and Description |
---|---|
void |
close()
closes the connection to previously opened database
|
void |
END TRANSACTION is an alias for COMMIT.
|
void |
exec(sql_query, result_object)
runs zero or more UTF-8 encoded, semicolon-separate SQL statements
|
Integer |
This routine returns the rowid of the most recent successful INSERT into the database.
|
void |
open(name, ram_based)
open an SQLite database file as specified by the filename argument.
|
void |
No changes can be made to the database except within a transaction.
|
Class Detail
SQLite
()
Representation of a SQLite connection.
All records returned by the SQLResult object are returned as strings. Thus, a numeric value such as 1
is actually returned as the string "1". SQLite only uses datatypes as recommendations. It does not enforce
data types and in fact always returns a string. More information about this and other SQLite-specific topics
can be found in a Google Talk given by Richard Hipp (the author of the SQLite library) @
video.google.com.
- Example:
var sqlite = new SQLite; var result = new SQLResult;
Method Detail
{void}
close
()
closes the connection to previously opened database
{void}
endtransaction
()
END TRANSACTION is an alias for COMMIT. See SQLite Reference
{void}
exec
(sql_query, result_object)
runs zero or more UTF-8 encoded, semicolon-separate SQL statements
- Parameters:
- {String} sql_query
- {SQLResult} result_object
{Integer}
lastinsertid
()
This routine returns the rowid of the most recent successful INSERT into the database.
Each entry in an SQLite table has a unique 64-bit signed integer key called the "rowid". The rowid is
always available as an undeclared column named ROWID, OID, or _ROWID_ as long as those names are not
also used by explicitly declared columns.
{void}
open
(name, ram_based)
open an SQLite database file as specified by the filename argument.
subject to test: (from http://www.sqlite.org/c3ref/open.html)
If the ram_based=1, then a private, temporary in-memory database is created for the connection. This in-memory database will vanish when the database connection is closed. Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.
If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.
subject to test: (from http://www.sqlite.org/c3ref/open.html)
If the ram_based=1, then a private, temporary in-memory database is created for the connection. This in-memory database will vanish when the database connection is closed. Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.
If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.
- Parameters:
- {String} name
- filename
- {Boolean} ram_based
{void}
starttransaction
()
No changes can be made to the database except within a transaction. Any command that changes the database
(basically, any SQL command other than SELECT) will automatically start a transaction if one is not already
in effect. Automatically started transactions are committed when the last query finishes.
Transactions can be started manually using the BEGIN (starttransaction) command. Such transactions usually persist until the
next COMMIT or ROLLBACK command. But a transaction will also ROLLBACK if the database is closed or if an error
occurs and the ROLLBACK conflict resolution algorithm is specified.
See SQLite Reference