Libraries.Data.Database.DatabaseTable Documentation

The DatabaseTable class holds information about the table that exists on a database. This information consists mostly of what columns the table contains and what type of table it is. The common table types are regular tables or a view. The DatabaseTable object corresponding to a table on a live database can be accessed through DatabaseMetaData.

Example Code

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Containers.Iterator

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

Iterator<DatabaseTable> iterator = meta:GetIterator()
repeat while iterator:HasNext()
DatabaseTable table = iterator:Next()
output "=== " + table:GetName() + " === " + table:GetType() + " === "
end

Inherits from: Libraries.Language.Object

Actions Documentation

Add(Libraries.Data.Database.DatabaseColumn column)

This action is used internally when the database metadata is updated. This adds columns to this table, not intended to be called by the user.

Parameters

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetColumn(text name)

This action returns a DatabaseColumn object that corresponds to the column that is in this DatabaseTable. The DatabaseColumn object has more information about the column such as the type of data it holds. If the column does not exist this action will return undefined.

Parameters

  • text name: The name of the column to grab from this table

Return

Libraries.Data.Database.DatabaseColumn: Returns the DatabaseColumn with the same name as given, if the table does not have that column then undefined will be returned

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
DatabaseColumn column = table:GetColumn("id")

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetIterator()

This action returns an Iterator object that allows for looping through all the columns in this table.

Return

Libraries.Containers.Iterator: Returns a DatabaseColumn iterator object

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Containers.Iterator

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

Iterator<DatabaseTable> iterator = meta:GetIterator()
repeat while iterator:HasNext()
    DatabaseTable table = iterator:Next()
    output "=== " + table:GetName() + " === " + table:GetType() + " === "
end

GetName()

This action returns the name of the table as it is stored on the database.

Return

text: Returns the name of the table as text

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
output table:GetName()

GetSize()

Returns the number of columns in the database table.

Return

integer: Returns the number of column in this table

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
output table:GetSize()

GetType()

This action returns the type of table this is. This will commonly return either "TABLE" or "VIEW".

Return

text: Returns the type of the table as text

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
output table:GetType()

HasColumn(text name)

This action returns true if the name given matches the name of a column in the table.

Parameters

  • text name: The name of the column to search for in this table

Return

boolean: Returns true if the table has the column, false otherwise

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
boolean hasID = table:HasColumn("id")
output hasID

IsView()

This action returns true if the table is a view. A view is a table on the database that is made up of rows and columns from the base tables. A view can be created from a Find query. The biggest difference is that you can not insert, or delete rows from a view but the entire view can be replaced or updated.

Return

boolean: Returns true if the table is a view, false otherwise

Example

use Libraries.Data.Database.Database
use Libraries.Data.Database.DatabaseMetaData
use Libraries.Data.Database.DatabaseTable
use Libraries.Data.Database.DatabaseColumn

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()

DatabaseTable table = meta:GetTable("myDB_table")
output "Table is view: " + table:IsView()

SetName(text name)

This action sets the name of this table. This is used internally when the database metadata is updated so this is not intended to be called by the user.

Parameters

  • text name

SetType(text type)

Used internally when the metadata is being updated. Sets the type of table this is. Either a view or a base table.

Parameters

  • text type