Home

# Class goog.gears.Database

Class that for accessing a Gears database

extends goog.events.EventTarget

Instance Method Summary
| `begin() ⇒ boolean` Marks the beginning of a database transaction using the default begin type. Does a real BEGIN operation if useTransactions is true for this database and this is the first opened transaction. This will throw an exception if this is a nested begin and is trying to elevate the begin type from the original BEGIN that was processed.
| `beginDeferred() ⇒ boolean` Marks the beginning of a deferred database transaction. Does a real BEGIN operation if useTransactions is true for this database and this is the first opened transaction.
| `beginExclusive() ⇒ boolean` Marks the beginning of an exclusive database transaction. Does a real BEGIN operation if useTransactions is true for this database and this is the first opened transaction. This will throw an exception if this is a nested begin and is trying to elevate the begin type from the original BEGIN that was processed.
| `beginImmediate() ⇒ boolean` Marks the beginning of an immediate database transaction. Does a real BEGIN operation if useTransactions is true for this database and this is the first opened transaction. This will throw an exception if this is a nested begin and is trying to elevate the begin type from the original BEGIN that was processed.
| `beginTransaction_(string beginType) ⇒ boolean` Marks the beginning of a database transaction. Does a real BEGIN operation if useTransactions is true for this database and the this is the first opened transaction
| `close()` Closes the database.
| `closeTransaction_(boolean rollback) ⇒ boolean` Helper that performs either a COMMIT or ROLLBACK command and dispatches pre/post commit/rollback events.
| `commit() ⇒ boolean` Marks the end of a successful transaction. Will do a real COMMIT if this the last outstanding transaction unless a nested transaction was closed with a ROLLBACK in which case a real ROLLBACK will be performed.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `ensureNoTransaction(string= opt_logMsgPrefix)` Ensures there is no open transaction upon return. An existing open transaction is rolled back.
| `execute(string sql, <Any Type> var_args) ⇒ ?GearsResultSet` Execute a sql statement with a set of arguments
| `executeVarArgs_(string sql, ?Object params, number startIndex) ⇒ ?GearsResultSet` This is useful to remove all the arguments juggling from inside the different helper functions.
| `forEachRow(string sql, ?Function f, ?Object= opt_this, <Any Type> var_args)` For each row in the result set f will be called with the following parameters: row (array of values), rowIndex and columnNames. Rows will continue being processed as long as f returns true.
| `forEachValue(string sql, ?Function f, ?Object= opt_this, <Any Type> var_args)` For each value in the result set f will be called with the following parameters; value, rowIndex, columnIndex, columnName. Values will continue being processed as long as f returns true.
| `getExecutionTime() ⇒ number` Returns the time in Ms that database operations have currently consumed. This only exists in debug builds, but it still may be useful for goog.gears.Trace.
| `getLastInsertRowId() ⇒ number`
| `getUseTransactions() ⇒ boolean` Whether transactions are used for the database
| `isInTransaction() ⇒ boolean` Returns whether or not we're in a transaction.
| `needsRollback() ⇒ boolean` Returns whether or not the current transaction has a pending rollback. Returns false if there is no current transaction.
| `open()` Opens the database.
| `queryArray(string sql, <Any Type> var_args) ⇒ ?Array` This calls query on the database and returns the first row as an array
| `queryArrays(string sql, <Any Type> var_args) ⇒ ?Array` This calls query on the database and builds a two dimensional array containing the result.
| `queryObject(string sql, <Any Type> var_args) ⇒ ?Object` This calls query on the database and returns the first row as a hash map where the keys are the column names.
| `queryObjectArray(string sql, <Any Type> var_args) ⇒ ?Array` This calls query on the database and builds an array containing hashes
| `queryObject_(string sql, ?Function f, ?Object params, number startIndex) ⇒ (Object|boolean|null|number|string|undefined)` Helper methods for queryArrays, queryObjectArray, queryValueArray, queryValue, queryObject.
| `queryValue(string sql, <Any Type> var_args) ⇒ (null|number|string)` This calls query on the database and returns the first value in the first row.
| `queryValueArray(string sql, <Any Type> var_args) ⇒ ?Array` This calls query on the database and returns an array containing the values in the first column. This is useful if the result set only contains one column.
| `remove()` Removes the database.
| `rollback(?Error= opt_e) ⇒ boolean` Marks the end of an unsuccessful transaction. Will do a real ROLLBACK if this the last outstanding transaction, otherwise the real ROLLBACK will be deferred until the last outstanding transaction is closed.
| `setDefaultBeginType(string beginType)` Sets the default begin type.
| `setUseTransactions(boolean b)` Whether transactions are used for the database
| `transact(?Function func) ⇒ (Object|boolean|null|number|string|undefined)` Executes a function transactionally.

Static Method Summary
| `isLockedException((Error|null|string) ex) ⇒ boolean` Determines if the exception is a locking error.
| `resultSetToArray(?GearsResultSet rs) ⇒ ?Array` Returns an array of the first row in the result set
| `resultSetToArrays(?GearsResultSet rs) ⇒ ?Array` Returns an array of arrays, where each sub array contains the selected values for each row in the result set. result values
| `resultSetToObject(?GearsResultSet rs) ⇒ ?Object` Returns a single hashed object from the result set (the first row), where the column names in the query are used as the members of the object.
| `resultSetToObjectArray(?GearsResultSet rs) ⇒ ?Array.<(Object|null)>` Returns a array of hash objects, one per row in the result set, where the column names in the query are used as the members of the object.
| `resultSetToValue(?GearsResultSet rs) ⇒ (null|number|string)` Returns a single value from the results (first column in first row).
| `resultSetToValueArray(?GearsResultSet rs) ⇒ ?Array.<(Object|null)>` Returns an array containing the first item of each row in a result set. This is useful for query that returns one column