Qore SqlUtil Module Reference
1.1
|
represents a database; this class embeds an AbstractDatabase object that is created automatically in the constructor based on the database driver for the AbstractDatasource object providing the database connection More...
Public Member Functions | |
constructor (AbstractDatasource ds, *hash opts) | |
creates the Database object More... | |
constructor (string ds, *hash opts) | |
creates the AbstractDatabase object More... | |
constructor (hash ds, *hash opts) | |
creates the AbstractDatabase object More... | |
bool | dropFunctionIfExists (string name, *hash opt) |
drops the given function if it exists; returns True if the function was dropped, False if not More... | |
bool | dropProcedureIfExists (string name, *hash opt) |
drops the given procedure if it exists; returns True if the procedure was dropped, False if not More... | |
bool | dropSequenceIfExists (string name, *hash opt) |
drops the given sequence if it exists; returns True if the sequence was dropped, False if not More... | |
bool | dropTableIfExists (string name, *hash opt) |
drops the given table if it exists; returns True if the table was dropped, False if not More... | |
Qore::ListIterator | functionIterator () |
returns an iterator listing the string function names in the database | |
list | getAlignFunctionSql (AbstractFunction f, *hash opt) |
returns a list of SQL strings that can be used to update a function in the database to the function definition passed as an argument More... | |
list | getAlignProcedureSql (AbstractFunction f, *hash opt) |
returns a list of SQL strings that can be used to update a stored procedure in the database to the stored procedure definition passed as an argument More... | |
list | getAlignSql (hash schema_hash, *hash opt, *Tables table_cache) |
accepts a hash argument describing a database schema and returns a list of SQL strings that can be used to align the structure and configuration of the current schema with that of the argument; if the objects described are identical then an empty list is returned More... | |
Qore::SQL::AbstractDatasource | getDatasource () |
gets the underlying AbstractDatasource | |
list | getDropSchemaSql (hash schema_hash, *hash opt) |
accepts a hash argument describing a database schema and returns a list of SQL strings that can be used to drop any existing objects described in the schema; if none of the described objects exist, then an empty list is returned More... | |
*AbstractFunction | getFunction (string name) |
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be found More... | |
int | getNextSequenceValue (string name) |
returns the next value in the given sequence More... | |
*AbstractFunction | getProcedure (string name) |
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored procedur cannot be found More... | |
*AbstractSequence | getSequence (string name) |
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be found More... | |
string | getSqlFromList (list l) |
returns an SQL string corresponding to the list of commands in the argument More... | |
*AbstractTable | getTable (string name) |
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found More... | |
*AbstractView | getView (string name) |
returns an AbstractView argument for the given view name or NOTHING if the view More... | |
list | listFunctions () |
returns a list of string function names in the database | |
list | listProcedures () |
returns a list of string procedure names in the database | |
list | listSequences () |
returns a list of string sequence names in the database | |
list | listTables () |
returns a list of string table names in the database | |
list | listViews () |
returns a list of string view names in the database | |
AbstractFunction | makeFunction (string name, string src, *hash opt) |
creates a database-specific AbstractFunction object corresponding to the arguments More... | |
AbstractFunction | makeProcedure (string name, string src, *hash opt) |
creates a database-specific AbstractFunction object for a stored procedure corresponding to the arguments More... | |
AbstractSequence | makeSequence (string name, number start=1, number increment=1, *softnumber end, *hash opts) |
creates a database-specific AbstractSequence object corresponding to the arguments More... | |
AbstractTable | makeTable (string name, hash desc, *hash opts) |
creates a database-specific AbstractTable object corresponding to the arguments More... | |
any | methodGate (string meth) |
executes a method on the contained AbstractDatabase object | |
Qore::ListIterator | procedureIterator () |
returns an iterator listing the string procedure names in the database | |
Qore::ListIterator | sequenceIterator () |
returns an iterator listing the string sequence names in the database | |
bool | supportsSequences () |
returns True if the database supports sequences | |
Qore::ListIterator | tableIterator () |
returns an iterator listing the string table names in the database | |
any | tryExec (string sql) |
executes some SQL with optional arguments so that if an error occurs the current transaction state is not lost More... | |
any | tryExecArgs (string sql, *softlist args) |
executes some SQL with optional arguments so that if an error occurs the current transaction state is not lost More... | |
any | tryExecRaw (string sql) |
executes some SQL so that if an error occurs the current transaction state is not lost More... | |
Qore::ListIterator | viewIterator () |
returns an iterator listing the string view names in the database | |
Private Attributes | |
AbstractDatabase | db |
the embedded AbstractDatabase object that actually provides the functionality for this class | |
represents a database; this class embeds an AbstractDatabase object that is created automatically in the constructor based on the database driver for the AbstractDatasource object providing the database connection
Driver-specific modules that provide the AbstractDatabase implementation embedded in this class are loaded on demand based on the driver's name. The driver-specific module's name is generated based on the db-driver's name with the first letter capitalized then with "SqlUtil"
appended.
For example:
"oracle"
: OracleSqlUtil"pgsql"
: PgsqlSqlUtil"mysql"
: MysqlSqlUtiletc.
SqlUtil::Database::constructor | ( | AbstractDatasource | ds, |
*hash | opts | ||
) |
creates the Database object
ds | the AbstractDatasource object used to provide the DB connection |
opts | a hash of options for the function creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options |
DATABASE-DRIVER-ERROR | no database-specific module can be loaded |
OPTION-ERROR | invalid or unsupported option passed |
creates the AbstractDatabase object
ds | a datasource description string in the format that can be parsed by parse_datasource() |
opts | a hash of options for the function creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
creates the AbstractDatabase object
ds | a hash giving parameters for the new datasource with the following possible keys (the "type" key is mandatory, also usable with the output of the parse_datasource() function):
|
opts | a hash of options for the table creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
drops the given function if it exists; returns True if the function was dropped, False if not
name | the name of the function |
opt | optional callback options; see AbstractDatabase::CallbackOptions for more info |
OPTION-ERROR | invalid or unknown callback option |
drops the given procedure if it exists; returns True if the procedure was dropped, False if not
name | the name of the procedure |
opt | optional callback options; see AbstractDatabase::CallbackOptions for more info |
OPTION-ERROR | invalid or unknown callback option |
drops the given sequence if it exists; returns True if the sequence was dropped, False if not
name | the name of the sequence |
opt | optional callback options; see AbstractDatabase::CallbackOptions for more info |
OPTION-ERROR | invalid or unknown callback option |
drops the given table if it exists; returns True if the table was dropped, False if not
name | the name of the table |
opt | optional callback options; see AbstractDatabase::CallbackOptions for more info |
OPTION-ERROR | invalid or unknown callback option |
list SqlUtil::Database::getAlignFunctionSql | ( | AbstractFunction | f, |
*hash | opt | ||
) |
returns a list of SQL strings that can be used to update a function in the database to the function definition passed as an argument
f | the template or target version of the function to compare to the database version |
opt | an optional hash of options for the generation of the SQL strings; see AbstractDatabase::CreationOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
list SqlUtil::Database::getAlignProcedureSql | ( | AbstractFunction | f, |
*hash | opt | ||
) |
returns a list of SQL strings that can be used to update a stored procedure in the database to the stored procedure definition passed as an argument
f | the template or target version of the stored procedure to compare to the database version |
opt | an optional hash of options for the generation of the SQL strings; see AbstractDatabase::CreationOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
accepts a hash argument describing a database schema and returns a list of SQL strings that can be used to align the structure and configuration of the current schema with that of the argument; if the objects described are identical then an empty list is returned
schema_hash | the schema template hash that decribes the target state of the schema |
opt | a hash of options for the SQL creation strings; see AbstractDatabase::AlignSchemaOptions for common options; each driver can support additional driver-specific options |
table_cache | an optional object of class Tables to return the cache of AbstractTable objects keyed by table name for the schema template (ie target table definitions) |
SCHEMA-DESCRIPTION-ERROR | the schema description hash has an error or a required object does not exist |
OPTION-ERROR | invalid or unsupported option passed |
accepts a hash argument describing a database schema and returns a list of SQL strings that can be used to drop any existing objects described in the schema; if none of the described objects exist, then an empty list is returned
schema_hash | the schema template hash that decribes the state of the schema |
opt | a hash of options for the SQL strings; see AbstractDatabase::DropSchemaOptions for common options; each driver can support additional driver-specific options |
SCHEMA-DESCRIPTION-ERROR | the schema description hash has an error |
OPTION-ERROR | invalid or unsupported option passed |
*AbstractFunction SqlUtil::Database::getFunction | ( | string | name | ) |
returns an AbstractFunction argument for the given function name or NOTHING if the function cannot be found
name | the uniquely-identifying name of the function to retrieve |
returns the next value in the given sequence
name | the name of the sequence |
*AbstractFunction SqlUtil::Database::getProcedure | ( | string | name | ) |
returns an AbstractFunction argument for the given stored procedure name or NOTHING if the stored procedur cannot be found
name | the uniquely-identifying name of the stored procedure to retrieve |
*AbstractSequence SqlUtil::Database::getSequence | ( | string | name | ) |
returns an AbstractSequence argument for the given sequence name or NOTHING if the sequence cannot be found
name | the uniquely-identifying name of the sequence to retrieve |
returns an SQL string corresponding to the list of commands in the argument
l | a list of SQL commands |
*AbstractTable SqlUtil::Database::getTable | ( | string | name | ) |
returns an AbstractTable argument for the given table name or NOTHING if the table cannot be found
name | the uniquely-identifying name of the table to retrieve |
*AbstractView SqlUtil::Database::getView | ( | string | name | ) |
returns an AbstractView argument for the given view name or NOTHING if the view
name | the uniquely-identifying name of the view to retrieve |
AbstractFunction SqlUtil::Database::makeFunction | ( | string | name, |
string | src, | ||
*hash | opt | ||
) |
creates a database-specific AbstractFunction object corresponding to the arguments
name | the name of the function |
src | the database-specific source code of the function (see the database-specific documentation for information about the format of this parameter; generally it's simply the normal source code for the function required by the database) |
opt | an optional hash of options for the creation of the function; see AbstractDatabase::CreationOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
AbstractFunction SqlUtil::Database::makeProcedure | ( | string | name, |
string | src, | ||
*hash | opt | ||
) |
creates a database-specific AbstractFunction object for a stored procedure corresponding to the arguments
name | the name of the stored procedure |
src | the database-specific source code of the stored procedure (see the database-specific documentation for information about the format of this parameter; generally it's simply the normal source code for the stored procedure required by the database) |
opt | an optional hash of options for the creation of the stored procedure; see AbstractDatabase::CreationOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
AbstractSequence SqlUtil::Database::makeSequence | ( | string | name, |
number | start = 1 , |
||
number | increment = 1 , |
||
*softnumber | end, | ||
*hash | opts | ||
) |
creates a database-specific AbstractSequence object corresponding to the arguments
name | the name of the sequence |
start | the starting value of the sequence |
increment | the increment value of the sequence |
end | the endinf value of the sequence, omit for no ending value |
opts | an optional hash of options for the creation of the sequence; see AbstractDatabase::CreationOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
SEQUENCE-ERROR | end not compatible with start and increment, increment is zero |
AbstractTable SqlUtil::Database::makeTable | ( | string | name, |
hash | desc, | ||
*hash | opts | ||
) |
creates a database-specific AbstractTable object corresponding to the arguments
name | the name of the table |
desc | a table description hash describing the table |
opts | an optional hash of options for the table creation string; see SqlUtil::AbstractTable::TableOptions for common options; each driver can support additional driver-specific options |
OPTION-ERROR | invalid or unsupported option passed |
any SqlUtil::Database::tryExec | ( | string | sql | ) |
executes some SQL with optional arguments so that if an error occurs the current transaction state is not lost
Include any arguments in the parameter list after the sql argument
sql | the SQL to execute |
any SqlUtil::Database::tryExecArgs | ( | string | sql, |
*softlist | args | ||
) |
executes some SQL with optional arguments so that if an error occurs the current transaction state is not lost
sql | the SQL to execute |
args | the bind / placeholder or other arguments corresponding to the SQL string |
any SqlUtil::Database::tryExecRaw | ( | string | sql | ) |
executes some SQL so that if an error occurs the current transaction state is not lost
Include any arguments in the parameter list after the sql argument
sql | the SQL to execute |