1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest qw/connect_ok/;
use Test::More;
use if -d ".git", "Test::FailWarnings";
use DBI qw(:sql_types);
# The following is by mje++
# http://pastebin.com/RkUwwVti
my $test_value = "1234567.20";
sub my_is {
my ($dbh, $test) = @_;
my ($x) = $dbh->selectrow_array(q/select b from test where a = ?/, undef, 1);
is($x, "$test_value", $test);
$dbh->do(q/delete from test/);
}
my $dbh = connect_ok(sqlite_see_if_its_a_number => 1);
$dbh->do(q/create table test (a integer, b varchar(20))/);
$dbh->do(q/insert into test values(?,?)/, undef, 1, $test_value);
SKIP: {
local $TODO = 'failing now';
my_is($dbh, "do insert");
};
my $sth = $dbh->prepare(q/insert into test values(?,?)/);
$sth->bind_param(1, 1, SQL_INTEGER);
$sth->bind_param(2, $test_value, SQL_CHAR);
$sth->execute;
my_is($dbh, "prepared insert with provided bound data and type SQL_CHAR");
$sth = $dbh->prepare(q/insert into test values(?,?)/);
$sth->bind_param(1, 1, SQL_INTEGER);
$sth->bind_param(2, $test_value, SQL_VARCHAR);
$sth->execute;
my_is($dbh, "prepared insert with provided bound data and type SQL_VARCHAR");
$sth = $dbh->prepare(q/insert into test values(?,?)/);
$sth->bind_param(1, undef, SQL_INTEGER);
$sth->bind_param(2, undef, SQL_CHAR);
$sth->execute(1, $test_value);
my_is($dbh, "prepared insert with sticky bound data and type SQL_CHAR");
$dbh->do(q/insert into test values(?,?)/, undef, 1, $test_value);
$sth = $dbh->prepare(q/update test set b = ? where a = ?/);
$sth->bind_param(1, undef, SQL_CHAR);
$sth->bind_param(2, undef, SQL_INTEGER);
$sth->execute($test_value, 1);
my_is($dbh, "update with sticky bound type char");
$dbh->{sqlite_see_if_its_a_number} = 0;
$dbh->do(q/insert into test values(?,?)/, undef, 1, $test_value);
my_is($dbh, "do insert see_if_its_a_number = 0");
$sth = $dbh->prepare(q/insert into test values(?,?)/);
$sth->bind_param(1, 1, SQL_INTEGER);
$sth->bind_param(2, $test_value, SQL_VARCHAR);
$sth->execute;
my_is($dbh, "prepared insert with provided bound data and type SQL_VARCHAR see_if_its_a_number=0");
done_testing;
|