Libraries.Data.Database.DatabaseMetaData Documentation

This class holds a table of all the database tables. This class allows for checking what tables exist on a database and from there it is possible to get more information about a specific table.

Example Code

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

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

DatabaseMetaData meta = database:GetDatabaseMetaData()
meta:QueryDatabaseForTables()
// output all the tables and all of their columns
Iterator<DatabaseTable> iterator = meta:GetIterator()
repeat while iterator:HasNext()
    DatabaseTable table = iterator:Next()
    output "=== " + table:GetName() + " === " + table:GetType() + " === "
    Iterator<DatabaseColumn> columns = table:GetIterator()
    repeat while columns:HasNext()
        DatabaseColumn column = columns:Next()
        output "    " + column:GetName()
    end
end

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Add(Libraries.Data.Database.DatabaseTable table)Used internally by plugins to fill out the metadata
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Empty()Clears the list of tables.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetIterator()Returns the Iterator for iterating through the database tables.
GetSize()This action returns how many tables are in the database.
GetTable(text name)Searches for table by name and returns the DatabaseTable which contains more information about the table stored in the database.
QueryDatabaseForTables()This action queries the database connection for any tables in the database and its columns, filling the in-memory representation of these objects for use.
RefreshTables()Some queries can add more tables or views which would alter the metadata.

Actions Documentation

Add(Libraries.Data.Database.DatabaseTable table)

Used internally by plugins to fill out the metadata

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.

Empty()

Clears the list of tables. Used to prevent the metadata from having duplicates if QueryForDatabaseForTables needs to be called multiple times.

Example Code

use Libraries.Data.Database.Database
        use Libraries.Data.Database.DatabaseMetaData
        use Libraries.Data.Database.DatabaseTable
        
        Database database
        database:Connect("localhost", "myDatabase", "user", "SuperSecret456")
        
        DatabaseMetaData meta = database:GetDatabaseMetaData()
        meta:QueryDatabaseForTables()

        meta:Empty()

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.

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

Returns the Iterator for iterating through the database tables. The iterator simplifies making a repeat statement for looping through all the database tables.

Example Code

use Libraries.Data.Database.Database
    use Libraries.Data.Database.DatabaseMetaData
    use Libraries.Data.Database.DatabaseTable
    use Libraries.Data.Database.DatabaseColumn
    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()
    end

Return

Libraries.Containers.Iterator:

GetSize()

This action returns how many tables are in the database.

Example Code

use Libraries.Data.Database.Database
    use Libraries.Data.Database.DatabaseMetaData
    
    Database database
    database:Connect("localhost", "myDatabase", "user", "SuperSecret456")
    
    DatabaseMetaData meta = database:GetDatabaseMetaData()
    meta:QueryDatabaseForTables()

    output "Number of tables: " + meta:GetSize()

Return

integer:

GetTable(text name)

Searches for table by name and returns the DatabaseTable which contains more information about the table stored in the database.

Example Code

use Libraries.Data.Database.Database
    use Libraries.Data.Database.DatabaseMetaData
    use Libraries.Data.Database.DatabaseTable
    
    Database database
    database:Connect("localhost", "myDatabase", "user", "SuperSecret456")
    
    DatabaseMetaData meta = database:GetDatabaseMetaData()
    meta:QueryDatabaseForTables()
    
    DatabaseTable table = meta:GetTable("myDB_table")
    output table:GetName()

Parameters

Return

Libraries.Data.Database.DatabaseTable:

QueryDatabaseForTables()

This action queries the database connection for any tables in the database and its columns, filling the in-memory representation of these objects for use. If this action is called multiple times, it will keep adding to the table, which means that refreshes of this object require calling Empty before use. Otherwise, we get duplicates.

Example Code

use Libraries.Data.Database.Database
        use Libraries.Data.Database.DatabaseMetaData
        use Libraries.Data.Database.DatabaseTable
        
        Database database
        database:Connect("localhost", "myDatabase", "user", "SuperSecret456")
        
        DatabaseMetaData meta = database:GetDatabaseMetaData()
        meta:QueryDatabaseForTables()

RefreshTables()

Some queries can add more tables or views which would alter the metadata. This action can be used to refresh the metadata so it can be up to data with the state of the database after a query.