@@ -35,7 +35,7 @@ use base qw( DBI::DBD::SqlEngine );
35
35
use Carp;
36
36
use vars qw( @ISA $VERSION $drh ) ;
37
37
38
- $VERSION = " 0.42 " ;
38
+ $VERSION = " 0.43 " ;
39
39
40
40
$drh = undef ; # holds driver handle(s) once initialized
41
41
@@ -85,6 +85,8 @@ use warnings;
85
85
86
86
use vars qw( @ISA $imp_data_size ) ;
87
87
88
+ use Carp;
89
+
88
90
@DBD::File::dr::ISA = qw( DBI::DBD::SqlEngine::dr ) ;
89
91
$DBD::File::dr::imp_data_size = 0;
90
92
@@ -100,6 +102,31 @@ sub dsn_quote
100
102
# XXX rewrite using TableConfig ...
101
103
sub default_table_source { " DBD::File::TableSource::FileSystem" }
102
104
105
+ sub connect
106
+ {
107
+ my ($drh , $dbname , $user , $auth , $attr ) = @_ ;
108
+
109
+ # We do not (yet) care about conflicting attributes here
110
+ # my $dbh = DBI->connect ("dbi:CSV:f_dir=test", undef, undef, { f_dir => "text" });
111
+ # will test here that both test and text should exist
112
+ if (my $attr_hash = (DBI-> parse_dsn ($dbname ))[3]) {
113
+ if (defined $attr_hash -> {f_dir } && ! -d $attr_hash -> {f_dir }) {
114
+ my $msg = " No such directory '$attr_hash ->{f_dir}" ;
115
+ $drh -> set_err (2, $msg );
116
+ $attr_hash -> {RaiseError } and croak $msg ;
117
+ return ;
118
+ }
119
+ }
120
+ if ($attr and defined $attr -> {f_dir } && ! -d $attr -> {f_dir }) {
121
+ my $msg = " No such directory '$attr ->{f_dir}" ;
122
+ $drh -> set_err (2, $msg );
123
+ $attr -> {RaiseError } and croak $msg ;
124
+ return ;
125
+ }
126
+
127
+ return $drh -> SUPER::connect ($dbname , $user , $auth , $attr );
128
+ } # connect
129
+
103
130
sub disconnect_all
104
131
{
105
132
} # disconnect_all
@@ -130,7 +157,7 @@ sub data_sources
130
157
{
131
158
my ($dbh , $attr , @other ) = @_ ;
132
159
ref ($attr ) eq " HASH" or $attr = {};
133
- exists $attr -> {f_dir } or $attr -> {f_dir } = $dbh -> {f_dir };
160
+ exists $attr -> {f_dir } or $attr -> {f_dir } = $dbh -> {f_dir };
134
161
exists $attr -> {f_dir_search } or $attr -> {f_dir_search } = $dbh -> {f_dir_search };
135
162
return $dbh -> SUPER::data_sources ($attr , @other );
136
163
} # data_source
@@ -343,6 +370,10 @@ sub data_sources
343
370
? $attr -> {f_dir }
344
371
: File::Spec-> curdir ();
345
372
defined $dir or return ; # Stream-based databases do not have f_dir
373
+ unless (-d $dir && -r $dir && -x $dir ) {
374
+ $drh -> set_err ($DBI::stderr , " Cannot use directory $dir from f_dir" );
375
+ return ;
376
+ }
346
377
my %attrs ;
347
378
$attr and %attrs = %$attr ;
348
379
delete $attrs {f_dir };
0 commit comments