DBD-Pg

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


 - Add non-blocking async COPY FROM support (pg_putcopydata_async, pg_putcopyend_async, pg_flush)
   (Github issue #177, pull request #176)
   [John Napiorkowski, Ed Sabol]

 - Ensure $sth->rows() returns 0 when no rows returned for updates, deletes,
     or inserts with ON CONFLICT DO NOTHING
   [Greg Sabino Mullane, reported by Yiannis]
   (Github issue #194, pull request #194)

 - Fix incorrect quoting of float string values (e.g. 'NaN')
   [Greg Sabino Mullane]

 - Fix a memory leak in the PQclosePrepared cleanup path
   [Rorsarach]
   (Github issue #187, pull request #188)

 - Fix a memory leak when bind_param called, and some around statement handles.
   [Greg Sabino Mullane]

 - Implement new string buffer system for statements and placeholders.

quote.c  view on Meta::CPAN

    New(0, new_string, original_length + 1, char);
    Copy(string_start, new_string, original_length, char);
    new_string[original_length] = '\0';
    (*new_length) = original_length;
    return new_string;
}

/*
  Quote a float aka numeric.
  We handle some string literals, e.g. "infinity"
  The server is more liberal than we are here, allowing nonsense things like '+NaN'.
  If not a special string, we allow for <space> .+- e E and 0-9 characters.
*/
char * quote_float(pTHX_ const char *string, STRLEN length, STRLEN *new_length, const int supports_estring)
{
    const char * const string_start = string;
    const STRLEN original_length = length;
    char * new_string;
    char * new_string_start;
    bool seen_digit = DBDPG_FALSE;

    PERL_UNUSED_ARG(supports_estring);

    if ((3 == length && 0 == strncasecmp(string, "NaN", 3)) ||
        (8 == length && 0 == strncasecmp(string, "Infinity", 8)) ||
        (9 == length && 0 == strncasecmp(string, "+Infinity", 9)) ||
        (9 == length && 0 == strncasecmp(string, "-Infinity", 9)) ||
        (3 == length && 0 == strncasecmp(string, "Inf", 3)) ||
        (4 == length && 0 == strncasecmp(string, "+Inf", 4)) ||
        (4 == length && 0 == strncasecmp(string, "-Inf", 4))) {
        New(0, new_string, length + 3, char);
        new_string_start = new_string;
        *new_string++ = '\'';
        Copy(string_start, new_string, length, char);

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

$val = -1;
eval {
    $val = $dbh->quote('123abc', SQL_INTEGER);
};
like ($@, qr{quote_integer: invalid input}, $t);
is ($val, -1, $t);

my $prefix = 'Valid float value works when quoting with SQL_FLOAT';
$count = 0;
$problems = 0;
for my $float ('123','0.00','0.234','23.31562', '1.23e04','6.54e+02','4e-3','NaN','Infinity','-infinity') {
    $count++;
    $t = "$prefix (value=$float)";
    $val = -1;
    eval { $val = $dbh->quote($float, SQL_FLOAT); };
    if ($@ ne q{}) {
        $problems++;
        is ($@, q{}, "$t: error");
    }
    elsif ($val ne ($float =~ /[ai]/ ? qq{'$float'} : $float)) {
        $problems++;

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

        $problems++;
        is ($@, q{}, "$t: error");
    }
    elsif ($val ne qq{'$number'}) {
        $problems++;
        is ($val, qq{'$number'}, $t);
    }
}

$prefix = 'Invalid float value fails when quoting with SQL_FLOAT';
for my $float ('3abc','123abc','','NaNum','-infinitee') {
    $count++;
    $t = "$prefix (value=$float)";
    $val = -1;
    eval { $val = $dbh->quote($float, SQL_FLOAT); };
    if ($@ !~ qr{quote_float: invalid input}) {
        $problems++;
        like ($@, qr{quote_float: invalid input}, $t);
    }
    elsif ($val != -1) {
        $problems++;



( run in 0.424 second using v1.01-cache-2.11-cpan-ff9377addf4 )