diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 13f3c11..0cb16a9 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -251,6 +251,16 @@ sub ping { 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 { my ($dbh, $info_type) = @_; diff --git a/t/20_blobs.t b/t/20_blobs.t index 4e29017..ae9633a 100644 --- a/t/20_blobs.t +++ b/t/20_blobs.t @@ -66,6 +66,13 @@ SCOPE: { ok( $sth->bind_param(1, 3), '->bind_param' ); ok( $sth->bind_param(2, undef, SQL_BLOB), '->bind_param' ); 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. @@ -78,6 +85,9 @@ SCOPE: { [ 1, $blob ], [ 2, '' ], [ 3, undef ], + [ 4, $blob ], + [ 5, '' ], + [ 6, undef ], ], 'Got the blob back ok' ); ok( $sth->finish, '->finish' ); }