Skip to content

Commit db55026

Browse files
committed
add a test-case showing PoC of new_sql_engine_meta
This adds a final fix and a test showing how to mix between different backends of DBI::DBD::SqlEngine
1 parent 489e67f commit db55026

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/DBI/DBD/SqlEngine.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ sub new_sql_engine_meta
816816
}
817817

818818
$dbh->{sql_meta}{$table} = { %{$values} };
819-
( my $class = $dbh->{ImplementorClass} ) =~ s/::db$/::Table/;
819+
my $class;
820+
defined $values->{sql_table_class} and $class = $values->{sql_table_class};
821+
defined $class or ( $class = $dbh->{ImplementorClass} ) =~ s/::db$/::Table/;
820822
# XXX we should never hit DBD::File::Table::get_table_meta here ...
821823
my ( undef, $meta ) = $class->get_table_meta( $dbh, $table, $respect_case );
822824
1;

t/53sqlengine_adv.t

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!perl -w
2+
$| = 1;
3+
4+
use strict;
5+
use warnings;
6+
7+
require DBD::DBM;
8+
9+
use File::Path;
10+
use File::Spec;
11+
use Test::More;
12+
use Cwd;
13+
use Config qw(%Config);
14+
use Storable qw(dclone);
15+
16+
my $using_dbd_gofer = ( $ENV{DBI_AUTOPROXY} || '' ) =~ /^dbi:Gofer.*transport=/i;
17+
plan skip_all => "Modifying driver state won't compute running behind Gofer" if($using_dbd_gofer);
18+
19+
use DBI;
20+
21+
# <[Sno]> what I could do is create a new test case where inserting into a DBD::DBM and after that clone the meta into a DBD::File $dbh
22+
# <[Sno]> would that help to get a better picture?
23+
24+
do "t/lib.pl";
25+
my $dir = test_dir();
26+
27+
my $dbm_dbh = DBI->connect( 'dbi:DBM:', undef, undef, {
28+
f_dir => $dir,
29+
sql_identifier_case => 2, # SQL_IC_LOWER
30+
}
31+
);
32+
33+
$dbm_dbh->do(q/create table FRED (a integer, b integer)/);
34+
$dbm_dbh->do(q/insert into fRED (a,b) values(1,2)/);
35+
$dbm_dbh->do(q/insert into FRED (a,b) values(2,1)/);
36+
37+
my $f_dbh = DBI->connect( 'dbi:File:', undef, undef, {
38+
f_dir => $dir,
39+
sql_identifier_case => 2, # SQL_IC_LOWER
40+
}
41+
);
42+
43+
my $dbm_fred_meta = $dbm_dbh->f_get_meta("fred", [qw(dbm_type)]);
44+
$f_dbh->f_new_meta( "fred", {sql_table_class => "DBD::DBM::Table"} );
45+
46+
my $r = $f_dbh->selectall_arrayref(q/select * from Fred/);
47+
ok( @$r == 2, 'rows found via mixed case table' );
48+
49+
done_testing();

0 commit comments

Comments
 (0)