Class Index

Classes


v1.2.1

DBTable

This class encapsulates information concerning a database table. Tables can be created by executing DBCatalog#createTable . Here is an example of creating a table:

	    db.catalog.createTable({
	    	tableName: "EMPL",
	    	columns: [ "EMPL_ID", "NAME", "AGE", "DEPT_ID" ],
	    	primaryKey: [ "EMPL_ID" ],
	    	data: [
	    		[0,"Bob",32,0],
	    		[1,"John",37,2],
	    		[2,"Fred",28,1],
	    		[3,"Sue",26,3],
	    		[4,"Beth",22,99],
	    		[5,"Mary",27,3],
	    		[6,"Adrian",24,1]
	    	]
	    });
	

Summary
Constructor Attributes Constructor Name and Description
This class encapsulates information concerning a database table.
Field Summary
Field Attributes Field Name and Description
The name of the table.
Method Summary
Method Attributes Method Name and Description
Deletes the specified row from the table.
Gets the current "persistence scope" of the table.
Inserts the specified row into the table.
This method replaces all of the rows in the table with the data provided.
setPersistenceScope (newPersistenceScope)
Sets the "persistence scope" of the table.
Updates the specified row in the table.
Detail
DBTable ()
This class encapsulates information concerning a database table.
See:
DBCatalog.createTable
Field Detail
{string} tableName
The name of the table.
Method Detail
{int} deleteRow (row)
Deletes the specified row from the table.

Here is an example of the usage:

	var rowsDeleted = db.catalog.getTable(tabName).deleteRow(row);
	

This method takes part in a transaction, so a DB#commit is required to finalize it, and a DB#rollback will revert the change.

Parameters:
{*[]} row
An array of values corresponding to a row in the table. This must be the same length as the number of columns in the table. When a primaryKey is defined on the table, only the primary key columns are used to match the row in the table. When no primaryKey is defined, all values in the row provided must match, and all rows in the table that match are deleted.
Throws:
{ Exception }
If row is not an array or does not contain the correct number of columns.
Returns:
{int} The number of rows deleted from the table. This can be greater than 1 when a primaryKey is not defined on the table and multiple rows have the same values matching every column in the row specified for deletion.
See:
DBTable#insertRow
DBTable#updateRow
DB#commit

{const} getPersistenceScope ()
Gets the current "persistence scope" of the table. The scope specifies whether the table will be stored in memory, in Session, or in a local storage mechanism. If this method returns DB.SCOPE_DEFAULT , then the catalog's persistence scope is used.
Returns:
{const} The persistence scope of the catalog.
See:
DBCatalog#getPersistenceScope
DBCatalog#isPersistenceScopeAvailable
DBTable#setPersistenceScope

{int} insertRow (row)
Inserts the specified row into the table. This method returns 1 or 0 indicating the number of rows inserted into the table. Effectively, this method will either return 1 or throw an exception due to a validation error.

If a primaryKey is defined on the table, validation is performed to ensure uniqueness of the primary key for the row being added. If the row being added will violate the primary key constraint, an exception is thrown.

Here is an example of the usage:

	var rowsInserted = db.catalog.getTable(tabName).insertRow(row);
	

This method takes part in a transaction, so a DB#commit is required to finalize it, and a DB#rollback will revert the change.

Parameters:
{*[]} row
An Array of values corresponding to the row to add to the table.
Throws:
{ Exception }
If row is not an array or does not contain the correct number of columns.
Returns:
{int} The number of rows inserted (1).
See:
DBTable#updateRow
DBTable#deleteRow
DB#commit

replaceData (rows)
This method replaces all of the rows in the table with the data provided.

This method takes part in a transaction, so a DB#commit is required to finalize it, and a DB#rollback will revert the change.

Parameters:
{*[][]} rows
An array of arrays corresponding to the row and column data of the table.
Throws:
{ Exception }
If any row is not an array or does not contain the correct number of columns.
{ Exception }
If a primaryKey is specified on the table, and multiple rows contain the same primary key.
See:
DBTable#insertRow
DB#commit

setPersistenceScope (newPersistenceScope)
Sets the "persistence scope" of the table. This specifies whether the table will be stored in memory, in Session, or in a local storage mechanism. When set to DB.SCOPE_DEFAULT , the scope of the catalog is used.

A table may only have a persistence scope that is "less than or equal to" the catalog's persistence scope, with the scope values defined as follows:

         DB.SCOPE_PAGE < DB.SCOPE_SESSION < DB.SCOPE_LOCAL

This method takes part in a transaction, so a DB#commit is required to finalize it, and a DB#rollback will revert the change.

Parameters:
{const} newPersistenceScope
The new Persistence Scope
Throws:
{ Exception }
If newPeristenceScope is greater than the catalog's persistence scope.
See:
DBCatalog#setPersistenceScope
DBCatalog#isPersistenceScopeAvailable
DBTable#getPersistenceScope
DB#commit

{int} updateRow (row)
Updates the specified row in the table. This method only works when a primaryKey is defined on the table, and the updated row being provided has its primary key columns matching an existing row in the table. This method returns 1 or 0 indicating the number of rows updated in the table. Effectively, if the primary key columns match an existing row, this returns 1, otherwise 0.

Here is an example of the usage:

	var rowsUpdated = db.catalog.getTable(tabName).updateRow(row);
	

This method takes part in a transaction, so a DB#commit is required to finalize it, and a DB#rollback will revert the change.

Parameters:
{*[]} row
A new array of values to replace a corresponding row in the table. The values in the primary key column(s) are used to match the new row against an existing row in the database. Values are copied out of the new row and into the table's existing row.
Throws:
{ Exception }
If row is not an array or does not contain the correct number of columns.
Returns:
{int} The number of rows updated (1 or 0).
See:
DBTable#insertRow
DBTable#deleteRow
DB#commit

©2012 Sequel Sphere, LLC.