Jaxer.DB.MySQL.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.MySQL.Connection Constructor(Object connectionParams) : Jaxer.DB.MySQL.Connection
Creates a new connection to the given databaseName. The resulting connection object is the only way to interact with the database.
Show Details 1.0 no

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

Creates a new connection to the given databaseName. The resulting connection object is the only way to interact with the database.

Parameters
Object connectionParams A hashmap of parameters for connecting to the database. Required properties are:
  • HOST (hostname of the server),
  • USER (username for authentication),
  • PASS (password for authentication, can be the empty string), and
  • NAME (database name, can be the empty string).
Optional parameters are:
  • PORT (connection port, default value is 3306),
  • SOCKET (absolute path to socket file, default value is null),
  • CLOSE_AFTER_EXECUTE (whether to close the connection after each call to execute, default is false), and
  • CLOSE_AFTER_REQUEST (whether to close the connection after each request, default is true).

Returns
Jaxer.DB.MySQL.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 ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. 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://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.
No Details 1.0 no
lastInsertRowId : Number
Returns the unique ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. 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://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.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) : Jaxer.DB.ResultSet|Number|Object[]
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. If the last argument is a (non-Array) object, it is used to pass in options. Currently two options are supported: dateHandler and useLocalTimezone. If dateHandler is given, it should be a function that takes the raw MySQL date/time/datetime string representation of a returned cell value, and a string describing the declared type, and returns the desired JavaScript representation. If dateHandler is not given, set useLocalTimezone to true to store date/time values using the local timezone. Otherwise, by default they are stored as UTC.
Show Details 1.0 no

Parameters
String sql The sql statement to be executed as a prepared statement

Returns
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. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.
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. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.
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. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.

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 ] ); 
getLastInsertId() : Number
Returns the unique ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. 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 lastInsertId or lastInsertRowId properties. See http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.
Show Details 1.0 no

Returns
Number The id, 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 three options are supported: flatten, dateHandler, and useLocalTimezone. If flatten is true, the returned result will be a single ResultSet with its rows being the concatenated rows of each query. If dateHandler is given, it should be a function that takes the raw MySQL date/time/datetime string representation of a returned cell value, and a string describing the declared type, and returns the desired JavaScript representation. If dateHandler is not given, set useLocalTimezone to true to store date/time values using the local timezone. Otherwise, by default they are stored as UTC.

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