403Webshell
Server IP : 103.119.228.120  /  Your IP : 18.223.237.218
Web Server : Apache
System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : nobody ( 99)
PHP Version : 5.6.40
Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime
MySQL : ON |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : ON |  Pkexec : ON
Directory :  /usr/local/share/man/man3/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/local/share/man/man3/Tie::DBI.3pm
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Tie::DBI 3"
.TH Tie::DBI 3 "2013-04-05" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Tie::DBI \- Tie hashes to DBI relational databases
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\&  use Tie::DBI;
\&  tie %h,\*(AqTie::DBI\*(Aq,\*(Aqmysql:test\*(Aq,\*(Aqtest\*(Aq,\*(Aqid\*(Aq,{CLOBBER=>1};
\&
\&  tie %h,\*(AqTie::DBI\*(Aq,{db       => \*(Aqmysql:test\*(Aq,
\&                   table    => \*(Aqtest\*(Aq,
\&                   key      => \*(Aqid\*(Aq,
\&                   user     => \*(Aqnobody\*(Aq,
\&                   password => \*(Aqghost\*(Aq,
\&                   CLOBBER  => 1};
\&
\&  # fetching keys and values
\&  @keys = keys %h;
\&  @fields = keys %{$h{$keys[0]}};
\&  print $h{\*(Aqid1\*(Aq}\->{\*(Aqfield1\*(Aq};
\&  while (($key,$value) = each %h) {
\&    print "Key = $key:\en";
\&    foreach (sort keys %$value) {
\&        print "\et$_ => $value\->{$_}\en";
\&    }
\&  }
\&
\&  # changing data
\&  $h{\*(Aqid1\*(Aq}\->{\*(Aqfield1\*(Aq} = \*(Aqnew value\*(Aq;
\&  $h{\*(Aqid1\*(Aq} = { field1 => \*(Aqnewer value\*(Aq,
\&                field2 => \*(Aqeven newer value\*(Aq,
\&                field3 => "so new it\*(Aqs squeaky clean" };
\&
\&  # other functions
\&  tied(%h)\->commit;
\&  tied(%h)\->rollback;
\&  tied(%h)\->select_where(\*(Aqprice > 1.20\*(Aq);
\&  @fieldnames = tied(%h)\->fields;
\&  $dbh = tied(%h)\->dbh;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module allows you to tie Perl associative arrays (hashes) to \s-1SQL\s0
databases using the \s-1DBI\s0 interface.  The tied hash is associated with a
table in a local or networked database.  One column becomes the hash
key.  Each row of the table becomes an associative array, from which
individual fields can be set or retrieved.
.SH "USING THE MODULE"
.IX Header "USING THE MODULE"
To use this module, you must have the \s-1DBI\s0 interface and at least one
\&\s-1DBD \s0(database driver) installed.  Make sure that your database is up
and running, and that you can connect to it and execute queries using
\&\s-1DBI.\s0
.SS "Creating the tie"
.IX Subsection "Creating the tie"
.Vb 1
\&   tie %var,\*(AqTie::DBI\*(Aq,[database,table,keycolumn] [,\e%options]
.Ve
.PP
Tie a variable to a database by providing the variable name, the tie
interface (always \*(L"Tie::DBI\*(R"), the data source name, the table to tie
to, and the column to use as the hash key.  You may also pass various
flags to the interface in an associative array.
.IP "database" 4
.IX Item "database"
The database may either be a valid DBI-style data source string of the
form \*(L"dbi:driver:database_name[:other information]\*(R", or a database
handle that has previously been opened.  See the documentation for \s-1DBI\s0
and your \s-1DBD\s0 driver for details.  Because the initial \*(L"dbi\*(R" is always
present in the data source, Tie::DBI will add it for you if necessary.
.Sp
Note that some drivers (Oracle in particular) have an irritating habit
of appending blanks to the end of fixed-length fields.  This will
screw up Tie::DBI's routines for getting key names.  To avoid this you
should create the database handle with a \fBChopBlanks\fR option of \s-1TRUE.\s0
You should also use a \fBPrintError\fR option of true to avoid complaints
during \s-1STORE\s0 and \s-1LISTFIELD\s0 calls.
.IP "table" 4
.IX Item "table"
The table in the database to bind to.  The table must previously have
been created with a \s-1SQL CREATE\s0 statement.  This module will not create
tables for you or modify the schema of the database.
.IP "key" 4
.IX Item "key"
The column to use as the hash key.  This column must prevoiusly have
been defined when the table was created.  In order for this module to
work correctly, the key column \fImust\fR be declared unique and not
nullable.  For best performance, the column should be also be declared
a key.  These three requirements are automatically satisfied for
primary keys.
.PP
It is possible to omit the database, table and keycolumn arguments, in
which case the module tries to retrieve the values from the options
array.  The options array contains a set of option/value pairs.  If
not provided, defaults are assumed.  The options are:
.IP "user" 4
.IX Item "user"
Account name to use for database authentication, if necessary.
Default is an empty string (no authentication necessary).
.IP "password" 4
.IX Item "password"
Password to use for database authentication, if necessary.  Default is
an empty string (no authentication necessary).
.IP "db" 4
.IX Item "db"
The database to bind to the hash, if not provided in the argument
list.  It may be a DBI-style data source string, or a
previously-opened database handle.
.IP "table" 4
.IX Item "table"
The name of the table to bind to the hash, if not provided in the
argument list.
.IP "key" 4
.IX Item "key"
The name of the column to use as the hash key, if not provided in the
argument list.
.IP "\s-1CLOBBER \s0(default 0)" 4
.IX Item "CLOBBER (default 0)"
This controls whether the database is writable via the bound hash.  A
zero value (the default) makes the database essentially read only.  An
attempt to store to the hash will result in a fatal error.  A \s-1CLOBBER\s0
value of 1 will allow you to change individual fields in the database,
and to insert new records, but not to delete entire records.  A
\&\s-1CLOBBER\s0 value of 2 allows you to delete records, but not to erase the
entire table.  A \s-1CLOBBER\s0 value of 3 or higher will allow you to erase
the entire table.
.Sp
.Vb 1
\&    Operation                       Clobber      Comment
\&
\&    $i = $h{strawberries}\->{price}     0       All read operations
\&    $h{strawberries}\->{price} += 5     1       Update fields
\&    $h{bananas}={price=>23,quant=>3}   1       Add records
\&    delete $h{strawberries}            2       Delete records
\&    %h = ()                            3       Clear entire table
\&    undef %h                           3       Another clear operation
.Ve
.Sp
All database operations are contingent upon your access privileges.
If your account does not have write permission to the database, hash
store operations will fail despite the setting of \s-1CLOBBER.\s0
.IP "\s-1AUTOCOMMIT \s0(default 1)" 4
.IX Item "AUTOCOMMIT (default 1)"
If set to a true value, the \*(L"autocommit\*(R" option causes the database
driver to commit after every store statement.  If set to a false
value, this option will not commit to the database until you
explicitly call the Tie::DBI \fIcommit()\fR method.
.Sp
The autocommit option defaults to true.
.IP "\s-1DEBUG \s0(default 0)" 4
.IX Item "DEBUG (default 0)"
When the \s-1DEBUG\s0 option is set to a non-zero value the module will echo
the contents of \s-1SQL\s0 statements and other debugging information to
standard error.  Higher values of \s-1DEBUG\s0 result in more verbose (and
annoying) output.
.IP "\s-1WARN \s0(default 1)" 4
.IX Item "WARN (default 1)"
If set to a non-zero value, warns of illegal operations, such as
attempting to delete the value of the key column.  If set to a zero
value, these errors will be ignored silently.
.IP "\s-1CASESENSITIV \s0(default 0)" 4
.IX Item "CASESENSITIV (default 0)"
If set to a non-zero value, all Fieldnames are casesensitiv. Keep
in mind, that your database has to support casesensitiv Fields if
you want to use it.
.SH "USING THE TIED ARRAY"
.IX Header "USING THE TIED ARRAY"
The tied array represents the database table.  Each entry in the hash
is a record, keyed on the column chosen in the \fItie()\fR statement.
Ordinarily this will be the table's primary key, although any unique
column will do.
.PP
Fetching an individual record returns a reference to a hash of field
names and values.  This hash reference is itself a tied object, so
that operations on it directly affect the database.
.SS "Fetching information"
.IX Subsection "Fetching information"
In the following examples, we will assume a database table structured
like this one:
.PP
.Vb 2
\&                    \-produce\-
\&    produce_id    price   quantity   description
\&
\&    strawberries  1.20    8          Fresh Maine strawberries
\&    apricots      0.85    2          Ripe Norwegian apricots
\&    bananas       1.30    28         Sweet Alaskan bananas
\&    kiwis         1.50    9          Juicy New York kiwi fruits
\&    eggs          1.00   12          Farm\-fresh Atlantic eggs
.Ve
.PP
We tie the variable \f(CW%produce\fR to the table in this way:
.PP
.Vb 5
\&    tie %produce,\*(AqTie::DBI\*(Aq,{db    => \*(Aqmysql:stock\*(Aq,
\&                           table => \*(Aqproduce\*(Aq,
\&                           key   => \*(Aqproduce_id\*(Aq,
\&                           CLOBBER => 2 # allow most updates
\&                           };
.Ve
.PP
We can get the list of keys this way:
.PP
.Vb 2
\&    print join(",",keys %produce);
\&       => strawberries,apricots,bananas,kiwis
.Ve
.PP
Or get the price of eggs thusly:
.PP
.Vb 3
\&    $price = $produce{eggs}\->{price};
\&    print "The price of eggs = $price";
\&        => The price of eggs = 1.2
.Ve
.PP
String interpolation works as you would expect:
.PP
.Vb 2
\&    print "The price of eggs is still $produce{eggs}\->{price}"
\&        => The price of eggs is still 1.2
.Ve
.PP
Various types of syntactic sugar are allowed.  For example, you can
refer to \f(CW$produce\fR{eggs}{price} rather than \f(CW$produce\fR{eggs}\->{price}.
Array slices are fully supported as well:
.PP
.Vb 3
\&    ($apricots,$kiwis) = @produce{apricots,kiwis};
\&    print "Kiwis are $kiwis\->{description};
\&        => Kiwis are Juicy New York kiwi fruits
\&
\&    ($price,$description) = @{$produce{eggs}}{price,description};
\&        => (2.4,\*(AqFarm\-fresh Atlantic eggs\*(Aq)
.Ve
.PP
If you provide the tied hash with a comma-delimited set of record
names, and you are \fBnot\fR requesting an array slice, then the module
does something interesting.  It generates a single \s-1SQL\s0 statement that
fetches the records from the database in a single pass (rather than
the multiple passes required for an array slice) and returns the
result as a reference to an array.  For many records, this can be much
faster.  For example:
.PP
.Vb 2
\&     $result = $produce{apricots,bananas};
\&         => ARRAY(0x828a8ac)
\&
\&     ($apricots,$bananas) = @$result;
\&     print "The price of apricots is $apricots\->{price}";
\&         => The price of apricots is 0.85
.Ve
.PP
Field names work in much the same way:
.PP
.Vb 3
\&     ($price,$quantity) = @{$produce{apricots}{price,quantity}};
\&     print "There are $quantity apricots at $price each";
\&         => There are 2 apricots at 0.85 each";
.Ve
.PP
Note that this takes advantage of a bit of Perl syntactic sugar which
automagically treats \f(CW$h\fR{'a','b','c'} as if the keys were packed
together with the $; pack character.  Be careful not to fall into this
trap:
.PP
.Vb 2
\&     $result = $h{join( \*(Aq,\*(Aq, \*(Aqapricots\*(Aq, \*(Aqbananas\*(Aq )};
\&         => undefined
.Ve
.PP
What you really want is this:
.PP
.Vb 2
\&     $result = $h{join( $;, \*(Aqapricots\*(Aq, \*(Aqbananas\*(Aq )};
\&         => ARRAY(0x828a8ac)
.Ve
.SS "Updating information"
.IX Subsection "Updating information"
If \s-1CLOBBER\s0 is set to a non-zero value (and the underlying database
privileges allow it), you can update the database with new values.
You can operate on entire records at once or on individual fields
within a record.
.PP
To insert a new record or update an existing one, assign a hash
reference to the record.  For example, you can create a new record in
\&\f(CW%produce\fR with the key \*(L"avocados\*(R" in this manner:
.PP
.Vb 3
\&   $produce{avocados} = { price       => 2.00,
\&                          quantity    => 8,
\&                          description => \*(AqChoice Irish avocados\*(Aq };
.Ve
.PP
This will work with any type of hash reference, including records
extracted from another table or database.
.PP
Only keys that correspond to valid fields in the table will be
accepted.  You will be warned if you attempt to set a field that
doesn't exist, but the other fields will be correctly set.  Likewise,
you will be warned if you attempt to set the key field.  These
warnings can be turned off by setting the \s-1WARN\s0 option to a zero value.
It is not currently possible to add new columns to the table.  You
must do this manually with the appropriate \s-1SQL\s0 commands.
.PP
The same syntax can be used to update an existing record.  The fields
given in the hash reference replace those in the record.  Fields that
aren't explicitly listed in the hash retain their previous values.  In
the following example, the price and quantity of the \*(L"kiwis\*(R" record
are updated, but the description remains the same:
.PP
.Vb 1
\&    $produce{kiwis} = { price=>1.25,quantity=>20 };
.Ve
.PP
You may update existing records on a field-by-field manner in the
natural way:
.PP
.Vb 4
\&    $produce{eggs}{price} = 1.30;
\&    $produce{eggs}{price} *= 2;
\&    print "The price of eggs is now $produce{eggs}{price}";
\&        => The price of eggs is now 2.6.
.Ve
.PP
Obligingly enough, you can use this syntax to insert new records too,
as in \f(CW$produce\fR{mangoes}{description}=\*(L"Sun\-ripened Idaho mangoes\*(R".
However, this type of update is inefficient because a separate \s-1SQL\s0
statement is generated for each field.  If you need to update more
than one field at a time, use the record-oriented syntax shown
earlier.  It's much more efficient because it gets the work done with
a single \s-1SQL\s0 command.
.PP
Insertions and updates may fail for any of a number of reasons, most
commonly:
.IP "1. You do not have sufficient privileges to update the database" 4
.IX Item "1. You do not have sufficient privileges to update the database"
.PD 0
.IP "2. The update would violate an integrity constraint, such as making a non-nullable field null, overflowing a numeric field, storing a string value in a numeric field, or violating a uniqueness constraint." 4
.IX Item "2. The update would violate an integrity constraint, such as making a non-nullable field null, overflowing a numeric field, storing a string value in a numeric field, or violating a uniqueness constraint."
.PD
.PP
The module dies with an error message when it encounters an error
during an update.  To trap these erorrs and continue processing, wrap
the update an \fIeval()\fR.
.SS "Other functions"
.IX Subsection "Other functions"
The tie object supports several useful methods.  In order to call
these methods, you must either save the function result from the \fItie()\fR
call (which returns the object), or call \fItied()\fR on the tie variable to
recover the object.
.IP "\fIconnect()\fR, \fIerror()\fR, \fIerrstr()\fR" 4
.IX Item "connect(), error(), errstr()"
These are low-level class methods.  \fIConnect()\fR is responsible for
establishing the connection with the \s-1DBI\s0 database.  \fIErrstr()\fR and
\&\fIerror()\fR return \f(CW$DBI::errstr\fR and \f(CW$DBI::error\fR respectively.  You may
may override these methods in subclasses if you wish.  For example,
replace \fIconnect()\fR with this code in order to use persistent database
connections in Apache modules:
.Sp
.Vb 6
\& use Apache::DBI;  # somewhere in the declarations
\& sub connect {
\& my ($class,$dsn,$user,$password,$options) = @_;
\&    return Apache::DBI\->connect($dsn,$user,
\&                                $password,$options);
\& }
.Ve
.IP "\fIcommit()\fR" 4
.IX Item "commit()"
.Vb 1
\&   (tied %produce)\->commit();
.Ve
.Sp
When using a database with the autocommit option turned off, values
that are stored into the hash will not become permanent until \fIcommit()\fR
is called.  Otherwise they are lost when the application terminates or
the hash is untied.
.Sp
Some \s-1SQL\s0 databases don't support transactions, in which case you will
see a warning message if you attempt to use this function.
.IP "\fIrollback()\fR" 4
.IX Item "rollback()"
.Vb 1
\&   (tied %produce)\->rollback();
.Ve
.Sp
When using a database with the autocommit option turned off, this
function will roll back changes to the database to the state they were
in at the last \fIcommit()\fR.  This function has no effect on database that
don't support transactions.
.IP "\fIselect_where()\fR" 4
.IX Item "select_where()"
.Vb 1
\&   @keys=(tied %produce)\->select_where(\*(Aqprice > 1.00 and quantity < 10\*(Aq);
.Ve
.Sp
This executes a limited form of select statement on the tied table and
returns a list of records that satisfy the conditions.  The argument
you provide should be the contents of a \s-1SQL WHERE\s0 clause, minus the
keyword \*(L"\s-1WHERE\*(R"\s0 and everything that ordinarily precedes it.  Anything
that is legal in the \s-1WHERE\s0 clause is allowed, including function
calls, ordering specifications, and sub-selects.  The keys to those
records that meet the specified conditions are returned as an array,
in the order in which the select statement returned them.
.Sp
Don't expect too much from this function.  If you want to execute a
complex query, you're better off using the database handle (see below)
to make the \s-1SQL\s0 query yourself with the \s-1DBI\s0 interface.
.IP "\fIdbh()\fR" 4
.IX Item "dbh()"
.Vb 1
\&   $dbh = (tied %produce)\->dbh();
.Ve
.Sp
This returns the tied hash's underlying database handle.  You can use
this handle to create and execute your own \s-1SQL\s0 queries.
.IP "\s-1CLOBBER, DEBUG, WARN\s0" 4
.IX Item "CLOBBER, DEBUG, WARN"
You can get and set the values of \s-1CLOBBER, DEBUG\s0 and \s-1WARN\s0 by directly
accessing the object's hash:
.Sp
.Vb 1
\&    (tied %produce)\->{DEBUG}++;
.Ve
.Sp
This lets you change the behavior of the tied hash on the fly, such as
temporarily granting your program write permission.
.Sp
There are other variables there too, such as the name of the key
column and database table.  Change them at your own risk!
.SH "PERFORMANCE"
.IX Header "PERFORMANCE"
What is the performance hit when you use this module rather than the
direct \s-1DBI\s0 interface?  It can be significant.  To measure the
overhead, I used a simple benchmark in which Perl parsed a 6180 word
text file into individual words and stored them into a database,
incrementing the word count with each store.  The benchmark then read
out the words and their counts in an \fIeach()\fR loop.  The database driver
was mySQL, running on a 133 MHz Pentium laptop with Linux 2.0.30.  I
compared Tie::RDBM, to DB_File, and to the same task using vanilla \s-1DBI
SQL\s0 statements.  The results are shown below:
.PP
.Vb 4
\&              UPDATE         FETCH
\&  Tie::DBI      70 s        6.1  s
\&  Vanilla DBI   14 s        2.0  s
\&  DB_File        3 s        1.06 s
.Ve
.PP
There is about a five-fold penalty for updates, and a three-fold
penalty for fetches when using this interface.  Some of the penalty is
due to the overhead for creating sub-objects to handle individual
fields, and some of it is due to the inefficient way the store and
fetch operations are implemented.  For example, using the tie
interface, a statement like \f(CW$h\fR{record}{field}++ requires as much as
four trips to the database: one to verify that the record exists, one
to fetch the field, and one to store the incremented field back.  If
the record doesn't already exist, an additional statement is required
to perform the insertion.  I have experimented with cacheing schemes
to reduce the number of trips to the database, but the overhead of
maintaining the cache is nearly equal to the performance improvement,
and cacheing raises a number of potential concurrency problems.
.PP
Clearly you would not want to use this interface for applications that
require a large number of updates to be processed rapidly.
.SH "BUGS"
.IX Header "BUGS"
.SH "BUGS"
.IX Header "BUGS"
The \fIeach()\fR call produces a fatal error when used with the Sybase
driver to access Microsoft \s-1SQL\s0 server. This is because this server
only allows one query to be active at a given time.  A workaround is
to use \fIkeys()\fR to fetch all the keys yourself.  It is not known whether
real Sybase databases suffer from the same problem.
.PP
The \fIdelete()\fR operator will not work correctly for setting field values
to null with \s-1DBD::CSV\s0 or with DBD::Pg.  \s-1CSV\s0 files do not have a good
conception of database nulls.  Instead you will set the field to an
empty string.  DBD::Pg just seems to be broken in this regard.
.SH "AUTHOR"
.IX Header "AUTHOR"
Lincoln Stein, lstein@cshl.org
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
.Vb 1
\&  Copyright (c) 1998, Lincoln D. Stein
.Ve
.PP
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.SH "AVAILABILITY"
.IX Header "AVAILABILITY"
The latest version can be obtained from:
.PP
.Vb 1
\&   http://www.genome.wi.mit.edu/~lstein/Tie\-DBI/
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIperl\fR\|(1), \s-1\fIDBI\s0\fR\|(3), \fITie::RDBM\fR\|(3)

Youez - 2016 - github.com/yon3zu
LinuXploit