Jaxer.DB.SQLite.Connection : Object
Return to: Jaxer Framework index

Creates a new connection to the given databaseName (file).

Platform Support

Jaxer Server Framework Jaxer Client Framework
1.0 no

Constructors

Constructor Action Jaxer Server Framework Jaxer Client Framework
Jaxer.DB.SQLite.Connection Constructor(Object connectionParams) : Jaxer.DB.SQLite.Connection
Creates a new connection to the given database (file). If the given database does not yet exist, it is created for you when you try to open it. The resulting connection object is the only way you interact with the database.
Show Details 1.0 no

Jaxer.DB.SQLite.Connection(Object connectionParams) : Jaxer.DB.SQLite.Connection

Creates a new connection to the given database (file). If the given database does not yet exist, it is created for you when you try to open it. The resulting connection object is the only way you interact with the database.

Parameters
Object connectionParams A hashmap of parameters needed to connect to the database. The only required property is PATH: the path to the database (data) file. An optional CLOSE_AFTER_EXECUTE parameter specifies whether to close the connection after each call to execute; the default is to keep it open.

Returns
Jaxer.DB.SQLite.Connection Returns an instance of Connection.

Properties

Property Action Jaxer Server Framework Jaxer Client Framework
implementation : String
Returns the string identifying the database implementation of this connection. You can compare this e.g. to Jaxer.DB.SQLite.IMPLEMENTATION or Jaxer.DB.MySQL.IMPLEMENTATION
No Details 1.0 no
isOpen : Boolean
Is the connection currently open? Recall that even if the answer is no the connection would automatically be opened when needed.
No Details 1.0 no
lastInsertId : Number
Returns the unique "rowid" of the most recent successful INSERT command on the current connection. If the table has a column of type INTEGER PRIMARY KEY, this is used as the rowid. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is a synonym for lastInsertRowId. See http://www.sqlite.org/c3ref/last_insert_rowid.html for more details.
No Details 1.0 no
lastInsertRowId : Number
Returns the unique "rowid" of the most recent successful INSERT command on the current connection. If the table has a column of type INTEGER PRIMARY KEY, this is used as the rowid. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is a synonym for lastInsertId. See http://www.sqlite.org/c3ref/last_insert_rowid.html for more details.
No Details 1.0 no
version : String
Returns the string identifying the version of the database to which you are connected.
No Details 1.0 no

Functions

Method Action Jaxer Server Framework Jaxer Client Framework
close() : void
Closes the connection if it's open. This is optional, and only does something if the connection is open.
No Details 1.0 no
execute(String sql, Object params) : Array<Object>|Jaxer.DB.ResultSet|Number
Executes the given sql using the connection. If the SQL includes ?'s (question marks) as parameter placeholders, the values of those parameters should be passed in as extra arguments to this function, either as individual arguments or as a single array.
Show Details 1.0 no

Parameters
String sql The sql statement to be executed as a prepared statement
Object params The sequential parameters passed to the prepared statement for execution. If this is an array, it is used as the list of parameters. If this is one or more parameters, that is used as the list.

Returns
Array<Object> The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned.
Jaxer.DB.ResultSet The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned.
Number The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned.

Examples
 rs = conn.execute("SELECT * FROM myTable"); rs = conn.execute("SELECT * FROM myTable WHERE id=? AND zip=?", myId, myZip);
                        rs = conn.execute("SELECT * FROM myTable WHERE id=? AND zip=?", [ myId, myZip ] ); 
Returns the unique "rowid" of the most recent successful INSERT command on the current connection. If the table has a column of type INTEGER PRIMARY KEY, this is used as the rowid. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is the same as asking for the lastInsertRowId or lastInsertId properties. See http://www.sqlite.org/c3ref/last_insert_rowid.html for more details.
Show Details 1.0 no

Returns
Number The rowid, or 0

mapExecute(String sql, Array arrayOfParameters, [Object options]) : Object
Prepares the given SQL query string on the current default database (as defined in configApps.js) and then iteratively executes it over the given array of parameters.
Show Details 1.0 no

Parameters
String sql The SQL to execute, using ?'s (question marks) as parameter placeholders
Array arrayOfParameters An array of parameters to use for each execution. Each element of the array may itself be a single value or an array of values (corresponding to the ?'s in the SQL)
Object options (optional)An optional hashmap of options. Currently one option is supported: flatten. If its value is true, the returned result will be a single ResultSet with its rows being the concatenated rows of each query.

Returns
Object A corresponding array of Jaxer.DB.ResultSets or Numbers for each query, or a combined Jaxer.DB.ResultSet or Number if the 'flatten' option is true. For SELECT-type queries one or more Jaxer.DB.ResultSets are returned; for INSERT/UPDATE/DELETE-type queries the number of affected rows is returned.

Examples
 [ rsA, rsB ] = conn.mapExecute("SELECT * FROM myTable WHERE id=?", [ idA, idB ] ); [ rsA, rsB ] = conn.mapExecute("SELECT
                        * FROM myTable WHERE id=? AND zip=?", [ [ idA, zipA ] , [ idB, zipB ] ] ); 
See Also

Jaxer.DB.ResultSet

open() : void
Opens the connection so queries can be executed. This is optional, since if the connection is not open when it's asked to execute some SQL, it will open the connection automatically. Also closing the connection is optional.
No Details 1.0 no
test(Boolean keepOpen) : Object
Tests the connection by trying to connect and catching and returning any error encountered. If the connection is successful, returns a null.
Show Details 1.0 no

Parameters
Boolean keepOpen If true, the connection will be kept open (if the test was successful). If false, the connection will be left in the same state as before the test: if it was open before it will be kept open, otherwise it will be closed.

Returns
Object If successful, returns null; if unsuccessful, returns the error. Usually you can use the error's sqlErrorCode and sqlErrorDescription to see what the error was (or just its toString() method).

aptana_docs