1 package DBIx::Class::Storage::DBI::AutoCast;
6 use base qw/DBIx::Class::Storage::DBI/;
9 __PACKAGE__->mk_group_accessors('simple' => 'auto_cast' );
13 DBIx::Class::Storage::DBI::AutoCast - Storage component for RDBMS requiring explicit placeholder typing
17 $schema->storage->auto_cast(1);
21 In some combinations of RDBMS and DBD drivers (e.g. FreeTDS and Sybase)
22 statements with values bound to columns or conditions that are not strings will
23 throw implicit type conversion errors.
25 As long as a column L<data_type|DBIx::Class::ResultSource/add_columns> is
26 defined and resolves to a base RDBMS native type via
27 L<_native_data_type|DBIx::Class::Storage::DBI/_native_data_type> as
28 defined in your Storage driver, the placeholder for this column will be
31 CAST(? as $mapped_type)
33 This option can also be enabled in
34 L<connect_info|DBIx::Class::Storage::DBI/connect_info> as:
36 on_connect_call => ['set_auto_cast']
40 sub _prep_for_execute {
43 my ($sql, $bind) = $self->next::method (@_);
45 # If we're using ::NoBindVars, there are no binds by this point so this code
47 if ($self->auto_cast && @$bind) {
49 my @sql_part = split /\?/, $sql, scalar @$bind + 1;
51 my $cast_type = $self->_native_data_type($_->[0]{sqlt_datatype});
52 $new_sql .= shift(@sql_part) . ($cast_type ? "CAST(? AS $cast_type)" : '?');
54 $sql = $new_sql . shift @sql_part;
60 =head2 connect_call_set_auto_cast
64 $schema->storage->auto_cast(1);
70 on_connect_call => ['set_auto_cast']
72 in L<connect_info|DBIx::Class::Storage::DBI/connect_info>.
76 sub connect_call_set_auto_cast {
81 =head1 FURTHER QUESTIONS?
83 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
85 =head1 COPYRIGHT AND LICENSE
87 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
88 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
89 redistribute it and/or modify it under the same terms as the
90 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.