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

Summary

Actions Summary Table

ActionsDescription
Add(Libraries.Data.Database.DatabaseColumn column)This action is used internally when the database metadata is updated.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetColumn(text name)This action returns a DatabaseColumn object that corresponds to the column that is in this DatabaseTable.
GetHashCode()This action gets the hash code for an object.
GetIterator()This action returns an Iterator object that allows for looping through all the columns in this table.
GetName()This action returns the name of the table as it is stored on the database.
GetSize()Returns the number of columns in the database table.
GetType()This action returns the type of table this is.
HasColumn(text name)This action returns true if the name given matches the name of a column in the table.
IsView()This action returns true if the table is a view.
SetName(text name)This action sets the name of this table.
SetType(text type)Used internally when the metadata is being updated.

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.

Example Code

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

Parameters

Return

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

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

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.

Example Code

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")

Parameters

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

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetIterator()

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

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

Return

Libraries.Containers.Iterator: Returns a DatabaseColumn iterator object

GetName()

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

Example Code

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()

Return

text: Returns the name of the table as text

GetSize()

Returns the number of columns in the database table.

Example Code

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()

Return

integer: Returns the number of column in this table

GetType()

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

Example Code

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()

Return

text: Returns the type of the table as text

HasColumn(text name)

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

Example Code

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

Parameters

Return

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

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.

Example Code

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()

Return

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

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

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