1DBD::XBase(3) User Contributed Perl Documentation DBD::XBase(3)
2
3
4
6 DBD::XBase - DBI driver for XBase compatible database files
7
9 use DBI;
10 my $dbh = DBI->connect("DBI:XBase:/directory/subdir")
11 or die $DBI::errstr;
12 my $sth = $dbh->prepare("select MSG from test where ID != 1")
13 or die $dbh->errstr();
14 $sth->execute() or die $sth->errstr();
15
16 my @data;
17 while (@data = $sth->fetchrow_array())
18 { ## further processing }
19
20 $dbh->do('update table set name = ? where id = 45', {}, 'krtek');
21
23 DBI compliant driver for module XBase. Please refer to DBI(3) documen‐
24 tation for how to actually use the module. In the connect call, specify
25 the directory containing the dbf files (and other, memo, etc.) as the
26 third part of the connect string. It defaults to the current directory.
27
28 Note that with dbf, there is no database server that the driver would
29 talk to. This DBD::XBase calls methods from XBase.pm module to read and
30 write the files on the disk directly, so any limitations and features
31 of XBase.pm apply to DBD::XBase as well. DBD::XBase basically adds SQL,
32 DBI compliant interface to XBase.pm.
33
34 The DBD::XBase doesn't make use of index files at the moment. If you
35 really need indexed access, check XBase(3) for notes about support for
36 variour index types.
37
39 The SQL commands currently supported by DBD::XBase's prepare are:
40
41 select
42
43 select fields_or_expressions from table [ where condition ]
44 [ order by field ]
45
46 Fields_or_expressions is a comma separated list of fields or arithmetic
47 expressions, or a "*" for all fields from the table. The "where" condi‐
48 tion specifies which rows will be returned, you can have arbitrary
49 arithmetic and boolean expression here, compare fields and constants
50 and use "and" and "or". Match using "like" is also supported. Examples:
51
52 select * from salaries where name = "Smith"
53 select first,last from people where login = "ftp"
54 or uid = 1324
55 select id,first_name,last_name from employ
56 where last_name like 'Ki%' order by last_name
57 select id + 1, substr(name, 1, 10) from employ where age > 65
58 select id, name from employ where id = ?
59
60 You can use bind parameters in the where clause, as the last example
61 shows. The actual value has to be supplied via bind_param or in the
62 call to execute or do, see DBI(3) for details. To check for NULL values
63 in the "where" expression, use "id is null" and "id is not null", not
64 "id == null".
65
66 Please note that you can only select from one table, joins are not sup‐
67 ported and are not planned to be supported. If you need them, get a
68 real RDBMS (or send me a patch).
69
70 In the arithmetic expressions you can use a couple of SQL functions --
71 currently supported are concat, substr (and substring), trim, ltrim and
72 rtrim, length. I do not have an exact idea of which and how many func‐
73 tions I want to support. It's easy to write them in a couple of minutes
74 now the interface is there (check the XBase::SQL module if you want to
75 send a patch containing support for more), it's just that I do not
76 really need them and sometimes it's hard to tell what is usefull and
77 what is SQL92 compatible. Comment welcome.
78
79 The select command may contain and order by clause. Only one column is
80 supported for sorting at the moment, patches are welcome.
81
82 The group by clause is not supported (and I do not plan them), nor are
83 the aggregate functions.
84
85 delete
86
87 delete from table [ where condition ]
88
89 The "where" condition is the same as for select. Examples:
90
91 delete from jobs ## emties the table
92 delete from jobs where companyid = "ISW"
93 delete from jobs where id < ?
94
95 insert
96
97 insert into table [ ( fields ) ] values ( list of values )
98
99 Here fields is a (optional) comma separated list of fields to set, list
100 of values is a list of constants to assign. If the fields are not spec‐
101 ified, sets the fields in the natural order of the table. You can use
102 bind parameters in the list of values. Examples:
103
104 insert into accounts (login, uid) values ("guest", 65534)
105 insert into accounts (login, uid) values (?, ?)
106 insert into passwd values ("user","*",4523,100,"Nice user",
107 "/home/user","/bin/bash")
108
109 update
110
111 update table set field = new value [ , set more fields ]
112 [ where condition ]
113
114 Example:
115
116 update passwd set uid = 65534 where login = "guest"
117 update zvirata set name = "Jezek", age = 4 where id = 17
118
119 Again, the value can also be specified as bind parameter.
120
121 update zvirata set name = ?, age = ? where id = ?
122
123 create table
124
125 create table table name ( columns specification )
126
127 Columns specification is a comma separated list of column names and
128 types. Example:
129
130 create table rooms ( roomid int, cat char(10), balcony boolean )
131
132 The allowed types are
133
134 char num numeric int integer float boolean blob memo date time
135 datetime
136
137 Some of them are synonyms. They are of course converted to appropriate
138 XBase types.
139
140 drop table
141
142 drop table table name
143
144 Example:
145
146 drop table passwd
147
149 Besides standard DBI attribudes, DBD::XBase supports database handle
150 attribute xbase_ignorememo:
151
152 $dbh->{'xbase_ignorememo'} = 1;
153
154 Setting it to 1 will cause subsequent tables to be opened while ignor‐
155 ing the memo files (dbt, fpt). So you can read dbf files for which you
156 don't have (you have lost them, for example) the memo files. The memo
157 fields will come out as nulls.
158
160 0.240
161
163 (c) 1997--2003 Jan Pazdziora, adelton@fi.muni.cz,
164 http://www.fi.muni.cz/~adelton/ at Faculty of Informatics, Masaryk Uni‐
165 versity in Brno, Czech Republic
166
168 perl(1); DBI(3), XBase(3); dbish(1)
169
170 Translation into Japanese (older version) at http://mem‐
171 ber.nifty.ne.jp/hippo2000/perltips/DBD/XBase.htm by Kawai Takanori.
172
173
174
175perl v5.8.8 2003-11-21 DBD::XBase(3)