Qore SqlUtil Module Reference  1.5
SqlUtil::Database Class Reference

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 Methods

 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...
 
SqlUtil::AbstractDatabase getDatabase ()
 gets the underlying AbstractDatabase
 
any methodGate (string meth)
 executes a method on the contained AbstractDatabase object
 

Private Attributes

AbstractDatabase db
 the embedded AbstractDatabase object that actually provides the functionality for this class
 

Detailed Description

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:

etc.

Member Function Documentation

◆ constructor() [1/3]

SqlUtil::Database::constructor ( AbstractDatasource  ds,
*hash  opts 
)

creates the Database object

Example:
Database db(ds);
Parameters
dsthe AbstractDatasource object used to provide the DB connection
optsa hash of options for the function creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options
Exceptions
DATABASE-DRIVER-ERRORno database-specific module can be loaded
OPTION-ERRORinvalid or unsupported option passed

◆ constructor() [2/3]

SqlUtil::Database::constructor ( string  ds,
*hash  opts 
)

creates the AbstractDatabase object

Example:
AbstractDatabase db("pgsql:user/pass@db%host");
Parameters
dsa datasource description string in the format that can be parsed by parse_datasource()
optsa hash of options for the function creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options
Exceptions
OPTION-ERRORinvalid or unsupported option passed

◆ constructor() [3/3]

SqlUtil::Database::constructor ( hash  ds,
*hash  opts 
)

creates the AbstractDatabase object

Example:
AbstractDatabase db("pgsql:user/pass@db%host");
Parameters
dsa 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):
  • type: (*string) The name of the database driver to use; this key is mandatory; if not present, an exception will be raised. See SQL Constants for builtin constants for DBI drivers shipped with Qore, or see the DBI driver documentation to use an add-on driver (this string should be the name of the driver to be loaded)
  • user: (*string) The user name for the new connection
  • pass: (*string) The password for the new connection
  • db: (*string) The database name for the new connection
  • charset: (*string) The database-specific name of the character encoding to use for the new connection. Also see Qore::SQL::Datasource::setDBCharset() for a method that allows this parameter to be set after the constructor. If no value is passed for this parameter, then the database character encoding corresponding to the default character encoding for the Qore process will be used instead.
  • host: (*string) The host name for the new connection
  • port: (softint) The port number for the new connection
  • options: (*hash) Any options for the new connection
optsa hash of options for the table creation string; see AbstractDatabase::DatabaseOptions for common options; each driver can support additional driver-specific options
Exceptions
OPTION-ERRORinvalid or unsupported option passed