=cut
-use overload
- '""' => \&from;
-
sub from { shift->name; }
1;
} @bind;
}
-sub _flatten_bind_params {
- my ($self, @bind) = @_;
-
- ### Turn @bind from something like this:
- ### ( [ "artist", 1 ], [ "cdid", 1, 3 ] )
- ### to this:
- ### ( 1, 1, 3 )
- return
- map {
- if ( defined( $_ && $_->[1] ) ) {
- @{$_}[ 1 .. $#$_ ];
- }
- else { undef; }
- } @bind;
-}
-
sub _query_start {
my ( $self, $sql, @bind ) = @_;
my $datatype = $rsrc && $rsrc->column_info($col)->{data_type};
foreach my $data (@$bound) {
- $data = ''.$data if ref $data;
+ $data = ''.$data if ref $data;
- $data = $self->_dbh->quote($data) if $self->should_quote($datatype, $data);
+ $data = $self->_dbh->quote($data)
+ if $self->should_quote_value($datatype, $data);
- $new_sql .= shift(@sql_part) . $data;
+ $new_sql .= shift(@sql_part) . $data;
}
}
$new_sql .= join '', @sql_part;
return ($new_sql, []);
}
-=head2 should_quote
+=head2 should_quote_value
This method is called by L</_prep_for_execute> for every column in
order to determine if its value should be quoted or not. The arguments
=cut
-sub should_quote { 1 }
+sub should_quote_value { 1 }
=head1 AUTHORS
}
sub insert {
- my $self = shift;
- my ($source, $to_insert) = @_;
+ my ($self, $source, $to_insert) = splice @_, 0, 3;
+
+ my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
+
+ my $updated_cols = $self->next::method($source, $to_insert, @_);
+
+ $self->_update_blobs($source, $blob_cols, $to_insert) if %$blob_cols;
+
+ return $updated_cols;
+}
+
+#sub update {
+# my ($self, $source) = splice @_, 0, 2;
+# my ($fields) = @_;
+#
+# my $blob_cols = $self->_remove_blob_cols($source, $fields);
+#
+# my @res = 1;
+#
+# if (%$fields) {
+# if (wantarray) {
+# @res = $self->next::method($source, @_);
+# } else {
+# $res[0] = $self->next::method($source, @_);
+# }
+# }
+#
+# $self->_update_blobs($source, $blob_cols, $fields) if %$blob_cols;
+#
+# return wantarray ? @res : $res[0];
+#}
+
+sub _remove_blob_cols {
+ my ($self, $source, $fields) = @_;
my %blob_cols;
- for my $col (keys %$to_insert) {
- $blob_cols{$col} = delete $to_insert->{$col}
+ for my $col (keys %$fields) {
+ $blob_cols{$col} = delete $fields->{$col}
if $self->_is_lob_type($source->column_info($col)->{data_type});
}
- my $updated_cols = $self->next::method(@_);
-
- $self->_update_blobs($source, \%blob_cols, $to_insert) if %blob_cols;
-
- return $updated_cols;
+ return \%blob_cols;
}
sub _update_blobs {
numeric => $decimal,
);
-sub should_quote {
+sub should_quote_value {
my $self = shift;
my ($type, $value) = @_;
- return $self->next::method(@_) if not defined $value;
-
- $type ||= '';
+ return $self->next::method(@_) if not defined $value or not defined $type;
if (my $key = List::Util::first { $type =~ /$_/i } keys %noquote) {
return 0 if $noquote{$key}->($value);
- } elsif (not $type) {
-# try to guess based on value
- return 0 if $number->($value) || $noquote->{money}->($value);
}
+## try to guess based on value
+# elsif (not $type) {
+# return 0 if $number->($value) || $noquote->{money}->($value);
+# }
+
return $self->next::method(@_);
}
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
-use DateTime::Format::Sybase;
my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
-plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
- unless ($dsn && $user);
-
-plan tests => (26 + 4*2)*2;
+if (not ($dsn && $user)) {
+ plan skip_all =>
+ 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
+ "\nWarning: This test drops and creates the tables " .
+ "'artist' and 'bindtype_test'";
+} else {
+ plan tests => (26 + 2)*2;
+}
my @storage_types = (
'DBI::Sybase',
$schema->connection($dsn, $user, $pass, {
AutoCommit => 1,
on_connect_call => [
- [ 'datetime_setup' ],
[ blob_setup => log_on_update => 1 ], # this is a safer option
],
});
is( $it->count, 7, 'COUNT of GROUP_BY ok' );
-# Test DateTime inflation with DATETIME
- my @dt_types = (
- ['DATETIME', '2004-08-21T14:36:48.080Z'],
- ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision
- );
-
- for my $dt_type (@dt_types) {
- my ($type, $sample_dt) = @$dt_type;
-
- eval { $schema->storage->dbh->do("DROP TABLE track") };
- $schema->storage->dbh->do(<<"SQL");
-CREATE TABLE track (
- trackid INT IDENTITY PRIMARY KEY,
- cd INT,
- position INT,
- last_updated_on $type,
-)
-SQL
- ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
-
- my $row;
- ok( $row = $schema->resultset('Track')->create({
- last_updated_on => $dt,
- cd => 1,
- }));
- ok( $row = $schema->resultset('Track')
- ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
- ->first
- );
- is( $row->updated_date, $dt, 'DateTime inflation works' );
- }
-
# mostly stole the blob stuff Nniuq wrote for t/73oracle.t
my $dbh = $schema->storage->dbh;
{
} eq $binstr{$size}, "verified inserted $size $type" );
}
}
+
+ # try a blob update
+ TODO: {
+ local $TODO = 'updating TEXT/IMAGE does not work yet';
+
+ my $new_str = $binstr{large} . 'foo';
+ eval { $rs->search({ id => $id })->update({ blob => $new_str }) };
+ ok !$@, 'updated blob successfully';
+ diag $@ if $@;
+ ok(eval {
+ $rs->search({ id=> $id }, { select => ['blob'] })->single->blob
+ } eq $new_str, "verified updated blob" );
+ diag $@ if $@;
+ }
}
# clean up our mess
END {
if (my $dbh = eval { $schema->storage->_dbh }) {
$dbh->do('DROP TABLE artist');
- $dbh->do('DROP TABLE track');
$dbh->do('DROP TABLE bindtype_test');
}
}
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
+
+if (not ($dsn && $user)) {
+ plan skip_all =>
+ 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
+ "\nWarning: This test drops and creates a table called 'track'";
+} else {
+ eval "use DateTime; use DateTime::Format::Sybase;";
+ if ($@) {
+ plan skip_all => 'needs DateTime and DateTime::Format::Sybase for testing';
+ }
+ else {
+ plan tests => (4 * 2 * 2) + 2; # (tests * dt_types * storage_types) + storage_tests
+ }
+}
+
+my @storage_types = (
+ 'DBI::Sybase',
+ 'DBI::Sybase::NoBindVars',
+);
+my $schema;
+
+for my $storage_type (@storage_types) {
+ $schema = DBICTest::Schema->clone;
+
+ unless ($storage_type eq 'DBI::Sybase') { # autodetect
+ $schema->storage_type("::$storage_type");
+ }
+ $schema->connection($dsn, $user, $pass, {
+ AutoCommit => 1,
+ on_connect_call => [ 'datetime_setup' ],
+ });
+
+ $schema->storage->ensure_connected;
+
+ isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
+
+ my @dt_types = (
+ ['DATETIME', '2004-08-21T14:36:48.080Z'],
+ ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision
+ );
+
+ for my $dt_type (@dt_types) {
+ my ($type, $sample_dt) = @$dt_type;
+
+ eval { $schema->storage->dbh->do("DROP TABLE track") };
+ $schema->storage->dbh->do(<<"SQL");
+CREATE TABLE track (
+ trackid INT IDENTITY PRIMARY KEY,
+ cd INT,
+ position INT,
+ last_updated_on $type,
+)
+SQL
+ ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
+
+ my $row;
+ ok( $row = $schema->resultset('Track')->create({
+ last_updated_on => $dt,
+ cd => 1,
+ }));
+ ok( $row = $schema->resultset('Track')
+ ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
+ ->first
+ );
+ is( $row->updated_date, $dt, 'DateTime roundtrip' );
+ }
+}
+
+# clean up our mess
+END {
+ if (my $dbh = eval { $schema->storage->_dbh }) {
+ $dbh->do('DROP TABLE track');
+ }
+}