1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

fix $dbh->quote(blob, SQL_BLOB) #51

This commit is contained in:
Kenichi Ishigaki 2019-05-25 01:33:09 +09:00
parent f9a8feccc0
commit e3bce4ab39
2 changed files with 20 additions and 0 deletions

View file

@ -251,6 +251,16 @@ sub ping {
return $dbh->FETCH('Active') ? 1 : 0; return $dbh->FETCH('Active') ? 1 : 0;
} }
sub quote {
my ($self, $value, $data_type) = @_;
return "NULL" unless defined $value;
if ($data_type and $data_type == DBI::SQL_BLOB) {
return q(X') . unpack('H*', $value) . q(');
}
$value =~ s/'/''/g;
return "'$value'";
}
sub get_info { sub get_info {
my ($dbh, $info_type) = @_; my ($dbh, $info_type) = @_;

View file

@ -66,6 +66,13 @@ SCOPE: {
ok( $sth->bind_param(1, 3), '->bind_param' ); ok( $sth->bind_param(1, 3), '->bind_param' );
ok( $sth->bind_param(2, undef, SQL_BLOB), '->bind_param' ); ok( $sth->bind_param(2, undef, SQL_BLOB), '->bind_param' );
ok( $sth->execute, '->execute' ); ok( $sth->execute, '->execute' );
ok my $quoted_blob = $dbh->quote($blob, SQL_BLOB);
ok( $dbh->do("INSERT INTO one VALUES( 4, $quoted_blob )"), 'insert quoted blob' );
ok my $quoted_empty = $dbh->quote('', SQL_BLOB);
ok( $dbh->do("INSERT INTO one VALUES( 5, $quoted_empty )"), 'insert quoted empty string' );
ok my $quoted_undef = $dbh->quote(undef, SQL_BLOB);
ok( $dbh->do("INSERT INTO one VALUES( 6, $quoted_undef )"), 'insert quoted undef' );
} }
# Now, try SELECT'ing the row out. # Now, try SELECT'ing the row out.
@ -78,6 +85,9 @@ SCOPE: {
[ 1, $blob ], [ 1, $blob ],
[ 2, '' ], [ 2, '' ],
[ 3, undef ], [ 3, undef ],
[ 4, $blob ],
[ 5, '' ],
[ 6, undef ],
], 'Got the blob back ok' ); ], 'Got the blob back ok' );
ok( $sth->finish, '->finish' ); ok( $sth->finish, '->finish' );
} }