DBD-Pg

 view release on metacpan or  search on metacpan

quote.c  view on Meta::CPAN

    char * result;

    /* Empty string is always an error. Here for dumb compilers. */
    if (len<1)
        croak("Invalid float");

    result = (char*)string;
    *retlen = len;

    /* Allow some standard strings in */
    if (0 != strncasecmp(string, "NaN", 4)
        && 0 != strncasecmp(string, "Infinity", 9)
        && 0 != strncasecmp(string, "-Infinity", 10)) {
        while (len > 0 && *string != '\0') {
            len--;
            if (isdigit(*string)
                || '.' == *string
                || ' ' == *string
                || '+' == *string
                || '-' == *string
                || 'e' == *string

t/12placeholders.t  view on Meta::CPAN


$t='Invalid integer fails to pass through when quoting with SQL_INTEGER';
$val = -1;
eval {
    $val = $dbh->quote('123abc', SQL_INTEGER);
};
like ($@, qr{Invalid integer}, $t);
is ($val, -1, $t);

my $prefix = 'Valid float value works when quoting with SQL_FLOAT';
for my $float ('123','0.00','0.234','23.31562', '1.23e04','6.54e+02','4e-3','NaN','Infinity','-infinity') {
    $t = "$prefix (value=$float)";
    $val = -1;
    eval { $val = $dbh->quote($float, SQL_FLOAT); };
    is ($@, q{}, $t);
    is ($val, $float, $t);

    next unless $float =~ /\w/;

    my $lcfloat = lc $float;
    $t = "$prefix (value=$lcfloat)";

t/12placeholders.t  view on Meta::CPAN


    my $ucfloat = uc $float;
    $t = "$prefix (value=$ucfloat)";
    $val = -1;
    eval { $val = $dbh->quote($ucfloat, SQL_FLOAT); };
    is ($@, q{}, $t);
    is ($val, $ucfloat, $t);
}

$prefix = 'Invalid float value fails when quoting with SQL_FLOAT';
for my $float ('3abc','123abc','','NaNum','-infinitee') {
    $t = "$prefix (value=$float)";
    $val = -1;
    eval { $val = $dbh->quote($float, SQL_FLOAT); };
    like ($@, qr{Invalid float}, $t);
    is ($val, -1, $t);
}

$dbh->rollback();

## Test placeholders plus binding



( run in 0.556 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )