📄 dbd::dbm.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...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" '''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 (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" 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 "DBD::DBM 3".TH DBD::DBM 3 "2007-09-26" "perl v5.10.0" "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"DBD::DBM \- a DBI driver for DBM & MLDBM files.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 6\& use DBI;\& $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq); # defaults to SDBM_File\& $dbh = DBI\->connect(\*(AqDBI:DBM(RaiseError=1):\*(Aq); # defaults to SDBM_File\& $dbh = DBI\->connect(\*(Aqdbi:DBM:type=GDBM_File\*(Aq); # defaults to GDBM_File\& $dbh = DBI\->connect(\*(Aqdbi:DBM:mldbm=Storable\*(Aq); # MLDBM with SDBM_File\& # and Storable.Ve.PPor.PP.Vb 2\& $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq, undef, undef);\& $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq, undef, undef, { dbm_type => \*(AqODBM_File\*(Aq });.Ve.PPand other variations on \fIconnect()\fR as shown in the \s-1DBI\s0 docs and withthe dbm_ attributes shown below.PP\&... and then use standard \s-1DBI\s0 prepare, execute, fetch, placeholders, etc.,see \*(L"\s-1QUICK\s0 \s-1START\s0\*(R" for an example.SH "DESCRIPTION".IX Header "DESCRIPTION"\&\s-1DBD::DBM\s0 is a database management sytem that can work right out of the box. If you have a standard installation of Perl and a standard installation of \s-1DBI\s0, you can begin creating, accessing, and modifying database tables without any further installation. You can also add some other modules to it for more robust capabilities if you wish..PPThe module uses a \s-1DBM\s0 file storage layer. \s-1DBM\s0 file storage is common on many platforms and files can be created with it in many languges. That means that, in addition to creating files with \s-1DBI/SQL\s0, you can also use \s-1DBI/SQL\s0 to access and modify files created by other \s-1DBM\s0 modules and programs. You can also use those programs to access files created with \s-1DBD::DBM\s0..PP\&\s-1DBM\s0 files are stored in binary format optimized for quick retrieval when using a key field. That optimization can be used advantageously to make \s-1DBD::DBM\s0 \s-1SQL\s0 operations that use key fields very fast. There are several different \*(L"flavors\*(R" of \s-1DBM\s0 \- different storage formats supported by different sorts of perl modules such as SDBM_File and \s-1MLDBM\s0. This module supports all of the flavors that perl supports and, when used with \s-1MLDBM\s0, supports tables with any number of columns and insertion of Perl objects into tables..PP\&\s-1DBD::DBM\s0 has been tested with the following \s-1DBM\s0 types: SDBM_File, NDBM_File, ODBM_File, GDBM_File, DB_File, BerekeleyDB. Each type was tested both with and without \s-1MLDBM\s0..SH "QUICK START".IX Header "QUICK START"\&\s-1DBD::DBM\s0 operates like all other \s-1DBD\s0 drivers \- it's basic syntax and operation is specified by \s-1DBI\s0. If you're not familiar with \s-1DBI\s0, you should start by reading \s-1DBI\s0 and the documents it points to and then come back and read this file. If you are familiar with \s-1DBI\s0, you already know most of what you need to know to operate this module. Just jump in and create a test script something like the one shown below..PPYou should be aware that there are several options for the \s-1SQL\s0 engine underlying \s-1DBD::DBM\s0, see \*(L"Supported \s-1SQL\s0 syntax\*(R". There are also many options for \s-1DBM\s0 support, see especially the section on \*(L"Adding multi-column support with \s-1MLDBM\s0\*(R"..PPBut here's a sample to get you started..PP.Vb 10\& use DBI;\& my $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq);\& $dbh\->{RaiseError} = 1;\& for my $sql( split /;\en+/,"\& CREATE TABLE user ( user_name TEXT, phone TEXT );\& INSERT INTO user VALUES (\*(AqFred Bloggs\*(Aq,\*(Aq233\-7777\*(Aq);\& INSERT INTO user VALUES (\*(AqSanjay Patel\*(Aq,\*(Aq777\-3333\*(Aq);\& INSERT INTO user VALUES (\*(AqJunk\*(Aq,\*(Aqxxx\-xxxx\*(Aq);\& DELETE FROM user WHERE user_name = \*(AqJunk\*(Aq;\& UPDATE user SET phone = \*(Aq999\-4444\*(Aq WHERE user_name = \*(AqSanjay Patel\*(Aq;\& SELECT * FROM user\& "){\& my $sth = $dbh\->prepare($sql);\& $sth\->execute;\& $sth\->dump_results if $sth\->{NUM_OF_FIELDS};\& }\& $dbh\->disconnect;.Ve.SH "USAGE".IX Header "USAGE".Sh "Specifiying Files and Directories".IX Subsection "Specifiying Files and Directories"\&\s-1DBD::DBM\s0 will automatically supply an appropriate file extension for the type of \s-1DBM\s0 you are using. For example, if you use SDBM_File, a table called \*(L"fruit\*(R" will be stored in two files called \*(L"fruit.pag\*(R" and \*(L"fruit.dir\*(R". You should \fInever\fR specify the file extensions in your \s-1SQL\s0 statements..PPHowever, I am not aware (and therefore \s-1DBD::DBM\s0 is not aware) of all possible extensions for various \s-1DBM\s0 types. If your \s-1DBM\s0 type uses an extension other than .pag and .dir, you should set the \fIdbm_ext\fR attribute to the extension. \fBAnd\fR you should write me with the name of the implementation and extension so I can add it to \s-1DBD::DBM\s0! Thanks in advance for that :\-)..PP.Vb 2\& $dbh = DBI\->connect(\*(Aqdbi:DBM:ext=.db\*(Aq); # .db extension is used\& $dbh = DBI\->connect(\*(Aqdbi:DBM:ext=\*(Aq); # no extension is used.Ve.PPor.PP.Vb 2\& $dbh\->{dbm_ext}=\*(Aq.db\*(Aq; # global setting\& $dbh\->{dbm_tables}\->{\*(Aqqux\*(Aq}\->{ext}=\*(Aq.db\*(Aq; # setting for table \*(Aqqux\*(Aq.Ve.PPBy default files are assumed to be in the current working directory. To have the module look in a different directory, specify the \fIf_dir\fR attribute in either the connect string or by setting the database handle attribute..PPFor example, this will look for the file /foo/bar/fruit (or /foo/bar/fruit.pag for \s-1DBM\s0 types that use that extension).PP.Vb 2\& my $dbh = DBI\->connect(\*(Aqdbi:DBM:f_dir=/foo/bar\*(Aq);\& my $ary = $dbh\->selectall_arrayref(q{ SELECT * FROM fruit });.Ve.PPAnd this will too:.PP.Vb 3\& my $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq);\& $dbh\->{f_dir} = \*(Aq/foo/bar\*(Aq;\& my $ary = $dbh\->selectall_arrayref(q{ SELECT x FROM fruit });.Ve.PPYou can also use delimited identifiers to specify paths directly in \s-1SQL\s0 statements. This looks in the same place as the two examples above but without setting \fIf_dir\fR:.PP.Vb 4\& my $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq);\& my $ary = $dbh\->selectall_arrayref(q{\& SELECT x FROM "/foo/bar/fruit"\& });.Ve.PPIf you have SQL::Statement installed, you can use table aliases:.PP.Vb 4\& my $dbh = DBI\->connect(\*(Aqdbi:DBM:\*(Aq);\& my $ary = $dbh\->selectall_arrayref(q{\& SELECT f.x FROM "/foo/bar/fruit" AS f\& });.Ve.PPSee the \*(L"\s-1GOTCHAS\s0 \s-1AND\s0 \s-1WARNINGS\s0\*(R" for using \s-1DROP\s0 on tables..Sh "Table locking and \fIflock()\fP".IX Subsection "Table locking and flock()"Table locking is accomplished using a lockfile which has the same name as the table's file but with the file extension '.lck' (or a lockfile extension that you suppy, see belwo). This file is created along with the table during a \s-1CREATE\s0 and removed during a \s-1DROP\s0. Every time the table itself is opened, the lockfile is \fIflocked()\fR. For \s-1SELECT\s0, this is an shared lock. For all other operations, it is an exclusive lock..PPSince the locking depends on \fIflock()\fR, it only works on operating systems that support \fIflock()\fR. In cases where \fIflock()\fR is not implemented, \s-1DBD::DBM\s0 will not complain, it will simply behave as if the \fIflock()\fR had occurred although no actual locking will happen. Read the documentation for \fIflock()\fR if you need to understand this..PPEven on those systems that do support \fIflock()\fR, the locking is only advisory \- as is allways the case with \fIflock()\fR. This means that if some other program tries to access the table while \s-1DBD::DBM\s0 has the table locked, that other program will *succeed* at opening the table. \s-1DBD::DBM\s0's locking only applies to \s-1DBD::DBM\s0. An exception to this would be the situation in which you use a lockfile with the other program that has the same name as the lockfile used in \s-1DBD::DBM\s0 and that program also uses \fIflock()\fR on that lockfile. In that case, \s-1DBD::DBM\s0 and your other program will respect each other's locks..PPIf you wish to use a lockfile extension other than '.lck', simply specify the dbm_lockfile attribute:.PP.Vb 3\& $dbh = DBI\->connect(\*(Aqdbi:DBM:lockfile=.foo\*(Aq);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -