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
Actions Documentation
Add(Libraries.Data.Database.DatabaseTable table)
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
- Libraries.Language.Object: The object to compare to.
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)
Empty()
Clears the list of tables. Used to prevent the metadata from having duplicates if QueryForDatabaseForTables needs to be called multiple times.
Example
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.
Parameters
- Libraries.Language.Object: The to be compared.
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)
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()
Returns the Iterator for iterating through the database tables. The iterator simplifies making a repeat statement for looping through all the database tables.
Return
Example
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
GetSize()
This action returns how many tables are in the database.
Return
integer:
Example
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()
GetTable(text name)
Searches for table by name and returns the DatabaseTable which contains more information about the table stored in the database.
Parameters
- text name
Return
Example
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()
HasTable(text name)
Searches for table by name and returns true if the DatabaseTable is found.
Parameters
- text name
Return
boolean:
Example
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()
output meta:HasTable("myDB_table")
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
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.