Qore SqlUtil Module Reference  1.5.2
SqlUtil::Tables Class Reference

the table container class stores a collection of tables in a schema More...

Inheritance diagram for SqlUtil::Tables:

Public Member Methods

 add (string k, Table val)
 adds the given value to the hash with the given key name
 
 add (string k, AbstractTable val)
 adds the given value to the hash with the given key name
 
 add (Table val)
 adds the given value to the hash with the given key name
 
 add (AbstractTable val)
 adds the given value to the hash with the given key name
 
 constructor ()
 creates an empty object
 
 constructor (AbstractDatasource ds, hash tables, *hash< auto > opt)
 creates and populates the object from a hash<auto> description
 
 constructor (AbstractDatasource ds)
 creates and populates the object from tables in the database
 
Qore::AbstractIterator dropIterator ()
 returns an iterator for a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies More...
 
AbstractTable get (AbstractDatasource ds, string name)
 gets a table from the database or from the cache if already cached
 
*list< auto > getDropAllForeignConstraintsOnTableSql (string name, *hash< auto > opt)
 returns a list of SQL strings that can be used to drop all the foreign constraints on a particular table More...
 
*string getDropConstraintIfExistsSql (string tname, string cname, *hash< auto > opts)
 returns an SQL string that can be used to drop an existing constraint on a table, if the table is not already cached or the constraint does not exist, then NOTHING is returned More...
 
list< auto > getDropList ()
 returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies More...
 
string getElementName ()
 returns "table" since this object stores AbstractTable objects
 
*AbstractTable getIfExists (AbstractDatasource ds, string name)
 gets a table from the database or from the cache if already cached; if the table does not exist, then NOTHING is returned
 
*string getRenameTableIfExistsSql (string old_name, string new_name, *hash< auto > opts)
 returns an SQL string that can be used to rename the given table if it exists and the target does not exist, otherwise returns NOTHING More...
 
AbstractTable memberGate (string k)
 returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception More...
 
 populate (AbstractDatasource ds, hash tables, *hash< auto > opt)
 populates the object from a hash<auto> description
 
 populate (AbstractDatasource ds)
 populates the object from tables in the database
 
bool tableRenamed (string old_name, string new_name, string old_sql_name)
 updates table names and internal references for renamed tables More...
 
AbstractTable take (string k)
 removes the given key from the contained hash and returns the value
 
- Public Member Methods inherited from SqlUtil::AbstractHashContainer
 clear ()
 purges the contained data More...
 
 constructor (*hash nh)
 creates the object with the hash argument passed
 
 constructor (AbstractHashContainer old)
 creates a copy of the object
 
 copy (AbstractHashContainer old)
 creates a "deep copy" of the object
 
bool empty ()
 returns True if the container is empty, False if not
 
*string firstKey ()
 Returns the first key name in the contained hash or NOTHING if the contained hash has no keys. More...
 
*hash< auto > getHash ()
 returns the hash contained by this object
 
bool hasKey (string k)
 Returns True if the key exists in the contained hash (may or may not be assigned a value), False if not. More...
 
bool hasKeyValue (string k)
 Returns True if the key exists in the contained hash and is assigned a value, False if not. More...
 
Qore::AbstractIterator iterator ()
 Returns a HashIterator object for the contained hash. More...
 
Qore::AbstractIterator keyIterator ()
 Returns a HashKeyIterator object for the contained hash. More...
 
list< stringkeys ()
 Returns a list of key names of the contained hash. More...
 
*string lastKey ()
 Returns the last key name in the contained hash or NOTHING if the contained hash has no keys. More...
 
bool matchKeys (hash h1)
 returns True if the hash argument has the same keys (in any order), False if not More...
 
bool matchKeys (list< auto > l)
 returns True if the list<auto> argument has the same list of key strings as the keys in the object (in any order), False if not More...
 
bool matchKeys (AbstractHashContainer c)
 returns True if the container argument has the same keys (in any order), False if not More...
 
auto memberGate (string k)
 returns the value of the given key in the contained hash if it exists, otherwise throws a KEY-ERROR exception More...
 
Qore::AbstractIterator pairIterator ()
 Returns a HashPairIterator object for the contained hash. More...
 
bool partialMatchKeys (hash h1)
 returns True if the hash argument has at least the same keys (in any order, can have more keys), False if not More...
 
bool partialMatchKeys (list< auto > l)
 returns True if the list<auto> argument has at least the same keys (in any order, can have more keys), False if not More...
 
bool partialMatchKeys (AbstractHashContainer c)
 returns True if the container argument has at least the same keys (in any order, can have more keys), False if not More...
 
 renameKey (string old_name, string new_name)
 renames the given key; maintains the key order
 
int size ()
 Returns the number of keys in the contained hash. More...
 
bool val ()
 Returns False if the contained hash has no keys, True if it does. More...
 
list< auto > values ()
 Returns a list of values of the contained hash. More...
 

Additional Inherited Members

- Private Attributes inherited from SqlUtil::AbstractHashContainer
*hash h
 the data to be contained
 

Detailed Description

the table container class stores a collection of tables in a schema

Member Function Documentation

◆ dropIterator()

Qore::AbstractIterator SqlUtil::Tables::dropIterator ( )

returns an iterator for a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies

Example:
map $1.drop(), tables.getDropIterator();
Returns
an iterator for a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies

◆ getDropAllForeignConstraintsOnTableSql()

*list<auto> SqlUtil::Tables::getDropAllForeignConstraintsOnTableSql ( string  name,
*hash< auto >  opt 
)

returns a list of SQL strings that can be used to drop all the foreign constraints on a particular table

Example:
*list<auto> l = tables.getDropAllForeignConstraintsOnTableSql(name);

Make sure that all relevant tables are cached before calling this method; if the table is not cached, then NOTHING is returned

Parameters
namethe name of the table to find all the foreigjn constraints for
opta hash of options for the SQL strings; see AbstractDatabase::DropSchemaOptions for common options; each driver can support additional driver-specific options
Returns
a list of SQL strings that can be used to drop all the foreign constraints on a particular table
Exceptions
OPTION-ERRORinvalid or unsupported option passed

◆ getDropConstraintIfExistsSql()

*string SqlUtil::Tables::getDropConstraintIfExistsSql ( string  tname,
string  cname,
*hash< auto >  opts 
)

returns an SQL string that can be used to drop an existing constraint on a table, if the table is not already cached or the constraint does not exist, then NOTHING is returned

Example:
*string sql = tables.getDropConstraintIfExistsSql("table", "pk_table");

If the sql_callback_executed option key is True and if the constraint to be dropped is a foreign constraint, then if any unique constraint is linked to this foreign constraint, the link is removed (see SQL CallBack Executed Flag for more information).

Parameters
tnamethe name of the table
cnamethe name of the constraint to drop if it exists
optsoptional callback options; see AbstractDatabase::CallbackOptions for more info
Returns
an SQL string that can be used to drop an existing constraint on a table, if the table is not already cached or the constraint does not exist, then NOTHING is returned

◆ getDropList()

list<auto> SqlUtil::Tables::getDropList ( )

returns a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies

Example:
list l = tables.getDropList();
map $1.drop(), l;
Returns
a list of cached table names in the order that can be used to drop the tables, taking into account foreign constraint dependencies

◆ getRenameTableIfExistsSql()

*string SqlUtil::Tables::getRenameTableIfExistsSql ( string  old_name,
string  new_name,
*hash< auto >  opts 
)

returns an SQL string that can be used to rename the given table if it exists and the target does not exist, otherwise returns NOTHING

Example:
*string sql = tables.getRenameTableIfExistsSql(old_name, new_name);

If the sql_callback_executed option key is True, this method also takes care of renaming internal foreign constraint references and source constraint references from unique keys for the renamed table (see SQL CallBack Executed Flag for more information).

Parameters
old_namethe current name of the table
new_namethe new name of the table
optsoptional callback options; see AbstractDatabase::CallbackOptions for more info
Returns
an SQL string that can be used to rename the given table if it exists and the target does not exist, otherwise returns NOTHING

◆ memberGate()

AbstractTable SqlUtil::Tables::memberGate ( string  k)

returns the AbstractTable object corresponding to the key given or throws a KEY-ERROR exception

Example:
AbstractTable t = tables.table_name;
Parameters
kthe name of the key to access
Returns
the value of the given key in the contained hash if it exists
Exceptions
KEY-ERRORthe given key does not exist in the contained hash
Note
this method is called automatically when an unknown or inaccessible member name is accessed from outside the class
See also
memberGate() Method

◆ tableRenamed()

bool SqlUtil::Tables::tableRenamed ( string  old_name,
string  new_name,
string  old_sql_name 
)

updates table names and internal references for renamed tables

Example:
tables.tableRenamed(old, newv);
Parameters
old_namethe current name of the table
new_namethe new name of the table
old_sql_namethe old full SQL name of the table (ie the value returned by SqlUtil::AbstractTable::getSqlName())
Returns
True if the table was renamed internally, False if not