MQdb::Database3pm
Generalized handle on an dbi database handle
Overview
Generalized handle on an DBI database handle. Used to provide an instance which holds connection information and allows a higher level get_connection/ disconnect logic that persists above the specific DBI connections. Also provides a real object for use with the rest of the toolkit.
Summary
MQdb::Database provides the foundation of the MappedQuery system. Databases are primarily specified with a URL format. The URL format includes specification of a driver so this single method can select among the supported DBD drivers. Currently the system supports MYSQL, Oracle, and SQLite. The URL also allows the system to provide the foundation for doing federation of persisted objects. Each DBObject contains a pointer to the Database instance where it is stored. With the database URL and internal database ID, each object is defined in a global space.
Attributes of MQdb::Database
driver : mysql, oracle, sqlite (default mysql)
user : username if the database requires
password : password if the database requires
host : hostname of the database server machine
port : IP port of the database if required
(mysql default is 3306)
dbname : database/schema name on the database server
for sqlite, this is the database file
Example URLS
mysql://<user>:<pass>@<host>:<port>/<database_name>
mysql://<host>:<port>/<database_name>
mysql://<user>@<host>:<port>/<database_name>
mysql://<host>/<database_name>
oracle://<user>:<pass>@/<database_name>
oracle://<user>:<pass>@<host>:<port>/<database_name>
sqlite:///<database_file>
Contact
Jessica Severin <[email protected]>
Appendix
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
new
Description: instance creation methodParameter : a hash reference of options same as attribute methodsReturntype : instance of this Class (subclass)Exceptions : none
new
Description: instance creation methodReturntype : instance of this Class (subclass)Exceptions : none
init
Description: initialization method which subclasses can extendReturntype : $selfExceptions : subclass dependent
new_from_url
Description: primary instance creation methodParameter : a string in URL formatReturntype : instance of MQdb::DatabaseExamples : my $db = MQdb::Database->new_from_url("mysql://<user>:<pass>@<host>:<port>/<database_name>");e.g. mysql://<host>:<port>/<database_name>e.g. mysql://<user>@<host>:<port>/<database_name>e.g. mysql://<host>/<database_name>e.g. sqlite:///<database_file>my $class = shift;Exceptions : none
copy
Description: makes a copy of the database configuration.New instance will have its own database connectionReturntype : instance of MQdb::Database
dbc
Description: connects to database and returns a DBI connectionReturntype : DBI database handleExceptions : none
disconnect
Description: disconnects handle from database, but retains object andall information so that it can be reconnected againat a later time.Returntype : noneExceptions : none
full_url
Description: returns the URL of this database with user and passwordReturntype : stringExceptions : none
url
Description: returns URL of this database but without user:passwordused for global referencing and federation systemsReturntype : stringExceptions : none
xml
Description: returns XML of this database but without user:passwordused for global referencing and federation systemsReturntype : stringExceptions : none
execute_sql
Description : executes SQL statement with external parameters and placeholdersExample : $db->execute_sql("insert into table1(id, value) values(?,?)", $id, $value);Parameter[1] : sql statement stringParameter[2..] : optional parameters for the SQL statementReturntype : noneExceptions : none
do_sql
Description : executes SQL statement with "do" and no external parametersExample : $db->do_sql("insert into table1(id, value) values(null,'hello world');");Parameter : sql statement string with no external parametersReturntype : noneExceptions : none
fetch_col_value
Arg (1) : $sql (string of SQL statement with place holders)Arg (2...) : optional parameters to map to the placehodlers within the SQLExample : $value = $self->fetch_col_value($db, "select some_column from my_table where id=?", $id);Description: General purpose function to allow fetching of a single column from a single row.Returntype : scalar valueExceptions : noneCaller : within subclasses to easy development
Releases
8 releases since Debian 6.0 (Squeeze); the text changed 2 times.