1DBD::File(3) User Contributed Perl Documentation DBD::File(3)
2
3
4
6 DBD::File - Base class for writing DBI drivers
7
9 This module is a base class for writing other DBDs.
10 It is not intended to function as a DBD itself.
11 If you want to access flatfiles, use DBD::AnyData, or DBD::CSV,
12 (both of which are subclasses of DBD::File).
13
15 The DBD::File module is not a true DBI driver, but an abstract base
16 class for deriving concrete DBI drivers from it. The implication is,
17 that these drivers work with plain files, for example CSV files or INI
18 files. The module is based on the SQL::Statement module, a simple SQL
19 engine.
20
21 See DBI for details on DBI, SQL::Statement for details on
22 SQL::Statement and DBD::CSV or DBD::IniFile for example drivers.
23
24 Metadata
25 The following attributes are handled by DBI itself and not by
26 DBD::File, thus they all work like expected:
27
28 Active
29 ActiveKids
30 CachedKids
31 CompatMode (Not used)
32 InactiveDestroy
33 Kids
34 PrintError
35 RaiseError
36 Warn (Not used)
37
38 The following DBI attributes are handled by DBD::File:
39
40 AutoCommit
41 Always on
42
43 ChopBlanks
44 Works
45
46 NUM_OF_FIELDS
47 Valid after "$sth-"execute>
48
49 NUM_OF_PARAMS
50 Valid after "$sth-"prepare>
51
52 NAME
53 Valid after "$sth-"execute>; undef for Non-Select statements.
54
55 NULLABLE
56 Not really working, always returns an array ref of one's, as
57 DBD::CSV doesn't verify input data. Valid after "$sth-"execute>;
58 undef for Non-Select statements.
59
60 These attributes and methods are not supported:
61
62 bind_param_inout
63 CursorName
64 LongReadLen
65 LongTruncOk
66
67 Additional to the DBI attributes, you can use the following dbh
68 attribute:
69
70 f_dir
71 This attribute is used for setting the directory where CSV files
72 are opened. Usually you set it in the dbh, it defaults to the
73 current directory ("."). However, it is overwritable in the
74 statement handles.
75
76 f_ext
77 This attribute is used for setting the file extension where (CSV)
78 files are opened. There are several possibilities.
79
80 DBI:CSV:f_dir=data;f_ext=.csv
81
82 In this case, DBD::File will open only "table.csv" if both
83 "table.csv" and "table" exist in the datadir. The table will still
84 be named "table". If your datadir has files with extensions, and
85 you do not pass this attribute, your table is named "table.csv",
86 which is probably not what you wanted. The extension is always
87 case-insensitive. The table names are not.
88
89 DBI:CSV:f_dir=data;f_ext=.csv/r
90
91 In this case the extension is required, and all filenames that do
92 not match are ignored.
93
94 f_schema
95 This will set the schema name. Default is the owner of the folder
96 in which the table file resides. "undef" is allowed.
97
98 my $dbh = DBI->connect ("dbi:CSV:", "", "", {
99 f_schema => undef,
100 f_dir => "data",
101 f_ext => ".csv/r",
102 }) or die $DBI::errstr;
103
104 The effect is that when you get table names from DBI, you can force
105 all tables into the same (or no) schema:
106
107 my @tables $dbh->tables ();
108
109 # no f_schema
110 "merijn".foo
111 "merijn".bar
112
113 # f_schema => "dbi"
114 "dbi".foo
115 "dbi".bar
116
117 # f_schema => undef
118 foo
119 bar
120
121 Driver private methods
122 data_sources
123 The "data_sources" method returns a list of subdirectories of the
124 current directory in the form "DBI:CSV:f_dir=$dirname".
125
126 If you want to read the subdirectories of another directory, use
127
128 my ($drh) = DBI->install_driver ("CSV");
129 my (@list) = $drh->data_sources (f_dir => "/usr/local/csv_data" );
130
131 list_tables
132 This method returns a list of file names inside $dbh->{f_dir}.
133 Example:
134
135 my ($dbh) = DBI->connect ("DBI:CSV:f_dir=/usr/local/csv_data");
136 my (@list) = $dbh->func ("list_tables");
137
138 Note that the list includes all files contained in the directory,
139 even those that have non-valid table names, from the view of SQL.
140
142 ยท The module is using flock () internally. However, this function
143 is not available on all platforms. Using flock () is disabled
144 on MacOS and Windows 95: There's no locking at all (perhaps not
145 so important on MacOS and Windows 95, as there's a single user
146 anyways).
147
149 This module is currently maintained by
150
151 H.Merijn Brand < h.m.brand at xs4all.nl > and Jens Rehsack < rehsack
152 at googlemail.com >
153
154 The original author is Jochen Wiedmann.
155
157 Copyright (C) 2009 by H.Merijn Brand & Jens Rehsack Copyright (C) 2004
158 by Jeff Zucker Copyright (C) 1998 by Jochen Wiedmann
159
160 All rights reserved.
161
162 You may freely distribute and/or modify this module under the terms of
163 either the GNU General Public License (GPL) or the Artistic License, as
164 specified in the Perl README file.
165
167 DBI, Text::CSV, Text::CSV_XS, SQL::Statement
168
169
170
171perl v5.10.1 2009-06-05 DBD::File(3)