379 changes: 198 additions & 181 deletions lib/DBIx/Class/Storage/DBI.pm

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ sub _rebless {
$self->_identity_method('@@identity');
}

sub source_bind_attributes {
my $self = shift;
my ($source) = @_;

my $bind_attributes = $self->next::method(@_);
# work around a bug in the ADO driver - use the max VARCHAR size for all
# binds that do not specify one via bind_attributes_by_data_type()
sub _dbi_attrs_for_bind {
my $attrs = shift->next::method(@_);

foreach my $column ($source->columns) {
$bind_attributes->{$column}{ado_size} ||= 8000; # max VARCHAR
for (@$attrs) {
$_->{ado_size} ||= 8000 if $_;
}

return $bind_attributes;
$attrs;
}

sub bind_attribute_by_data_type {
Expand Down
19 changes: 5 additions & 14 deletions lib/DBIx/Class/Storage/DBI/AutoCast.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,19 @@ L<connect_info|DBIx::Class::Storage::DBI/connect_info> as:

sub _prep_for_execute {
my $self = shift;
my ($op, $extra_bind, $ident, $args) = @_;

my ($sql, $bind) = $self->next::method (@_);

# If we're using ::NoBindVars, there are no binds by this point so this code
# gets skippeed.
if ($self->auto_cast && @$bind) {
my $new_sql;
my @sql_part = split /\?/, $sql;
my $col_info = $self->_resolve_column_info($ident,[ map $_->[0], @$bind ]);

foreach my $bound (@$bind) {
my $col = $bound->[0];
my $type = $self->_native_data_type($col_info->{$col}{data_type});

foreach my $data (@{$bound}[1..$#$bound]) {
$new_sql .= shift(@sql_part) .
($type ? "CAST(? AS $type)" : '?');
}
my @sql_part = split /\?/, $sql, scalar @$bind + 1;
for (@$bind) {
my $cast_type = $self->_native_data_type($_->[0]{sqlt_datatype});
$new_sql .= shift(@sql_part) . ($cast_type ? "CAST(? AS $cast_type)" : '?');
}
$new_sql .= join '', @sql_part;
$sql = $new_sql;
$sql = $new_sql . shift @sql_part;
}

return ($sql, $bind);
Expand Down
4 changes: 2 additions & 2 deletions lib/DBIx/Class/Storage/DBI/MSSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sub insert {

sub _prep_for_execute {
my $self = shift;
my ($op, $extra_bind, $ident, $args) = @_;
my ($op, $ident, $args) = @_;

# cast MONEY values properly
if ($op eq 'insert' || $op eq 'update') {
Expand Down Expand Up @@ -113,7 +113,7 @@ sub _execute {
my $self = shift;
my ($op) = @_;

my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
my ($rv, $sth, @bind) = $self->next::method(@_);

if ($op eq 'insert') {

Expand Down
29 changes: 14 additions & 15 deletions lib/DBIx/Class/Storage/DBI/NoBindVars.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@ sub _prep_for_execute {
my ($sql, $bind) = $self->next::method(@_);

# stringify bind args, quote via $dbh, and manually insert
#my ($op, $extra_bind, $ident, $args) = @_;
my $ident = $_[2];
#my ($op, $ident, $args) = @_;
my $ident = $_[1];

my @sql_part = split /\?/, $sql;
my $new_sql;

my $col_info = $self->_resolve_column_info($ident, [ map $_->[0], @$bind ]);
my $col_info = $self->_resolve_column_info(
$ident, [ map { $_->[0]{dbic_colname} || () } @$bind ]
);

foreach my $bound (@$bind) {
my $col = shift @$bound;
for (@$bind) {
my $datatype = $col_info->{ $_->[0]{dbic_colname}||'' }{data_type};

my $datatype = $col_info->{$col}{data_type};
my $data = (ref $_->[1]) ? "$_->[1]" : $_->[1]; # always stringify

foreach my $data (@$bound) {
$data = ''.$data if ref $data;
$data = $self->_prep_interpolated_value($datatype, $data)
if $datatype;

$data = $self->_prep_interpolated_value($datatype, $data)
if $datatype;
$data = $self->_get_dbh->quote($data)
unless $self->interpolate_unquoted($datatype, $data);

$data = $self->_dbh->quote($data)
unless $self->interpolate_unquoted($datatype, $data);

$new_sql .= shift(@sql_part) . $data;
}
$new_sql .= shift(@sql_part) . $data;
}

$new_sql .= join '', @sql_part;

return ($new_sql, []);
Expand Down
3 changes: 1 addition & 2 deletions lib/DBIx/Class/Storage/DBI/ODBC/ACCESS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ sub insert {
my $self = shift;
my ( $source, $to_insert ) = @_;

my $bind_attributes = $self->source_bind_attributes( $source );
my ( undef, $sth ) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert );
my ( undef, $sth ) = $self->_execute( 'insert', $source, $to_insert );

#store the identity here since @@IDENTITY is connection global and this prevents
#possibility that another insert to a different table overwrites it for this resultsource
Expand Down
94 changes: 47 additions & 47 deletions lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,14 @@ sub _ping {
}

sub _dbh_execute {
my $self = shift;
my ($dbh, $op, $extra_bind, $ident, $bind_attributes, @args) = @_;
my ($self, $dbh, $sql, @args) = @_;

my (@res, $tried);
my $want = wantarray;
my $next = $self->next::can;
do {
try {
my $exec = sub { $self->$next($dbh, $op, $extra_bind, $ident, $bind_attributes, @args) };
my $exec = sub { $self->$next($dbh, $sql, @args) };

if (!defined $want) {
$exec->();
Expand All @@ -298,7 +297,6 @@ sub _dbh_execute {
if (! $tried and $_ =~ /ORA-01003/) {
# ORA-01003: no statement parsed (someone changed the table somehow,
# invalidating your cursor.)
my ($sql, $bind) = $self->_prep_for_execute($op, $extra_bind, $ident, \@args);
delete $dbh->{CachedKids}{$sql};
}
else {
Expand Down Expand Up @@ -384,55 +382,57 @@ sub connect_call_datetime_setup {
);
}

=head2 source_bind_attributes
Handle LOB types in Oracle. Under a certain size (4k?), you can get away
with the driver assuming your input is the deprecated LONG type if you
encode it as a hex string. That ain't gonna fly at larger values, where
you'll discover you have to do what this does.
This method had to be overridden because we need to set ora_field to the
actual column, and that isn't passed to the call (provided by Storage) to
bind_attribute_by_data_type.
According to L<DBD::Oracle>, the ora_field isn't always necessary, but
adding it doesn't hurt, and will save your bacon if you're modifying a
table with more than one LOB column.
=cut

sub source_bind_attributes
{
require DBD::Oracle;
my $self = shift;
my($source) = @_;

my %bind_attributes = %{ $self->next::method(@_) };

foreach my $column ($source->columns) {
my %column_bind_attrs = %{ $bind_attributes{$column} || {} };
### Note originally by Ron "Quinn" Straight <quinnfazigu@gmail.org>
### http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=commitdiff;h=5db2758de644d53e07cd3e05f0e9037bf40116fc
#
# Handle LOB types in Oracle. Under a certain size (4k?), you can get away
# with the driver assuming your input is the deprecated LONG type if you
# encode it as a hex string. That ain't gonna fly at larger values, where
# you'll discover you have to do what this does.
#
# This method had to be overridden because we need to set ora_field to the
# actual column, and that isn't passed to the call (provided by Storage) to
# bind_attribute_by_data_type.
#
# According to L<DBD::Oracle>, the ora_field isn't always necessary, but
# adding it doesn't hurt, and will save your bacon if you're modifying a
# table with more than one LOB column.
#
sub _dbi_attrs_for_bind {
my ($self, $ident, $bind) = @_;
my $attrs = $self->next::method($ident, $bind);

for my $i (0 .. $#$attrs) {
if (keys %{$attrs->[$i]||{}} and my $col = $bind->[$i][0]{dbic_colname}) {
$attrs->[$i]{ora_field} = $col;
}
}

my $data_type = $source->column_info($column)->{data_type};
$attrs;
}

if ($self->_is_lob_type($data_type)) {
if ($DBD::Oracle::VERSION eq '1.23') {
$self->throw_exception(
"BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later ".
"version.\n\nSee: https://rt.cpan.org/Public/Bug/Display.html?id=46016\n"
);
}
my $dbd_loaded;
sub bind_attribute_by_data_type {
my ($self, $dt) = @_;

$dbd_loaded ||= do {
require DBD::Oracle;
if ($DBD::Oracle::VERSION eq '1.23') {
$self->throw_exception(
"BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later ".
"version.\n\nSee: https://rt.cpan.org/Public/Bug/Display.html?id=46016\n"
);
}
1;
};

$column_bind_attrs{'ora_type'} = $self->_is_text_lob_type($data_type)
if ($self->_is_lob_type($dt)) {
return {
ora_type => $self->_is_text_lob_type($dt)
? DBD::Oracle::ORA_CLOB()
: DBD::Oracle::ORA_BLOB()
;
$column_bind_attrs{'ora_field'} = $column;
}

$bind_attributes{$column} = \%column_bind_attrs;
};
}

return \%bind_attributes;
}

sub _svp_begin {
Expand Down
8 changes: 5 additions & 3 deletions lib/DBIx/Class/Storage/DBI/Replicated.pm
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,26 @@ my $method_dispatch = {
svp_release
relname_to_table_alias
_dbh_last_insert_id
_fix_bind_params
_default_dbi_connect_attributes
_dbi_connect_info
_dbic_connect_attributes
auto_savepoint
_query_start
_query_end
_format_for_trace
_dbi_attrs_for_bind
bind_attribute_by_data_type
transaction_depth
_dbh
_select_args
_dbh_execute_array
_sql_maker
_query_start
_per_row_update_delete
_dbh_begin_work
_dbh_execute_inserts_with_no_binds
_select_args_to_query
_svp_generate_name
_multipk_update_delete
source_bind_attributes
_normalize_connect_info
_parse_connect_do
_dbh_commit
Expand Down Expand Up @@ -336,6 +336,8 @@ my $method_dispatch = {
_arm_global_destructor
_verify_pid
source_bind_attributes
get_use_dbms_capability
set_use_dbms_capability
get_dbms_capability
Expand Down
7 changes: 7 additions & 0 deletions lib/DBIx/Class/Storage/DBI/SQLite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ sub deployment_statements {
$self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
}

sub bind_attribute_by_data_type {
$_[1] =~ /^ (?: int(?:eger)? | (?:tiny|small|medium|big)int ) $/ix
? do { require DBI; DBI::SQL_INTEGER() }
: undef
;
}

=head2 connect_call_use_foreign_keys
Used as:
Expand Down
11 changes: 4 additions & 7 deletions lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ sub _is_lob_column {

sub _prep_for_execute {
my $self = shift;
my ($op, $extra_bind, $ident, $args) = @_;
my ($op, $ident, $args) = @_;

my ($sql, $bind) = $self->next::method (@_);

my $table = blessed $ident ? $ident->from : $ident;

my $bind_info = $self->_resolve_column_info(
$ident, [map $_->[0], @{$bind}]
$ident, [map { $_->[0]{dbic_colname} || () } @{$bind}]
);
my $bound_identity_col =
first { $bind_info->{$_}{is_auto_increment} }
Expand Down Expand Up @@ -333,7 +333,7 @@ sub _execute {
my $self = shift;
my ($op) = @_;

my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
my ($rv, $sth, @bind) = $self->next::method(@_);

if ($op eq 'insert') {
$self->_identity($sth->fetchrow_array);
Expand Down Expand Up @@ -634,10 +634,7 @@ EOF
}
);

my @bind = do {
my $idx = 0;
map [ $_, $idx++ ], @source_columns;
};
my @bind = map { [ $source_columns[$_] => $_ ] } (0 .. $#source_columns);

$self->_execute_array(
$source, $sth, \@bind, \@source_columns, \@new_data, sub {
Expand Down
63 changes: 48 additions & 15 deletions t/73oracle_hq.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ do_creates($dbh);
START WITH name = ?
CONNECT BY parentid = PRIOR artistid
)',
[ [ name => 'root'] ],
[ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'] ],
);
is_deeply (
[ $rs->get_column ('name')->all ],
Expand All @@ -132,7 +133,8 @@ do_creates($dbh);
START WITH name = ?
CONNECT BY parentid = PRIOR artistid
)',
[ [ name => 'root'] ],
[ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'] ],
);

is( $rs->count, 5, 'Connect By count ok' );
Expand All @@ -159,7 +161,8 @@ do_creates($dbh);
CONNECT BY parentid = PRIOR artistid
ORDER SIBLINGS BY name DESC
)',
[ [ name => 'root'] ],
[ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'] ],
);

is_deeply (
Expand All @@ -185,7 +188,8 @@ do_creates($dbh);
START WITH name = ?
CONNECT BY parentid = PRIOR artistid
)',
[ [ name => 'root'] ],
[ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'] ],
);

is_deeply(
Expand Down Expand Up @@ -220,7 +224,12 @@ do_creates($dbh);
START WITH me.name = ?
CONNECT BY parentid = PRIOR artistid
)',
[ [ 'cds.title' => '%cd' ], [ 'me.name' => 'root' ] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'cds.title', 'sqlt_size' => 100 }
=> '%cd'],
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'me.name', 'sqlt_size' => 100 }
=> 'root'],
],
);

is_deeply(
Expand All @@ -239,7 +248,12 @@ do_creates($dbh);
START WITH me.name = ?
CONNECT BY parentid = PRIOR artistid
)',
[ [ 'cds.title' => '%cd' ], [ 'me.name' => 'root' ] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'cds.title', 'sqlt_size' => 100 }
=> '%cd'],
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'me.name', 'sqlt_size' => 100 }
=> 'root'],
],
);

is( $rs->count, 1, 'Connect By with a join; count ok' );
Expand All @@ -262,7 +276,10 @@ do_creates($dbh);
CONNECT BY parentid = PRIOR artistid
ORDER BY LEVEL ASC, name ASC
)',
[ [ name => 'root' ] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'],
],
);


Expand Down Expand Up @@ -312,7 +329,10 @@ do_creates($dbh);
) me
WHERE ROWNUM <= 2
)',
[ [ name => 'root' ] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'],
],
);

is_deeply (
Expand All @@ -336,7 +356,10 @@ do_creates($dbh);
WHERE ROWNUM <= 2
) me
)',
[ [ name => 'root' ] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'],
],
);

is( $rs->count, 2, 'Connect By; LIMIT count ok' );
Expand Down Expand Up @@ -364,10 +387,14 @@ do_creates($dbh);
GROUP BY( rank + ? ) HAVING count(rank) < ?
)',
[
[ __cbind => 3 ],
[ name => 'root' ],
[ __gbind => 1 ],
[ cnt => 2 ]
[ { dbic_colname => '__cbind' }
=> 3 ],
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'root'],
[ { dbic_colname => '__gbind' }
=> 1 ],
[ { dbic_colname => 'cnt' }
=> 2 ],
],
);

Expand Down Expand Up @@ -411,7 +438,10 @@ do_creates($dbh);
START WITH name = ?
CONNECT BY NOCYCLE parentid = PRIOR artistid
)',
[ [ name => 'cycle-root'] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'cycle-root'],
],
);
is_deeply (
[ $rs->get_column ('name')->all ],
Expand All @@ -432,7 +462,10 @@ do_creates($dbh);
START WITH name = ?
CONNECT BY NOCYCLE parentid = PRIOR artistid
)',
[ [ name => 'cycle-root'] ],
[
[ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 }
=> 'cycle-root'],
],
);

is( $rs->count, 4, 'Connect By Nocycle count ok' );
Expand Down
30 changes: 24 additions & 6 deletions t/746mssql.t
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,16 @@ SQL
);

my ($sql, @bind) = @${$owners->page(3)->as_query};
is_deeply (
is_same_bind (
\@bind,
[
$dialect eq 'Top' ? [ test => 'xxx' ] : (), # the extra re-order bind
([ 'me.name' => 'somebogusstring' ], [ test => 'xxx' ]) x 2 # double because of the prefetch subq
$dialect eq 'Top' ? [ { dbic_colname => 'test' } => 'xxx' ] : (), # the extra re-order bind
(map {
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' }
=> 'somebogusstring' ],
[ { dbic_colname => 'test' }
=> 'xxx' ],
} (1,2)), # double because of the prefetch subq
],
);

Expand Down Expand Up @@ -411,13 +416,26 @@ SQL
);

($sql, @bind) = @${$books->page(3)->as_query};
is_deeply (
is_same_bind (
\@bind,
[
# inner
[ 'owner.name' => 'wiggle' ], [ 'owner.name' => 'woggle' ], [ source => 'Library' ], [ test => '1' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
=> 'wiggle' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
=> 'woggle' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ],
[ { dbic_colname => 'test' }
=> '1' ],

# outer
[ 'owner.name' => 'wiggle' ], [ 'owner.name' => 'woggle' ], [ source => 'Library' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
=> 'wiggle' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'owner.name' }
=> 'woggle' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ],
],
);

Expand Down
18 changes: 11 additions & 7 deletions t/93autocast.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ my $rs = $schema->resultset ('CD')->search ({
'tracks.last_updated_at' => { '!=', undef },
'tracks.last_updated_on' => { '<', 2009 },
'tracks.position' => 4,
'tracks.single_track' => \[ '= ?', [ single_track => [1, 2, 3 ] ] ],
'me.single_track' => \[ '= ?', [ single_track => [1, 2, 3 ] ] ],
}, { join => 'tracks' });

my $bind = [
[ cdid => 5 ],
[ 'tracks.last_updated_on' => 2009 ],
[ 'tracks.position' => 4 ],
[ 'single_track' => [ 1, 2, 3] ],
[ { sqlt_datatype => 'integer', dbic_colname => 'cdid' }
=> 5 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'single_track' }
=> [ 1, 2, 3] ],
[ { sqlt_datatype => 'datetime', dbic_colname => 'tracks.last_updated_on' }
=> 2009 ],
[ { sqlt_datatype => 'int', dbic_colname => 'tracks.position' }
=> 4 ],
];

is_same_sql_bind (
Expand All @@ -51,10 +55,10 @@ is_same_sql_bind (
LEFT JOIN track tracks ON tracks.cd = me.cdid
WHERE
cdid > ?
AND me.single_track = ?
AND tracks.last_updated_at IS NOT NULL
AND tracks.last_updated_on < ?
AND tracks.position = ?
AND tracks.single_track = ?
)',
$bind,
'expected sql with casting off',
Expand All @@ -70,10 +74,10 @@ is_same_sql_bind (
LEFT JOIN track tracks ON tracks.cd = me.cdid
WHERE
cdid > CAST(? AS INT)
AND me.single_track = CAST(? AS INT)
AND tracks.last_updated_at IS NOT NULL
AND tracks.last_updated_on < CAST (? AS DateTime)
AND tracks.position = ?
AND tracks.single_track = CAST(? AS INT)
)',
$bind,
'expected sql with casting on',
Expand Down
17 changes: 14 additions & 3 deletions t/count/count_rs.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ my $schema = DBICTest->init_schema();
LIMIT 3 OFFSET 8
) tracks
)',
[ [ position => 1 ], [ position => 2 ] ],
[
[ { sqlt_datatype => 'int', dbic_colname => 'position' }
=> 1 ],
[ { sqlt_datatype => 'int', dbic_colname => 'position' }
=> 2 ],
],
'count_rs db-side limit applied',
);
}
Expand Down Expand Up @@ -109,7 +114,12 @@ my $schema = DBICTest->init_schema();
LIMIT 3 OFFSET 4
) cds
)',
[ [ 'tracks.position' => 1 ], [ 'tracks.position' => 2 ] ],
[
[ { sqlt_datatype => 'int', dbic_colname => 'tracks.position' }
=> 1 ],
[ { sqlt_datatype => 'int', dbic_colname => 'tracks.position' }
=> 2 ],
],
'count_rs db-side limit applied',
);
}
Expand Down Expand Up @@ -140,7 +150,8 @@ my $schema = DBICTest->init_schema();
HAVING newest_cd_year = ?
) me
)',
[ [ 'newest_cd_year' => '2001' ],],
[ [ { dbic_colname => 'newest_cd_year' }
=> '2001' ] ],
'count with having clause keeps sql as alias',
);

Expand Down
8 changes: 5 additions & 3 deletions t/count/prefetch.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ my $schema = DBICTest->init_schema();
GROUP BY cds.cdid
) cds
)',
[ map { [ 'tracks.position' => $_ ] } (1, 2) ],
[ map { [ { sqlt_datatype => 'int', dbic_colname => 'tracks.position' } => $_ ] } (1, 2) ],
);
}

Expand Down Expand Up @@ -65,7 +65,9 @@ my $schema = DBICTest->init_schema();
)
genre
)',
[ [ 'genre.name' => 'emo' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'genre.name' }
=> 'emo' ]
],
);
}

Expand All @@ -91,7 +93,7 @@ my $schema = DBICTest->init_schema();
LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid
WHERE lyrics.lyric_id IS NULL AND (position = ? OR position = ?)
)',
[ map { [ position => $_ ] } (1, 2) ],
[ map { [ { sqlt_datatype => 'int', dbic_colname => 'position' } => $_ ] } (1, 2) ],
);
}

Expand Down
2 changes: 1 addition & 1 deletion t/lib/DBICTest/Schema/FourKeys.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __PACKAGE__->add_columns(
'hello' => { data_type => 'integer' },
'goodbye' => { data_type => 'integer' },
'sensors' => { data_type => 'character', size => 10 },
'read_count' => { data_type => 'integer', is_nullable => 1 },
'read_count' => { data_type => 'int', is_nullable => 1 },
);
__PACKAGE__->set_primary_key(qw/foo bar hello goodbye/);

Expand Down
30 changes: 20 additions & 10 deletions t/prefetch/correlated.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ my $c_rs = $cdrs->search ({}, {
'+columns' => { sibling_count => $cdrs->search(
{
'siblings.artist' => { -ident => 'me.artist' },
'siblings.cdid' => { '!=' => ['-and', { -ident => 'me.cdid' }, 'bogus condition'] },
'siblings.cdid' => { '!=' => ['-and', { -ident => 'me.cdid' }, 23414] },
}, { alias => 'siblings' },
)->count_rs->as_query,
},
Expand All @@ -51,11 +51,15 @@ is_same_sql_bind(
[

# subselect
[ 'siblings.cdid' => 'bogus condition' ],
[ 'me.artist' => 2 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'siblings.cdid' }
=> 23414 ],

[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 2 ],

# outher WHERE
[ 'me.artist' => 2 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 2 ],
],
'Expected SQL on correlated realiased subquery'
);
Expand Down Expand Up @@ -85,7 +89,7 @@ $schema->storage->debugcb(undef);

# first add a lone non-as-ed select
# it should be reordered to appear at the end without throwing prefetch/bind off
$c_rs = $c_rs->search({}, { '+select' => \[ 'me.cdid + ?', [ __add => 1 ] ] });
$c_rs = $c_rs->search({}, { '+select' => \[ 'me.cdid + ?', [ \ 'inTEger' => 1 ] ] });

# now add an unbalanced select/as pair
$c_rs = $c_rs->search ({}, {
Expand Down Expand Up @@ -127,17 +131,23 @@ is_same_sql_bind(
[

# first subselect
[ 'siblings.cdid' => 'bogus condition' ],
[ 'me.artist' => 2 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'siblings.cdid' }
=> 23414 ],

[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 2 ],

# second subselect
[ 'me.artist' => 2 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 2 ],

# the addition
[ __add => 1 ],
[ { sqlt_datatype => 'inTEger' }
=> 1 ],

# outher WHERE
[ 'me.artist' => 2 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 2 ],
],
'Expected SQL on correlated realiased subquery'
);
Expand Down
3 changes: 2 additions & 1 deletion t/prefetch/count.t
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ is_same_sql_bind (
JOIN track tracks ON tracks.cd = cds.cdid
WHERE ( me.artistid = ? )
)',
[ [ 'me.artistid' => 4 ] ],
[ [ { sqlt_datatype => 'integer', dbic_colname => 'me.artistid' }
=> 4 ] ],
);


Expand Down
13 changes: 9 additions & 4 deletions t/prefetch/grouped.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ for ($cd_rs->all) {
)
me
)',
[ map { [ 'me.cd' => $_] } ($cd_rs->get_column ('cdid')->all) ],
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
=> $_ ] } ($cd_rs->get_column ('cdid')->all) ],
'count() query generated expected SQL',
);

Expand All @@ -96,7 +97,8 @@ for ($cd_rs->all) {
JOIN cd cd ON cd.cdid = me.cd
WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )
)',
[ map { [ 'me.cd' => $_] } ( ($cd_rs->get_column ('cdid')->all) x 2 ) ],
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
=> $_ ] } ( ($cd_rs->get_column ('cdid')->all) x 2 ) ],
'next() query generated expected SQL',
);

Expand Down Expand Up @@ -264,7 +266,8 @@ for ($cd_rs->all) {
)
me
)',
[ map { [ 'me.cd' => $_] } ($cd_rs->get_column ('cdid')->all) ],
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.cd' }
=> $_ ] } ($cd_rs->get_column ('cdid')->all) ],
'count() query generated expected SQL',
);
}
Expand Down Expand Up @@ -323,7 +326,9 @@ for ($cd_rs->all) {
GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
artist.artistid, artist.name, artist.rank, artist.charfield
)',
[ map { [ 'tracks.title' => 'ugabuganoexist' ] } (1 .. 2) ],
[ map { [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'tracks.title' }
=> 'ugabuganoexist' ] } (1,2)
],
);
}

Expand Down
4 changes: 3 additions & 1 deletion t/prefetch/o2m_o2m_order_by_with_limit.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ is_same_sql_bind(
WHERE ( me.rank = ? )
ORDER BY me.name ASC, me.artistid DESC, tracks.cd
)},
[ [ 'me.rank' => 13 ], [ 'me.rank' => 13 ] ],
[ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' }
=> 13 ] } (1,2)
],
'correct SQL on limited prefetch over search_related ordered by root',
);

Expand Down
9 changes: 5 additions & 4 deletions t/prefetch/standard.t
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ $rs = $schema->resultset("CD")->search(

cmp_ok( $rs->count, '==', 3, "count() ok after group_by on related column" );

$rs = $schema->resultset("Artist")->search(
{},
{ join => [qw/ cds /], group_by => [qw/ me.name /], having =>{ 'MAX(cds.cdid)'=> \'< 5' } }
);
$rs = $schema->resultset("Artist")->search({}, {
join => [qw/ cds /],
group_by => [qw/ me.name /],
having => \[ 'MAX(cds.cdid) < ?', [ \'int' => 5 ] ],
});

cmp_ok( $rs->all, '==', 2, "results ok after group_by on related column with a having" );

Expand Down
34 changes: 19 additions & 15 deletions t/prefetch/with_limit.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ my $use_prefetch = $no_prefetch->search(
}
);

# add a floating +select to make sure it does nto throw things off
# add a floating +select to make sure it does not throw things off
# we also expect it to appear in both selectors, as we can not know
# for sure which part of the query it applies to (may be order_by,
# maybe something else)
#
# we use a reference to the same array in bind vals, because
# is_deeply picks up this difference too (not sure if bug or
# feature)
my $bind_one = [ __add => 1 ];
$use_prefetch = $use_prefetch->search({}, {
'+select' => \[ 'me.artistid + ?', $bind_one ],
'+select' => \[ 'me.artistid + ?', [ \ 'inTEger' => 1 ] ],
});

my $bind_int_resolved = sub { [ { sqlt_datatype => 'inTEger' } => 1 ] };
my $bind_vc_resolved = sub { [
{ sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'tracks.title' }
=> 'blah-blah-1234568'
] };
is_same_sql_bind (
$use_prefetch->as_query,
'(
Expand Down Expand Up @@ -77,12 +81,12 @@ is_same_sql_bind (
ORDER BY name DESC, cds.artist, cds.year ASC
)',
[
$bind_one, # outer select
$bind_one, # inner select
[ 'tracks.title' => 'blah-blah-1234568' ], # inner where
$bind_one, # inner group_by
[ 'tracks.title' => 'blah-blah-1234568' ], # outer where
$bind_one, # outer group_by
$bind_int_resolved->(), # outer select
$bind_int_resolved->(), # inner select
$bind_vc_resolved->(), # inner where
$bind_int_resolved->(), # inner group_by
$bind_vc_resolved->(), # outer where
$bind_int_resolved->(), # outer group_by
],
'Expected SQL on complex limited prefetch'
);
Expand Down Expand Up @@ -184,12 +188,12 @@ is_same_sql_bind (
WHERE ( ( artist.name = ? AND me.year = ? ) )
ORDER BY tracks.cd
)',
[
[ 'artist.name' => 'foo' ],
[ 'me.year' => 2010 ],
[ 'artist.name' => 'foo' ],
[ 'me.year' => 2010 ],
],
[ map {
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'artist.name' }
=> 'foo' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.year' }
=> 2010 ],
} (1,2)],
'No grouping of non-multiplying resultsets',
);

Expand Down
3 changes: 2 additions & 1 deletion t/relationship/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ is_same_sql_bind (
ON artist_undirected_maps.id1 = me.artistid OR artist_undirected_maps.id2 = me.artistid
WHERE ( artistid = ? )
)',
[[artistid => 1]],
[[ { sqlt_datatype => 'integer', dbic_colname => 'artistid' }
=> 1 ]],
'expected join sql produced',
);

Expand Down
16 changes: 13 additions & 3 deletions t/resultset/as_query.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,31 @@ my $cdrs = $schema->resultset('CD');

$art_rs = $art_rs->search({ name => 'Billy Joel' });

my $name_resolved_bind = [
{ sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'name' }
=> 'Billy Joel'
];

{
is_same_sql_bind(
$art_rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( name = ? ))",
[ [ name => 'Billy Joel' ] ],
[ $name_resolved_bind ],
);
}

$art_rs = $art_rs->search({ rank => 2 });

my $rank_resolved_bind = [
{ sqlt_datatype => 'integer', dbic_colname => 'rank' }
=> 2
];

{
is_same_sql_bind(
$art_rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
[ [ rank => 2 ], [ name => 'Billy Joel' ] ],
[ $rank_resolved_bind, $name_resolved_bind ],
);
}

Expand All @@ -46,7 +56,7 @@ my $rscol = $art_rs->get_column( 'charfield' );
is_same_sql_bind(
$rscol->as_query,
"(SELECT me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
[ [ rank => 2 ], [ name => 'Billy Joel' ] ],
[ $rank_resolved_bind, $name_resolved_bind ],
);
}

Expand Down
3 changes: 2 additions & 1 deletion t/resultset/as_subselect_rs.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ is_same_sql_bind (
WHERE ( source = ? )
) me
)',
[ [ source => 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
'Resultset-class attributes do not seep outside of the subselect',
);

Expand Down
8 changes: 4 additions & 4 deletions t/resultset/bind_attr.t
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ TODO: {
$rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) me WHERE title LIKE ?)",
[
[ '!!dummy' => '1999' ],
[ '!!dummy' => 'Spoon%' ]
[ {} => '1999' ],
[ {} => 'Spoon%' ]
],
'got correct SQL'
);
Expand Down Expand Up @@ -100,8 +100,8 @@ TODO: {
$rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) me WHERE title LIKE ?)",
[
[ '!!dummy' => '1999' ],
[ '!!dummy' => 'Spoon%' ]
[ {} => '1999' ],
[ {} => 'Spoon%' ]
],
'got correct SQL (cookbook arbitrary SQL, in separate file)'
);
Expand Down
8 changes: 5 additions & 3 deletions t/search/related_strip_prefetch.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use DBICTest;
my $schema = DBICTest->init_schema();

my $rs = $schema->resultset('CD')->search (
{ 'tracks.id' => { '!=', 666 }},
{ 'tracks.trackid' => { '!=', 666 }},
{ join => 'artist', prefetch => 'tracks', rows => 2 }
);

Expand All @@ -26,7 +26,7 @@ is_same_sql_bind (
FROM cd me
JOIN artist artist ON artist.artistid = me.artist
LEFT JOIN track tracks ON tracks.cd = me.cdid
WHERE ( tracks.id != ? )
WHERE ( tracks.trackid != ? )
LIMIT 2
) me
JOIN artist artist ON artist.artistid = me.artist
Expand All @@ -35,7 +35,9 @@ is_same_sql_bind (
GROUP BY tags.tagid, tags.cd, tags.tag
)',

[ [ 'tracks.id' => 666 ] ],
[ [ { sqlt_datatype => 'integer', dbic_colname => 'tracks.trackid' }
=> 666 ]
],
'Prefetch spec successfully stripped on search_related'
);

Expand Down
32 changes: 17 additions & 15 deletions t/search/subquery.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ my @tests = (
attrs => { rows => 5 },
sqlbind => \[
"( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE (title = ? AND year LIKE ?) LIMIT 5)",
[ title => 'buahaha' ],
[ year => '20%' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'title' }
=> 'buahaha' ],
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'year' }
=> '20%' ],
],
},

{
rs => $cdrs,
search => {
artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
artistid => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'artistid' )->as_query },
},
sqlbind => \[
"( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE artist_id IN ( SELECT me.id FROM artist me LIMIT 1 ) )",
"( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE artistid IN ( SELECT me.artistid FROM artist me LIMIT 1 ) )",
],
},

Expand Down Expand Up @@ -62,15 +64,15 @@ my @tests = (
attrs => {
alias => 'cd2',
from => [
{ cd2 => $cdrs->search({ id => { '>' => 20 } })->as_query },
{ cd2 => $cdrs->search({ artist => { '>' => 20 } })->as_query },
],
},
sqlbind => \[
"( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE id > ?
SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE artist > ?
) cd2
)",
[ 'id', 20 ]
[ { sqlt_datatype => 'integer', dbic_colname => 'artist' } => 20 ]
],
},

Expand All @@ -96,11 +98,11 @@ my @tests = (
alias => 'cd2',
from => [
{ cd2 => $cdrs->search(
{ id => { '>' => 20 } },
{ artist => { '>' => 20 } },
{
alias => 'cd3',
from => [
{ cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
{ cd3 => $cdrs->search( { artist => { '<' => 40 } } )->as_query }
],
}, )->as_query },
],
Expand All @@ -111,11 +113,11 @@ my @tests = (
(SELECT cd3.cdid, cd3.artist, cd3.title, cd3.year, cd3.genreid, cd3.single_track
FROM
(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
FROM cd me WHERE id < ?) cd3
WHERE id > ?) cd2
FROM cd me WHERE artist < ?) cd3
WHERE artist > ?) cd2
)",
[ 'id', 40 ],
[ 'id', 20 ]
[ { sqlt_datatype => 'integer', dbic_colname => 'artist' } => 40 ],
[ { dbic_colname => 'artist' } => 20 ], # no rsrc in outer manual from - hence no resolution
],
},

Expand Down Expand Up @@ -147,8 +149,8 @@ my @tests = (
SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE title = ?
) cd2
)",
[ 'title',
'Thriller'
[ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'title' }
=> 'Thriller'
]
],
},
Expand Down
23 changes: 12 additions & 11 deletions t/sqlmaker/bind_transport.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use DBIC::SqlMakerTest;

my $schema = DBICTest->init_schema();

my $ne_bind = [ _ne => 'bar' ];
my $rs = $schema->resultset('CD')->search({ -and => [
'me.artist' => { '!=', 'foo' },
'me.artist' => { '!=', \[ '?', $ne_bind ] },
'me.artist' => { '!=', '666' },
'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
]});

# bogus sql query to make sure bind composition happens properly
Expand Down Expand Up @@ -40,14 +39,16 @@ for (1,2) {
LIMIT 1 OFFSET 2
)',
[
[ 'me.artist' => 'foo' ],
$ne_bind,
[ _add => 1 ],
[ 'me.artist' => 'foo' ],
$ne_bind,
[ _sub => 2 ],
[ _lt => 3 ],
[ _mu => 4 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 666 ],
[ { dbic_colname => '_ne' } => 'bar' ],
[ { dbic_colname => '_add' } => 1 ],
[ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' }
=> 666 ],
[ { dbic_colname => '_ne' } => 'bar' ],
[ { dbic_colname => '_sub' } => 2 ],
[ { dbic_colname => '_lt' } => 3 ],
[ { dbic_colname => '_mu' } => 4 ],
],
'Correct crazy sql',
);
Expand Down
9 changes: 6 additions & 3 deletions t/sqlmaker/limit_dialects/generic_subq.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ is_same_sql_bind(
) < 2
ORDER BY me.title
)',
[ [ 'source', 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

is_deeply (
Expand Down Expand Up @@ -78,7 +79,8 @@ is_same_sql_bind(
) BETWEEN 1 AND 3
ORDER BY "title" DESC
)',
[ [ 'source', 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

is_deeply (
Expand Down Expand Up @@ -113,7 +115,8 @@ is_same_sql_bind(
) BETWEEN 1 AND 4294967295
ORDER BY "title"
)',
[ [ 'source', 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

is_deeply (
Expand Down
6 changes: 4 additions & 2 deletions t/sqlmaker/limit_dialects/rno.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ is_same_sql_bind(
) me
WHERE rno__row__index BETWEEN 1 AND 1
)',
[ [ 'source', 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

$schema->storage->_sql_maker->quote_char ([qw/ [ ] /]);
Expand Down Expand Up @@ -68,7 +69,8 @@ is_same_sql_bind(
) [me]
WHERE [rno__row__index] BETWEEN 1 AND 1
)',
[ [ 'source', 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

{
Expand Down
16 changes: 11 additions & 5 deletions t/sqlmaker/limit_dialects/toplimit.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ for my $null_order (
) me
ORDER BY me.id DESC
)',
[ [ source => 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);
}

Expand Down Expand Up @@ -141,7 +142,8 @@ for my $ord_set (
) me
ORDER BY $ord_set->{order_req}
)",
[ [ source => 'Library' ] ],
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);
}

Expand Down Expand Up @@ -171,7 +173,10 @@ is_same_sql_bind (
WHERE ( source = ? )
ORDER BY title
)',
[ [ source => 'Library' ], [ source => 'Library' ] ],
[ map { [
{ sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ]
} (1,2) ],
);

# test deprecated column mixing over join boundaries
Expand All @@ -190,8 +195,9 @@ is_same_sql_bind( $rs_selectas_top->search({})->as_query,
JOIN owners owner ON owner.id = me.owner
WHERE ( source = ? )
ORDER BY me.id
)',
[ [ 'source', 'Library' ] ],
)',
[ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' }
=> 'Library' ] ],
);

{
Expand Down
11 changes: 7 additions & 4 deletions t/sqlmaker/order_by_bindtransport.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ sub test_order {
ORDER BY $args->{order_req}
)",
[
[qw(foo bar)],
[qw(read_count 5)],
[qw(read_count 8)],
[ { sqlt_datatype => 'integer', dbic_colname => 'foo' }
=> 'bar' ],
[ { sqlt_datatype => 'int', dbic_colname => 'read_count' }
=> 5 ],
[ { sqlt_datatype => 'int', dbic_colname => 'read_count' }
=> 8 ],
$args->{bind}
? @{ $args->{bind} }
? map { [ { dbic_colname => $_->[0] } => $_->[1] ] } @{ $args->{bind} }
: ()
],
) || diag Dumper $args->{order_by};
Expand Down
49 changes: 49 additions & 0 deletions t/storage/source_bind_compat.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use strict;
use warnings;

use Test::More;
use Test::Warn;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;

{
package DBICTest::Legacy::Storage;
use base 'DBIx::Class::Storage::DBI::SQLite';

use Data::Dumper::Concise;

sub source_bind_attributes { return {} }
}


my $schema = DBICTest::Schema->clone;
$schema->storage_type('DBICTest::Legacy::Storage');
$schema->connection('dbi:SQLite::memory:');

$schema->storage->dbh_do( sub { $_[1]->do(<<'EOS') } );
CREATE TABLE artist (
artistid INTEGER PRIMARY KEY NOT NULL,
name varchar(100),
rank integer NOT NULL DEFAULT 13,
charfield char(10)
)
EOS

my $legacy = sub { $schema->resultset('Artist')->search({ name => 'foo'})->next };
if (DBIx::Class->VERSION >= 0.09) {
&throws_ok(
$legacy,
qr/XXXXXXXXX not sure what error to put here yet XXXXXXXXXXXXXXX/,
'deprecated use of source_bind_attributes throws',
);
}
else {
&warnings_exist (
$legacy,
qr/\QThe source_bind_attributes() override in DBICTest::Legacy::Storage relies on a deprecated codepath/,
'Warning issued during invocation of legacy storage codepath',
);
}

done_testing;