™.. DBIx::Simple - Online Linux Manual PageSection : 3
Updated : 2007-09-17
Source : perl v5.10.1
Note : User Contributed Perl Documentation
NAMEDBIx::Simple − Easy−to−use OO interface to DBI
SYNOPSIS
DBIx::Simple $db = DBIx::Simple−>connect(...) # or −>new
$db−>keep_statements = 16
$db−>lc_columns = 1
$db−>result_class = 'DBIx::Simple::Result';
$db−>begin_work $db−>commit
$db−>rollback $db−>disconnect
$db−>func(...) $db−>last_insert_id
$result = $db−>query(...)
DBIx::SImple + SQL::Interp $result = $db−>iquery(...)
DBIx::Simple + SQL::Abstract $db−>abstract = SQL::Abstract−>new(...)
$result = $db−>select(...)
$result = $db−>insert(...)
$result = $db−>update(...)
$result = $db−>delete(...)
DBIx::Simple::Result @columns = $result−>columns
$result−>into($foo, $bar, $baz)
$row = $result−>fetch
@row = $result−>list @rows = $result−>flat
$row = $result−>array @rows = $result−>arrays
$row = $result−>hash @rows = $result−>hashes
%map = $result−>map_arrays(...)
%map = $result−>map_hashes(...)
%map = $result−>map
$rows = $result−>rows
$dump = $result−>text
$result−>finish
DBIx::Simple::Result + DBIx::XHTML_Table $html = $result−>html(...)
$table_object = $result−>xto(...)
ExamplesPlease read DBIx::Simple::Examples for code examples.
DESCRIPTIONDBIx::Simple provides a simplified interface to DBI, Perl's powerful database module. This module is aimed at rapid development and easy maintenance. Query preparation and execution are combined in a single method, the result object (which is a wrapper around the statement handle) provides easy row-by-row and slurping methods. The \*(C`query\*(C'\fR method returns either a result object, or a dummy object. The dummy object returns undef (or an empty list) for all methods and when used in boolean context, is false. The dummy object lets you postpone (or skip) error checking, but it also makes immediate error checking simply \*(C`$db\->query(...) or die $db\->error\*(C'\fR.
DBIx::Simple methodsDBIx::Simple−>connect($dbh) DBIx::Simple−>connect($dsn, $user, $pass, \%options) DBIx::Simple−>new($dbh) DBIx::Simple−>new($dsn, $user, $pass, \%options) The \*(C`connect\*(C'\fR or \f(CW\*(C`new\*(C'\fR class method takes either an existing \s-1DBI\s0 object ($dbh), or a list of arguments to pass to \*(C`DBI\->connect\*(C'\fR. See \s-1DBI\s0 for a detailed description. You cannot use this method to clone a DBIx::Simple object: the $dbh passed should be a DBI::db object, not a DBIx::Simple object. This method is the constructor and returns a DBIx::Simple object on success. On failure, it returns undef. lc_columns = $bool When true at time of query execution, makes \*(C`columns\*(C'\fR, \f(CW\*(C`hash\*(C'\fR, \f(CW\*(C`hashes\*(C'\fR, and \*(C`map_hashes\*(C'\fR use lower cased column names. \f(CW\*(C`lc_columns\*(C'\fR is true by default. keep_statements = $integer Sets the number of statement objects that DBIx::Simple can keep for reuse. This can dramatically speed up repeated queries (like when used in a loop). \*(C`keep_statements\*(C'\fR is 16 by default. A query is only reused if it equals a previously used one literally. This means that to benefit from this caching mechanism, you must use placeholders and never interpolate variables yourself. # Wrong:
$db−>query("INSERT INTO foo VALUES ('$foo', '$bar', '$baz')");
$db−>query("SELECT FROM foo WHERE foo = '$foo' OR bar = '$bar'");
# Right:
$db−>query('INSERT INTO foo VALUES (??)', $foo, $bar, $baz);
$db−>query('SELECT FROM foo WHERE foo = ? OR bar = ?', $foo, $baz);
Of course, automatic value escaping is a much better reason for using placeholders. result_class = $string Class to use for result objects. Defaults to DBIx::Simple::Result. A constructor is not used. error Returns the error string of the last DBI method. See the discussion of "\*(C`err\*(C'\fR\*(L" and ”\*(C`errstr\*(C'\fR" in \s-1DBI\s0. query($query, @values) The \*(C`query\*(C'\fR method prepares and executes the query and returns a result object. If the string \*(C`(??)\*(C'\fR is present in the query, it is replaced with a list of as many question marks as @values. The database drivers substitute placeholders (question marks that do not appear in quoted literals) in the query with the given @values, after them escaping them. You should always use placeholders, and never use raw user input in database queries. On success, returns a DBIx::Simple::Result object. On failure, returns a DBIx::Simple::Dummy object. iquery Uses SQL::Interp to interpolate values into a query, and uses the resulting generated query and bind arguments with \*(C`query\*(C'\fR. See SQL::Interp's documentation for usage information. Requires that Mark Stosberg's SQL::Interp module be installed. It is available from CPAN. SQL::Interp is a fork from David Manura's SQL::Interpolate. select, insert, update, delete Calls the respective method on \*(C`abstract\*(C'\fR, and uses the resulting generated query and bind arguments with \*(C`query\*(C'\fR. See SQL::Abstract's documentation for usage information. You can override the object by assigning to the \*(C`abstract\*(C'\fR property. Obviously, calling \*(C`query\*(C'\fR directly is faster for the computer and using these abstracting methods is faster for the programmer. abstract = SQL::Abstract−>new(...) Sets the object to use with the \*(C`select\*(C'\fR, \f(CW\*(C`insert\*(C'\fR, \f(CW\*(C`update\*(C'\fR and \f(CW\*(C`delete\*(C'\fR methods. On first access, will create one with SQL::Abstract's default options. Requires that Nathan Wiger's SQL::Abstract module be installed. It is available from CPAN. In theory, you can assign any object to this property, as long as that object has these four methods, and they return a list suitable for use with the \*(C`query\*(C'\fR method. begin_work, begin, commit, rollback These transaction related methods call the DBI respective methods and Do What You Mean. See DBI for details. \*(C`begin\*(C'\fR is an alias for \f(CW\*(C`begin_work\*(C'\fR. func(...) This calls the \*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. last_insert_id(...) This calls the \*(C`last_insert_id\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. Note that this feature requires DBI 1.38 or newer. dbh Exposes the internal database handle. Use this only if you know what you are doing. Keeping a reference or doing queries can interfere with DBIx::Simple's garbage collection and error reporting. disconnect Destroys (finishes) active statements and disconnects. Whenever the database object is destroyed, this happens automatically if DBIx::Simple handled the connection (i.e. you didn't use an existing DBI handle). After disconnecting, you can no longer use the database object or any of its result objects.
DBIx::Simple::DummyThe \*(C`query\*(C'\fR method of DBIx::Simple returns a dummy object on failure. Its methods all return an empty list or undef, depending on context. When used in boolean context, a dummy object evaluates to false.
DBIx::Simple::Result methodscolumns Returns a list of column names. In scalar context, returns an array reference. Column names are lower cased if \*(C`lc_columns\*(C'\fR was true when the query was executed. bind(LIST) Binds the given LIST to the columns. The elements of LIST must be writable LVALUEs. In other words, use this method as: $result−>bind(my ($foo, $bar));
$result−>fetch;
Or, combined: $result−>into(my ($foo, $bar));
Unlike with DBI's \*(C`bind_columns\*(C'\fR, the \f(CW\*(C`\e\*(C'\fR operator is not needed. Bound variables are very efficient. Binding a tied variable doesn't work. fetch Fetches a single row and returns a reference to the array that holds the values. This is the same array every time. Subsequent fetches (using any method) may change the values in the variables passed and the returned reference's array. into(LIST) Combines \*(C`bind\*(C'\fR with \f(CW\*(C`fetch\*(C'\fR. Returns what \f(CW\*(C`fetch\*(C'\fR returns. list Fetches a single row and returns a list of values. In scalar context, returns only the last value. array Fetches a single row and returns an array reference. hash Fetches a single row and returns a hash reference. Keys are lower cased if \*(C`lc_columns\*(C'\fR was true when the query was executed. flat Fetches all remaining rows and returns a flattened list. In scalar context, returns an array reference. arrays Fetches all remaining rows and returns a list of array references. In scalar context, returns an array reference. hashes Fetches all remaining rows and returns a list of hash references. In scalar context, returns an array reference. Keys are lower cased if \*(C`lc_columns\*(C'\fR was true when the query was executed. map_arrays($column_number) Constructs a hash of array references keyed by the values in the chosen column. In scalar context, returns a hash reference. In list context, returns interleaved keys and values. map_hashes($column_name) Constructs a hash of hash references keyed by the values in the chosen column. In scalar context, returns a hash reference. In list context, returns interleaved keys and values. map Constructs a simple hash, using the two columns as key/value pairs. Should only be used with queries that return two columns. In scalar context, returns a hash reference. In list context, returns interleaved keys and values. rows Returns the number of rows affected by the last row affecting command, or −1 if the number of rows is not known or not available. For SELECT statements, it is generally not possible to know how many rows are returned. MySQL does provide this information. See DBI for a detailed explanation. xto(%attr) Returns a DBIx::XHTML_Table object, passing the constructor a reference to %attr. Requires that Jeffrey Hayes Anderson's DBIx::XHTML_Table module be installed. It is available from CPAN. In general, using the \*(C`html\*(C'\fR method (described below) is much easier. \f(CW\*(C`xto\*(C'\fR is available in case you need more flexibility. This method ignores the \*(C`lc_columns\*(C'\fR property. html(%attr) Returns an (X)HTML formatted table, using the DBIx::XHTML_Table module. Passes a reference to %attr to both the constructor and the \*(C`output\*(C'\fR method. Requires that Jeffrey Hayes Anderson's DBIx::XHTML_Table module be installed. It is available from CPAN. This method is a shortcut method. That means that $result−>html
$result−>html(
tr => { bgcolor => [ 'silver', 'white' ] },
no_ucfirst => 1
)
do the same as: $result−>xto−>output
$result−>xto(
tr => { bgcolor => [ 'silver', 'white' ] }
)−>output(
no_ucfirst => 1
);
text($type) Returns a string with a simple text representation of the data. $type can be any of: \*(C`neat\*(C'\fR, \f(CW\*(C`table\*(C'\fR, \f(CW\*(C`box\*(C'\fR. It defaults to \f(CW\*(C`table\*(C'\fR if Text::Table is installed, to \*(C`neat\*(C'\fR if it is. \*(C`table\*(C'\fI and \f(CI\*(C`box\*(C'\fI require that Anno Siegel's Text::Table module be installed. It is available from CPAN. attr(...) Returns a copy of an sth attribute (property). See ‟Statement Handle Attributes” in DBI for details. func(...) This calls the \*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. finish Finishes the statement. After finishing a statement, it can no longer be used. When the result object is destroyed, its statement handle is automatically finished and destroyed. There should be no reason to call this method explicitly; just let the result object go out of scope.
MISCELLANEOUSThe mapping methods do not check whether the keys are unique. Rows that are fetched later overwrite earlier ones. PrintError is disabled by default. If you enable it, beware that it will report line numbers in DBIx/Simple.pm.
LICENSEThere is no license. This software was released into the public domain. Do with it what you want, but on your own risk. The author disclaims any responsibility.
AUTHORJuerd Waalboer <juerd@cpan.org> <http://juerd.nl/>
SEE ALSOperl, perlref DBI, DBIx::Simple::Examples, SQL::Abstract, DBIx::XHTML_Table 0
Johanes Gumabo
Data Size : 46,066 byte
man-DBIx::Simple.3pmBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 3 / 165,800
Visitor ID : :
Visitor IP : 3.15.223.129 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|DBIx::Simple.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|DBIx::Simple.3pm|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|DBIx::Simple.3pm|41|br══─}─══|'br══─}─══
) (htmlprn|149|DBIx::Simple.3pm|41|'br══─}─══ |'br══─}─══
) (rof_nr_x|149|DBIx::Simple.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (rof_unit_scale_px|41|DBIx::Simple.3pm|51/52|F|.ie \nF ══─{─══. de IX
) (rof_if|19|DBIx::Simple.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (htmlprn|149|DBIx::Simple.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX
) (rof_escape_sequence|91|DBIx::Simple.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2"
) (parse_manual_page_|249|DBIx::Simple.3pm|57|══─}─══|.══─}─══
) (htmlprn|149|DBIx::Simple.3pm|57|.══─}─══ |.══─}─══
) (rof_escape_sequence|91|DBIx::Simple.3pm|208|\*(C`query\*(C'\fR method returns either a result object, or a dummy object. The |The \f(CW\*(C`query\*(C'\fR method returns either a result object, or a dummy object. The
) (rof_escape_sequence|91|DBIx::Simple.3pm|211|\*(C`$db\->query(...) or die $db\->error\*(C'\fR. |checking, but it also makes immediate error checking simply \f(CW\*(C`$db\->query(...) or die $db\->error\*(C'\fR.
) (rof_escape_sequence|91|DBIx::Simple.3pm|228|\*(C`connect\*(C'\fR or \f(CW\*(C`new\*(C'\fR class method takes either an existing \s-1DBI\s0 object |The \f(CW\*(C`connect\*(C'\fR or \f(CW\*(C`new\*(C'\fR class method takes either an existing \s-1DBI\s0 object
) (rof_escape_sequence|91|DBIx::Simple.3pm|229|\*(C`DBI\->connect\*(C'\fR. See \s-1DBI\s0 for a |($dbh), or a list of arguments to pass to \f(CW\*(C`DBI\->connect\*(C'\fR. See \s-1DBI\s0 for a
) (rof_escape_sequence|91|DBIx::Simple.3pm|240|\*(C`columns\*(C'\fR, \f(CW\*(C`hash\*(C'\fR, \f(CW\*(C`hashes\*(C'\fR, and |When true at time of query execution, makes \f(CW\*(C`columns\*(C'\fR, \f(CW\*(C`hash\*(C'\fR, \f(CW\*(C`hashes\*(C'\fR, and
) (rof_escape_sequence|91|DBIx::Simple.3pm|241|\*(C`map_hashes\*(C'\fR use lower cased column names. \f(CW\*(C`lc_columns\*(C'\fR is true by default. |\&\f(CW\*(C`map_hashes\*(C'\fR use lower cased column names. \f(CW\*(C`lc_columns\*(C'\fR is true by default.
) (rof_escape_sequence|91|DBIx::Simple.3pm|247|\*(C`keep_statements\*(C'\fR is 16 by default. |\&\f(CW\*(C`keep_statements\*(C'\fR is 16 by default.
) (rof_escape_sequence|91|DBIx::Simple.3pm|273|\*(C`err\*(C'\fR\*(L" |Returns the error string of the last \s-1DBI\s0 method. See the discussion of "\f(CW\*(C`err\*(C'\fR\*(L"
) (rof_escape_sequence|91|DBIx::Simple.3pm|274|\*(C`errstr\*(C'\fR" in \s-1DBI\s0. |and \*(R"\f(CW\*(C`errstr\*(C'\fR" in \s-1DBI\s0.
) (rof_escape_sequence|91|DBIx::Simple.3pm|278|\*(C`query\*(C'\fR method prepares and executes the query and returns a result object. |The \f(CW\*(C`query\*(C'\fR method prepares and executes the query and returns a result object.
) (rof_escape_sequence|91|DBIx::Simple.3pm|280|\*(C`(??)\*(C'\fR is present in the query, it is replaced with a list of as |If the string \f(CW\*(C`(??)\*(C'\fR is present in the query, it is replaced with a list of as
) (rof_escape_sequence|91|DBIx::Simple.3pm|295|\*(C`query\*(C'\fR. |generated query and bind arguments with \f(CW\*(C`query\*(C'\fR.
) (rof_escape_sequence|91|DBIx::Simple.3pm|305|\*(C`abstract\*(C'\fR, and uses the resulting generated |Calls the respective method on \f(CW\*(C`abstract\*(C'\fR, and uses the resulting generated
) (rof_escape_sequence|91|DBIx::Simple.3pm|306|\*(C`query\*(C'\fR. |query and bind arguments with \f(CW\*(C`query\*(C'\fR.
) (rof_escape_sequence|91|DBIx::Simple.3pm|309|\*(C`abstract\*(C'\fR property. |object by assigning to the \f(CW\*(C`abstract\*(C'\fR property.
) (rof_escape_sequence|91|DBIx::Simple.3pm|311|\*(C`query\*(C'\fR directly is faster for the computer and using these |Obviously, calling \f(CW\*(C`query\*(C'\fR directly is faster for the computer and using these
) (rof_escape_sequence|91|DBIx::Simple.3pm|316|\*(C`select\*(C'\fR, \f(CW\*(C`insert\*(C'\fR, \f(CW\*(C`update\*(C'\fR and \f(CW\*(C`delete\*(C'\fR |Sets the object to use with the \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`insert\*(C'\fR, \f(CW\*(C`update\*(C'\fR and \f(CW\*(C`delete\*(C'\fR
) (rof_escape_sequence|91|DBIx::Simple.3pm|324|\*(C`query\*(C'\fR method. |\&\f(CW\*(C`query\*(C'\fR method.
) (rof_escape_sequence|91|DBIx::Simple.3pm|331|\*(C`begin\*(C'\fR is an alias for \f(CW\*(C`begin_work\*(C'\fR. |\&\f(CW\*(C`begin\*(C'\fR is an alias for \f(CW\*(C`begin_work\*(C'\fR.
) (rof_escape_sequence|91|DBIx::Simple.3pm|335|\*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. |This calls the \f(CW\*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details.
) (rof_escape_sequence|91|DBIx::Simple.3pm|339|\*(C`last_insert_id\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. Note |This calls the \f(CW\*(C`last_insert_id\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. Note
) (rof_escape_sequence|91|DBIx::Simple.3pm|356|\*(C`query\*(C'\fR method of DBIx::Simple returns a dummy object on failure. Its |The \f(CW\*(C`query\*(C'\fR method of DBIx::Simple returns a dummy object on failure. Its
) (rof_escape_sequence|91|DBIx::Simple.3pm|366|\*(C`lc_columns\*(C'\fR was true when the query was |Column names are lower cased if \f(CW\*(C`lc_columns\*(C'\fR was true when the query was
) (rof_escape_sequence|91|DBIx::Simple.3pm|385|\*(C`bind_columns\*(C'\fR, the \f(CW\*(C`\e\*(C'\fR operator is not needed. |Unlike with \s-1DBI\s0's \f(CW\*(C`bind_columns\*(C'\fR, the \f(CW\*(C`\e\*(C'\fR operator is not needed.
) (rof_escape_sequence|91|DBIx::Simple.3pm|399|\*(C`bind\*(C'\fR with \f(CW\*(C`fetch\*(C'\fR. Returns what \f(CW\*(C`fetch\*(C'\fR returns. |Combines \f(CW\*(C`bind\*(C'\fR with \f(CW\*(C`fetch\*(C'\fR. Returns what \f(CW\*(C`fetch\*(C'\fR returns.
) (rof_escape_sequence|91|DBIx::Simple.3pm|414|\*(C`lc_columns\*(C'\fR was true when the query was executed. |Keys are lower cased if \f(CW\*(C`lc_columns\*(C'\fR was true when the query was executed.
) (rof_escape_sequence|91|DBIx::Simple.3pm|434|\*(C`lc_columns\*(C'\fR was true when the query was executed. |Keys are lower cased if \f(CW\*(C`lc_columns\*(C'\fR was true when the query was executed.
) (rof_escape_sequence|91|DBIx::Simple.3pm|478|\*(C`html\*(C'\fR method (described below) is much easier. \f(CW\*(C`xto\*(C'\fR |In general, using the \f(CW\*(C`html\*(C'\fR method (described below) is much easier. \f(CW\*(C`xto\*(C'\fR
) (rof_escape_sequence|91|DBIx::Simple.3pm|481|\*(C`lc_columns\*(C'\fR property. |This method ignores the \f(CW\*(C`lc_columns\*(C'\fR property.
) (rof_escape_sequence|91|DBIx::Simple.3pm|486|\*(C`output\*(C'\fR method. |a reference to \f(CW%attr\fR to both the constructor and the \f(CW\*(C`output\*(C'\fR method.
) (rof_escape_sequence|91|DBIx::Simple.3pm|517|\*(C`neat\*(C'\fR, \f(CW\*(C`table\*(C'\fR, \f(CW\*(C`box\*(C'\fR. It defaults to \f(CW\*(C`table\*(C'\fR if |can be any of: \f(CW\*(C`neat\*(C'\fR, \f(CW\*(C`table\*(C'\fR, \f(CW\*(C`box\*(C'\fR. It defaults to \f(CW\*(C`table\*(C'\fR if
) (rof_escape_sequence|91|DBIx::Simple.3pm|518|\*(C`neat\*(C'\fR if it is. |Text::Table is installed, to \f(CW\*(C`neat\*(C'\fR if it is.
) (rof_escape_sequence|91|DBIx::Simple.3pm|520|\*(C`table\*(C'\fI and \f(CI\*(C`box\*(C'\fI require that Anno Siegel's Text::Table module be |\&\fI\f(CI\*(C`table\*(C'\fI and \f(CI\*(C`box\*(C'\fI require that Anno Siegel's Text::Table module be
) (rof_escape_sequence|91|DBIx::Simple.3pm|530|\*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details. |This calls the \f(CW\*(C`func\*(C'\fR method of \s-1DBI\s0. See \s-1DBI\s0 for details.
)