![]() |
![]() |
Supporting the evolution of a new free world. |
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DBE - Database (Express) Engine for PerlThe DBE module permits a secure and fast way to access database systems. DBE was developed for high performance and low usage of resources. The chart below illustrates the functionality of DBE.
DOCUMENTATION
NAME
DBE - Database (Express) Engine for Perl
SYNOPSIS
use DBE; $con = DBE->connect( %arg ); $con = DBE->connect( $dsn ); $res = $con->query( $sql ); $res = $con->query( $sql, @bind_values ); $rv = $con->do( $sql ); $rv = $con->do( $sql, @bind_values ); $con->prepare( $sql ); $res = $con->execute( ... ); $stmt = $con->prepare( $sql ); $stmt->bind_param( $p_num, $value ); $stmt->bind_param( $p_num, $value, $type ); $res = $stmt->execute(); $res = $stmt->execute( @bind_values ); @row = $res->fetch_row(); $res->fetch_row( \@row ); $res->fetch_row( \%row ); @row = $res->fetchrow_array(); $row = $res->fetchrow_arrayref(); $row = $res->fetchrow_hashref(); $array = $res->fetchall_arrayref(); $hash = $res->fetchall_hashref( $key ); @name = $res->fetch_names(); $num_rows = $res->num_rows(); $num_fields = $res->num_fields(); $rv = $con->auto_commit( $mode ); $rv = $con->begin_work(); $rv = $con->commit(); $rv = $con->rollback(); $str = $con->error(); $errno = $con->errno(); $rv = $con->set_charset( $charset ); $charset = $con->get_charset(); $quoted = $db->quote( $arg ); $quoted = $db->quote_id( ... ); DESCRIPTION
DBE provides an interface for high performance database communication.
The goal for this module is a fast and efficient database interface with the power of DBI.
The documentation uses different variable names for different classes. These variables are defined as follows. $con defines a connection class, $res defines a result set class, $stmt defines a statement class and $lob defines a class of a large object.
Uniform SQL
Functions with SQL statements offer an extended notation of catalog, schema and table names. If a SQL statement starts with a percent (%) sign identities can be written uniformly. The identities stay in square brackets []. Within the notation points (.) are evaluated as separators for schema, table and field names. The catalog is identified by an AT (@) character. It must be the last part in the identity. The route (#) character is converted into a point.
Examples
MySQL Driver
# uniform $con->query("% SELECT * FROM [table@db] WHERE [field] = '1'"); # native $con->query("SELECT * FROM `db`.`table` WHERE `field` = '1'"); PostgreSQL Driver
# uniform $con->query("% SELECT * FROM [schema.table] AS [t1] WHERE [t1.id] = 1"); # native $con->query('SELECT * FROM "schema"."table" AS "t1" WHERE "t1"."id" = 1'); Text Driver
# uniform $con->query('% SELECT * FROM [table#csv] WHERE [table.field] = 1'); # native $con->query('SELECT * FROM "table.csv" WHERE "table"."field" = 1'); Parameter Names in Placeholders for All
Uniform SQL enables you to use parameter names in placeholders. A parameter name begins with a colon (:) character and may contain one or more of the following characters: 'a'-'z', 'A'-'Z', '0'-'9', '_'. The names are converted into question mark (?) characters before the statement is sent to the driver.
Examples
# prepare, execute $stmt = $con->prepare( '% SELECT * FROM [table] WHERE [id] > :id' ); $stmt->bind_param( ':id', 1000, 'i' ); $res = $stmt->execute(); # or as query $res = $con->query( '% SELECT * FROM [table] WHERE [id] > :id', { 'id' => 1000 } ); Functions by Category
Main Functions
Accessing Result Data
Accessing Fields in a Result Set
Transactions
Combined Selects
Information and Catalog Functions
Misc Functions
Error Handling
Large Objects
Examples
Simple Query
use DBE; $con = DBE->connect( 'provider' => 'MySQL', 'socket' => '/tmp/mysql.sock', 'user' => 'root', 'auth' => '', 'db' => 'test', 'charset' => 'utf8', ); $res = $con->query( "SELECT * FROM table WHERE field = 'foo'" ); print join( '|', $res->fetch_names() ), "\n"; while( @row = $res->fetch_row() ) { print join( '|', @row ), "\n"; } Query with statements
use DBE; $dsn = "Provider=MySQL;Host=localhost;User=root;Password=;Database=test"; $con = DBE->connect( $dsn ); $con->set_charset( 'utf8' ); $stmt = $con->prepare( 'SELECT * FROM table WHERE field = ?' ); # bind "foo" to parameter 1 and execute $res = $stmt->execute( 'foo' ); print join( '|', $res->fetch_names() ), "\n"; while( $row = $res->fetchrow_arrayref() ) { print join( '|', @$row ), "\n"; } METHODS
Connection Control Methods
The connection string that includes the provider name, and other parameters needed to establish the initial connection.
The basic format of a connection string includes a series of keyword/value pairs separated by semicolons. The equal sign (=) connects each keyword and its value. To include values that contain a semicolon, single-quote character, or double-quote character, the value must be enclosed in double quotation marks. If the value contains both a semicolon and a double-quote character, the value can be enclosed in single quotation marks. The single quotation mark is also useful if the value starts with a double-quote character. Conversely, the double quotation mark can be used if the value starts with a single quotation mark. If the value contains both single-quote and double-quote characters, the quotation-mark character used to enclose the value must be doubled every time it occurs within the value. Parameters are listed below.
All parameters are case-insensitive. Additional parameters are documented in the drivers manual.
Return Values
Returns a connection object ($con) on success, or undef on failure.
Examples
# parameters as hash $con = DBE->connect( 'provider' => 'Text', 'dbq' => '/path/to/csv-files/', ); # parameters as dsn $dsn = 'Provider=Text;DBQ=.;Format="Delimited(;)";QuoteBy=""""'; $con = DBE->connect( $dsn );
Closes the connection explicitly and frees its resources. disconnect() is a synonym for close().
Sets the default character set to be used when sending data from and to the database server.
Parameters
The character set to be set.
Return Values
Returns a TRUE value on success or undef on failure.
Gets the default character set.
Return Values
Returns the default character set or undef on error.
Returns the last error code for the most recent function call that can succeed or fail.
Return Values
An error code value for the last call, if it failed. Zero means no error occurred.
Examples
# global error $con = DBE->connect( ... ) or die 'Connect failed (' . DBE->errno . ') ' . DBE->error; # connection error $con->query( ... ) or die 'Query failed (' . $con->errno . ') ' . $con->error;
Returns the last error message for the most recent function call that can succeed or fail.
Return Values
A string that describes the error. An empty string if no error occurred.
Examples
# global error $con = DBE->connect( ... ) or die 'Connect failed ' . DBE->error; # connection error $con->query( ... ) or die 'Query failed ' . $con->error;
Sets or removes a userdefined error handler.
Parameters
Function name or code reference.
Argument can be used to pass a class reference.
Return Values
Resturns true on success, or undef on error.
Parameters passed to error function
Examples
Error handler
$con = DBE->connect ('Provider=Text'); # set error handler to a function $con->set_error_handler (\&error_handler); # raise a syntax error $con->do ("SELECT * FROM"); sub error_handler { # does allmost the same like internal croak my ($code, $msg, $provider, $action, $obj_id, $obj) = @_; my ($pkg, $file, $line) = caller (); print STDERR "[$provider] $action: $msg at $file line $line\n"; exit; } Error handler as class function
$con = DBE->connect ('Provider=Text'); $obj = MY->new (); # set error handler to an object $con->set_error_handler ('error_handler', $obj); # or # $con->set_error_handler ('MY::error_handler', $obj); # or # $con->set_error_handler (\&MY::error_handler, $obj); # raise a syntax error $con->do ("SELECT * FROM"); 1; package MY; require Carp; sub new { bless {}, shift; } sub error_handler { # does allmost the same like internal croak my ($this, $code, $msg, $provider, $action, $obj_id, $obj) = @_; &Carp::croak ("[$provider] $action: $msg"); }
Enables tracing support with a specified level. The levels are defined as follows:
0 - DBE_TRACE_NONE - disable tracing
1 - DBE_TRACE_SQL - trace sql statements only
2 - DBE_TRACE_SQLFULL - trace sql statements inlcuding bind
and execute calls
3 - DBE_TRACE_ALL - trace all messages
Setting trace options to a connection object will overwrite global trace settings.
The $iohandle parameter can contain an io handle to write the messages there. The default handle is STDERR.
Examples
# global tracing of all messages DBE->trace( 3 ); # trace into a file open( $fh, "> trace.log" ) or die "can't open file: $!"; DBE->trace( 3, $fh ); # just trace the sql statements within a connection object $con->trace( 1 ); # disable global tracing DBE->trace( 0 );
Command Execution Methods
Return Values
For selective queries query() returns a result class ($res) on success, or FALSE on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc, query() returns TRUE on success or FALSE on error.
Prepares the SQL query pointed to by the null-terminated string query, and returns a statement handle to be used for further operations on the statement. The query must consist of a single SQL statement.
Parameters
The query, as a string.
This parameter can include one or more parameter markers in the SQL statement by embedding question mark (?) characters at the appropriate positions.
Return Values
Returns a statement class ($stmt) or FALSE on failure.
Examples
With statement
$stmt = $con->prepare( 'UPDATE table WHERE field = ?' ); # bind 'foo' to 'field' as type 'string' $stmt->bind_param( 1, 'foo', 's' ); # execute $res = $stmt->execute(); Without statement
$con->prepare( 'UPDATE table WHERE field = ?' ); # bind 'foo' to 'field' as type 'string' $con->bind_param( 1, 'foo', 's' ); # execute $res = $con->execute(); See Also
execute(), bind_param()
Returns the number of parameters in the statement.
Binds a value to a prepared statement as parameter
Parameters
The number of parameter starting at 1.
Any scalar value.
A string that contains one character which specify the type for the corresponding bind value:
Character Description --------------------- i corresponding value has type integer d corresponding value has type double s corresponding value has type string b corresponding value has type binary
Return Values
Returns a true value on success, or undef on error.
Example
$stmt = $con->prepare( 'UPDATE table WHERE field1 = ? AND field2 = ?' ); # bind '100' to 'field1' as type 'integer' $stmt->bind_param( 1, 100, 'i' ); # bind 'foo' to 'field2' $stmt->bind_param( 2, 'foo' ); See Also
prepare(), execute()
Values bound in this way are usually treated as "string" types unless the driver can determine the correct type.
Return Values
Returns a true value on success, or undef on error.
Executes a prepared statement.
Parameters
An array of values to bind. Values bound in this way are usually treated as "string" types unless the driver can determine the correct type.
Return Values
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, query returns a result class ($res) on success, or undef on error.
For other type of SQL statements, UPDATE, DELETE, DROP, etc, query returns a true value on success, or undef on error.
Example
$stmt = $con->prepare( 'UPDATE table WHERE field = ?' ); # bind 'foo' to 'field' and execute $res = $stmt->execute( 'foo' ); Note
Some drivers (like MySQL) do not support different result sets within the same statement. In this case each result set of the statement share the same data.
See Also
prepare(), bind_param()
Closes a statement explicitly.
Retrieving Query Result Information
Return Values
The value of an AUTO_INCREMENT (IDENDITY,SERIAL) field that was updated by the previous query. Returns NULL if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.
Accessing Result Data
Note
This method is designed for testing purposes and should not be used to export data.
Fetches the next row into bound variables. See more at bind_column().
Get a result row as an array or a hash. fetchrow_array() is a synonym for fetch_row().
Paramters
A reference to an array which will be filled with the data of the next row.
A reference to a hash will be filled with the data of the next row, where each key in the hash represents the name of one of the result set columns.
Return Values
Without parameters it returns an array of values that is filled with the data of the next row. With parameters it returns TRUE. FALSE is returned if there are no more rows in result set.
Examples
$res = $con->query( "SELECT prename, name FROM person" ); $res->fetch_row( \%row ); print "First person is $row{'prename'} $row{'name'}\n"; $res->fetch_row( \@row ); print "Second person is $row[0] $row[1]\n"; @row = $res->fetch_row; print "Third person is $row[0] $row[1]\n";
Fetch all rows from the result set and return a column of it.
Paramters
A reference to an array to store the data into.
A column number between 0 and num_fields() - 1. Defaults to 0.
A reference to a hash to store the data into. Each key in the hash contains the data of column $num_key and each value contains the data of column $num_val.
Column number to fetch as key. Defaults to 0.
Column number to fetch as value. Defaults to 1.
Return Values
Without \@col and \%col paramters it returns an array of values that corresponds to the specified column of each row in the result set, or TRUE on success, or FALSE if no data is available.
Examples
Fetch columns as array
$res = $con->query( "SELECT name FROM color" ); @colors = $res->fetch_col(); or $res->fetch_col( \@colors ); print "Available colors: ", join( ', ', @colors ), "\n"; Fetch columns as hash
$res = $con->query( "SELECT id, name FROM color" ); $res->fetch_col( \%color ); $res = $con->query( "SELECT color_id, description FROM articles" ); $res->bind( $color_id, $desc ); while( $res->fetch ) { print "Article $desc has color ", $color{$color_id}, "\n"; }
Fetch a result row as an enumerated array.
Return Values
Returns a reference to an array of values that corresponds to the fetched row, or FALSE if there are no more rows in result set.
Fetch a result row as an associative array (hash).
Paramters
Name conversation. A value of "lc" convert names to lowercase and a value of "uc" convert names to uppercase.
Return Values
Returns a reference to a hash of values representing the fetched row in the result set, where each key in the hash represents the name of one of the result set columns or FALSE if there are no more rows in the resultset.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other columns of the same name, you either need to access the result with numeric indices by using fetch_row(), fetchrow_arrayref() or add alias names.
Fetch all data from the result as a reference to an array, which contains a reference to each row.
Paramters
Fetch all fields of every row as a hash ref.
Return Values
Returns a reference to an array of references to all fetched rows, or FALSE if no data is available.
Examples
$res = $con->query( "SELECT name, age FROM person" ); $a_per = $res->fetchall_arrayref(); foreach $row( @$a_per ) { print $row->[0], " is ", $row->[1], " years old\n"; } # fetch as hashref $a_per = $res->fetchall_arrayref( {} ); foreach $row( @$a_per ) { print $row->{'name'}, " is ", $row->{'age'}, " years old\n"; }
Fetch all data from the result as a reference to hash containing a key for each distinct value of the $key(n) column that was fetched.
Parameters
Column name to use their values as key in the hash.
Return Values
Returns a reference to a hash containing a key for each distinct value of the $key(n) column that was fetched. For each key the corresponding value is a reference to a hash containing all the selected columns and their values.
Examples
$res = $con->query( 'SELECT ID, Name FROM Table' ); $data = $res->fetchall_hashref( 'ID' ); # print name of ID = 2 print $data->{2}->{'Name'}; $res = $con->query( 'SELECT ID1, ID2, Name FROM Table' ); $data = $res->fetchall_hashref( 'ID1', 'ID2' ); # print name of ID1 = 2 and ID2 = 10 print $data->{2}->{10}->{'Name'};
Binds a variable to a column in the result set.
Parameters
Number of column starting at 1.
A variable to bind. If it is a reference to a variable it will be dereferenced once.
Return Values
Returns a true value on succes, or undef on error.
Examples
my ($article_id, $article_name); $res = $con->query( "SELECT ID, Name FROM Article" ); $res->bind_column( 1, $article_id ); $res->bind_column( 2, $article_name ); while( $res->fetch ) { print "article $article_id: $article_name\n"; }
Binds one or more variables to the columns in the result set. It is a shorthand version of bind_column().
Examples
my ($prename, $name, $age); $res = $con->query( "SELECT Prename, Name, Age FROM Person" ); $res->bind( $prename, $name, $age ); while( $res->fetch ) { print "$name, $prename is $age years old\n"; } Bind a hash
my %row; $res = $con->query( "SELECT Prename, Name, Age FROM Person" ); $res->bind( @row{$res->names('lc')} ); while( $res->fetch ) { print "$row{'name'}, $row{'prename'} is $row{'age'} years old\n"; }
Get the number of rows in a result.
Return Values
Returns number of rows in the result set.
Get the actual position of row cursor in a result (Starting at 0).
Return Values
Returns the actual position of row cursor in a result.
Set the actual position of row cursor in a result (Starting at 0).
Paramters
Absolute row position. Valid between 0 and num_rows() - 1.
Return Values
Returns the previous position of row cursor in a result.
Accessing Fields in a Result Set
Return Values
Returns an array of field names or FALSE if no field information is available.
Gets the number of fields (columns) in a result.
Return Values
Returns number of fields in the result set.
Returns the next field in the result set.
Return Values
Returns a hash which contains field definition information or FALSE if no field information is available.
Gets the actual position of field cursor in a result (Starting at 0).
Return Values
Returns the actual position of field cursor in the result.
Sets the actual position of field cursor in the result (Starting at 0).
Paramters
Absolute field position. Valid between 0 and num_fields() - 1.
Return Values
Returns the previous position of field cursor in the result.
Transaction Methods
Return Values
Returns a true value on success, or undef on error.
Turns off auto-commit mode for the database connection until transaction is finished.
Return Values
Returns a true value on success, or undef on error.
Commits the current transaction for the database connection.
Return Values
Returns a true value on success, or undef on error.
Rollbacks the current transaction for the database.
Return Values
Returns a true value on success, or undef on error.
Simple Data Fetching
Information and Catalog Functions
If SQL_ALL_TYPES is specified, information about all supported data types would be returned in ascending order by TYPE_NAME. All unsupported data types would be absent from the result set.
Return Values
Returns a result set where each table is represented by one row. The result set contains the columns listed below in the order given.
Returns a result set that can be used to fetch information about tables and views that exist in the database.
Parameters
String that may contain a pattern-value to qualify the result set. Catalog is the first part of a three-part table name.
String that may contain a pattern-value to qualify the result set by schema name.
String that may contain a pattern-value to qualify the result set by table name.
String that may contain a value list to qualify the result set by table type. The value is a list of values separated by commas for the types of interest. Valid table type identifiers may include: ALL, BASE TABLE, TABLE, VIEW, SYSTEM TABLE. If $table argument is empty, then this is equivalent to specifying all of the possibilities for the table type identifier.
If SYSTEM TABLE is specified, then both system tables and system views (if there are any) are returned.
Note
Since "_" is a pattern matching value, you may need to escape pattern-values by escape_pattern() first.
Return Values
Returns a result set where each table is represented by one row. The result set contains the columns listed below in the order given.
Get a list of columns in the specified tables. The information is returned in a result set, which can be retrieved using the same functions that are used to fetch a result set generated by a SELECT statement.
Parameters
String that may contain a pattern-value to qualify the result set. Catalog is the first part of a three-part table name.
String that may contain a pattern-value to qualify the result set by schema name.
String that may contain a pattern-value to qualify the result set by table name.
String that may contain a pattern-value to qualify the result set by column name.
Note
Since "_" is a pattern matching value, you may need to escape pattern-values by escape_pattern() first.
Return Values
Returns a result set class, with columns listed below in the order given.
Returns a list of column names that comprise the primary key for a table. The information is returned in a result set, which can be retrieved using the same functions that are used to process a result set that is generated by a query.
Parameters
Catalog qualifier of a 3 part table name.
Schema qualifier of table name.
Table name.
Return Values
Returns the primary key columns from a single table, Search patterns cannot be used to specify the schema qualifier or the table name.
The result set contains the columns that are listed below, ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION.
Returns information about foreign keys for the specified table. The information is returned in a result set which can be processed using the same functions that are used to retrieve a result that is generated by a query.
Parameters
Catalog qualifier of the primary key table.
Schema qualifier of the primary key table.
Name of the table name containing the primary key.
Catalog qualifier of the table containing the foreign key.
Schema qualifier of the table containing the foreign key.
Name of the table containing the foreign key.
Usage
If $pk_table contains a table name, and $fk_table is empty, foreign_keys() returns a result set that contains the primary key of the specified table and all of the foreign keys (in other tables) that refer to it.
If $fk_table contains a table name, and $pk_table is empty, foreign_keys() returns a result set that contains all of the foreign keys in the specified table and the primary keys (in other tables) to which they refer.
If both $pk_table and $fk_table contain table names, foreign_keys() returns the foreign keys in the table specified in $fk_table that refer to the primary key of the table specified in $pk_table. This should be one key at the most.
Return Values
Returns a reference to a result set, or FALSE on failure. The columns of the result set are listed below in the order given.
Retrieve a list of statistics about a single table and the indexes associated with the table. The information is returned in a result set, which can be retrieved using the same functions that are used to fetch a result set generated by a SELECT statement.
Parameters
Catalog is the first part of a three-part table name. It cannot contain a string search pattern.
Schema qualifier of the specified table. It cannot contain a string search pattern.
Table name. This argument cannot be a empty. It cannot contain a string search pattern.
If TRUE, only unique indexes are returned. If FALSE, all indexes are returned.
Return Values
Returns a result set class, with columns listed below in the order given.
special_columns retrieves the following information about columns within a specified table:
The information is returned in a result set, which can be retrieved using the same functions that are used to fetch a result set generated by a SELECT statement.
Parameters
Catalog is the first part of a three-part table name. It cannot contain a string search pattern.
Schema qualifier of the specified table. It cannot contain a string search pattern.
Table name. This argument cannot be a empty. It cannot contain a string search pattern.
Minimum required duration for which the unique row identifier is valid. $scope must be one of the following:
The row identifier is guaranteed to be valid only while positioned on that row. A later reselect using the same row identifier values may not return a row if the row was updated or deleted by another transaction.
The row identifier is guaranteed to be valid for the duration of the current transaction.
The row identifier is guaranteed to be valid for the duration of the connection.
Determines whether to return special columns that can have a NULL value. Must be one of the following:
Exclude special columns that can have NULL values. Some drivers cannot support SQL_NO_NULLS, and these drivers will return an empty result set if SQL_NO_NULLS was specified. Applications should be prepared for this case and request SQL_NO_NULLS only if it is absolutely required.
Return special columns even if they can have NULL values.
Return Values
Returns a result set class, with columns listed below in the order given.
Other Functions
Return Values
The quoted value with adding the required type of outer quotation marks.
Example
print $con->quote( "Don't clash with quote chars" ); # output: 'Don''t clash with quote chars'
Quote a value for use as a binary value in an SQL statement,
The quote_bin() method should not be used with placeholders.
Parameters
Value to be quoted as binary value.
Return Values
The quoted value to use as binary value in SQL statements, or undef if the driver does not support binary values directly in SQL statements.
Example
print $con->quote_bin( "DBE" ); # SQLite3: X'444245' # MySQL: 0x444245 # PostgreSQL: '\104\102\105'
Quote an identifier (table name etc.) for use in an SQL statement, by escaping any special characters it contains and adding the required type of outer quotation marks.
Parameters
One or more identifiers to quote.
Return Values
The quoted string with adding the required type of outer quotation marks.
Examples
# MySQL driver: $s = $con->quote_id( 'table' ); # returns: `table` $s = $con->quote_id( 'table', 'field' ); # returns: `table`.`field` $s = $con->quote_id( 'table', '*' ); # returns: `table`.*
Sets or returns the name conversion in result sets for subsequent queries.
Examples
# read the actual state print "current name conversion: ", $con->name_convert() || "none", "\n"; # convert names to uppercase $con->name_convert( "NAME_uc" ); # run a query $res = $con->query( "SELECT ..." ); $res->names; # uppercase # convert names to lowercase $con->name_convert( "lc" ); # run a query $res = $con->query( "SELECT ..." ); $res->fetchrow_hashref; # keys are in lowercase # disable name conversion $con->name_convert( "" );
Adds a limit to SELECT statements. Setting this option affects subsequent calls to query() and prepare().
The driver holds $limit rows in the result set and calls internally
SELECT again to give access to all rows.
Examples
Table "t1" should contain more then one row
# set limit to 1 row $con->row_limit( 1 ); # the driver holds one row in the result set $res = $con->query( "SELECT * FROM t1" ); # num_rows returns the total number of rows available print $res->num_rows, "\n"; # fetch the first row @row = $res->fetch_row; # fetch the second row # the driver now makes a new SELECT call to the dbms @row = $res->fetch_row; # disable row limit for further queries $con->row_limit( 0 ); Pagination Example
$limit = 10; $offset = 0; $con->row_limit( $limit, $offset ); $res->query( "SELECT * FROM t1" ); $first_row = $offset + 1; $last_row = $res->num_rows - $offset; $last_row > $limit and $last_row = $limit; print "print rows $first_row to $last_row\n"; for $row_pos( $first_row .. $last_row ) { $res->fetch_row( \@row ) or last; print "row $row_pos ", join( '|', @row ), "\n"; } Note
row_limit() must be supported by the driver. Known supporting drivers are MySQL, PostgreSQL and SQLite3.
Sets or gets a connection attribute. Attribute names are given as string. Following attributes are available to DBE:
croak, warn, reconnect
A description of these attributes can be found on connect().
Example
$prv = $con->get_attr( 'croak' ); # enable croak on error $con->set_attr( 'croak' => 1 ); eval { # raise an error $con->do( "SELECT" ); }; # restore previous attribute $con->set_attr( 'croak' => $prv ); if( $@ ) { print "SELECT failed: $@\n"; }
Determines if the connection is still working. Returns TRUE on success, or FALSE on failure.
Checks the driver for a function.
Parameters
Name of the function.
Return Values
Return TRUE if the function exists, or FALSE if not.
Example
if( ! $con->driver_has( 'prepare' ) ) { print "statements are not available!\n"; }
Large Objects
Drivers with access to large objects would create this class which supports following methods.
Return Values
Returns number of bytes read, 0 on eof, or undef on error.
Writes to the large object from the given buffer.
Parameters
The buffer to be written.
The optional parameter $offset can specify an alternate offset in the buffer.
The optional parameter $length can specify an alternate length of bytes written to the socket. If this length is greater then the buffer length, it is silently truncated to the length of the buffer.
Return Values
Returns the number of bytes successfully written, or undef on error.
Returns the size of the large object, or undef on error.
Moves the large object pointer to a specified location.
Parameters
Number of bytes or characters from $origin.
Initial position. It must be one of the following values:
0 - Beginning of large object. 1 - Current position of large object. 2 - End of large object.
Return Values
Returns a true value on success, or undef on error.
Returns the current position of the large object, or undef on error.
Writes to the large object from the given parameters.
Return Values
Returns a true value on success, or undef on error.
Example
$lob->print( 'hello lob', "\n" );
Returns the character read as an integer, or -1 on end of large object, or undef on error.
Returns a true value if a read operation has attempted to read past the end of the large object, 0 otherwise, or undef on error.
Closes the large object stream.
Return Values
Returns a true value on success, or undef on error.
THREADSAFETY
DBE was build for threads and should run properly with threads enabled. Objects are shared between threads. This means not that database connections are thread safe. It is never safe to use the same connection in two or more threads. You should make own connections for each thread. If you want share a database connection between threads you should use the lock() statement, which is a part of the threads::shared module.
AUTHORS
Navalla org., Christian Mueller, http://www.navalla.org/
COPYRIGHT
The DBE module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Generated with Perl 5.10.1 and
Perl-CGI 1.0 over
FastCGI within 12.41ms
in memory safe mode.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||