db

DB.close

DB.close()

Closes the database connection for this DB object instance. In case of error an exception will be thrown.

DB.closeAllStatements

DB.closeAllStatements()

Tries to close all prepared statements for this DB object instance. If an error occurs during this process an exception will be thrown.

DB.closeStatement

DB.closeStatement(aStatement)

Closes the corresponding prepared statement. If an error occurs during this process an exception will be thrown.

DB.commit

DB.commit()

Commits to the database the current database session on the current DB object instance. In case of error an exception will be thrown.

DB.convertDates

DB.convertDates(aFlag)

Sets to true or false (defaults to false) the conversion of Dates to javascript Date objects instead of strings.

DB.db

DB.db(aDriver, aURL, aLogin, aPassword, aTimeout)

Creates a new instance of the object DB providing java class aDriver (e.g. oracle.jdbc.OracleDriver) that must be included on OpenAF's classpath, a JDBC aURL, aLogin and aPassword. If the aDriver is  null or undefined the Oracle driver will be used. Optionally you can provide aTimeout in ms.

Examples of JDBC URLs:

- Oracle Thin: jdbc:oracle:thin:@::
- PostgreSQL : jdbc:postgresql://:/
- H2         : jdbc:h2:

DB.getAutoCommit

DB.getAutoCommit() : boolean

Retrieves the current database connection auto-commit flag state.

DB.getConnect

DB.getConnect() : JavaObject

Returns a Java database connection.

DB.getStatements

DB.getStatements() : Array

Returns the current list of database prepared statements that weren't closed it. Do close them, as soon as possible, using the DB.closeStatement or DB.closeAllStatements functions.

DB.h2StartServer

DB.h2StartServer(aPort, aListOfArguments) : String

Starts a H2 server on aPort (if provided) with an array of arguments (supported options are:  -tcpPort, -tcpSSL, -tcpPassword, -tcpAllowOthers, -tcpDaemon, -trace, -ifExists, -baseDir, -key). After creating the access URL will be returned. In case of error an exception will be thrown.

DB.h2StopServer

DB.h2StopServer()

Stops a H2 server started for this DB instance.

DB.q

DB.q(aQuery) : Map

Performs aQuery (SQL) on the current DB object instance. It returns a Map with a results array that will have an element per result set line. In case of error an exception will be  thrown.

DB.qLob

DB.qLob(aSQL) : Object

Performs aSQL query on the current DB object instance. It tries to return only the first result set row and the first object that can be either a CLOB (returns a string) or a BLOB (byte array). In case of error an exception will be thrown.

DB.qs

DB.qs(aQuery, arrayOfBindVariables, keepStatement) : Map

Performs aQuery (SQL) on the current DB object instance using the bind variables from the arrayOfBindVariables. It returns a Map with a results array that will have an element per result set line. In case of error an  exception will be thrown. Optionally you can specify to keepStatement (e.g. boolean) to keep from closing the prepared statement used for reuse in another qs call. If you specify to use keepStatement do close this query, as soon as possible, using DB.closeStatement(aQuery) (where you provide an exactly equal statement to  aQuery) or DB.closeAllStatements.

DB.qsRS

DB.qsRS(aQuery, arrayOfBindVariables) : Map

Performs aQuery (SQL) on the current DB object instance using the bind variables from the arrayOfBindVariables. It returns a java ResultSet object that should be closed after use. In case of error an  exception will be thrown. If you specify to use keepStatement do close this query, as soon as possible, using DB.closeStatement(aQuery) (where you provide an exactly equal statement to  aQuery) or DB.closeAllStatements.

DB.rollback

DB.rollback(dontIgnoreError)

Rollbacks the current database session on the current DB object instance. In case of error an exception will be thrown if dontIgnoreError = true

DB.setAutoCommit

DB.setAutoCommit(aFlag)

Sets to true or false (defaults to false) the current database connection auto-commit.

DB.u

DB.u(aSQL) : Number

Executes a SQL statement on the current DB object instance. On success it will return the number of rows affected. In case of error an exception will be thrown.

DB.uLob

DB.uLob(aSQL, aLOB) : Number

Executes a SQL statement on the current DB object instance to update a CLOB or BLOB provided in aLOB. On success it will return the number of rows affected. In case of error an exception will be thrown.

DB.uLobs

DB.uLobs(aSQL, anArray) : Number

Executes a SQL statement on the current DB object instance that can have CLOB or BLOB bind variables that can be specified on anArray. On success it will return the number of rows affected. In case of error an exception will be thrown.

DB.us

DB.us(aSQL, anArray, keepStatement) : Number

Executes a SQL statement on the current DB object instance that can have bind variables that  can be specified on anArray. On success it will return the number of rows affected. In case of error an exception will be thrown. Optionally you can specify to keepStatement (e.g. boolean) to keep from closing the prepared statement used for reuse in another us call. If you specify to use keepStatement do close this query, as soon as possible, using DB.closeStatement(aQuery) (where you provide an exactly equal statement to  aQuery) or DB.closeAllStatements.

DB.usArray

DB.usArray(aSQL, anArrayOfArrays, aBatchSize, keepStatement) : Number

Executes, and commits, a batch of a SQL statement on the current DB object instance that can have bind variables that  can be specified on an array, for each record, as part of anArrayOfArrays. On success it will return the number of rows  affected. In case of error an exception will be thrown. Optionally you can specify to keepStatement (e.g. boolean) to keep from closing the prepared statement used for reuse in another usArray call. If you specify to use keepStatement do close this query, as soon as possible, using DB.closeStatement(aQuery) (where you provide an exactly equal statement to  aQuery) or DB.closeAllStatements. You can also specify aBatchSize (default is 1000) to indicate when a commit should be performed while executing aSQL for each array of bind variables in anArrayOfArrays.

Example:

var values = [ [1,2], [2,2], [3,3], [4,5]];
db.usArray("INSERT INTO A (c1, c2) VALUES (?, ?)", values, 2);