NAME

DBIx::Printf::Named - A named-printf-style prepared statement

SYNOPSIS

use DBIx::Printf::Named;

use DBIx::Printf;

my $sql = $dbh->nprintf(
    'select * from t where str=%(str)s or int=%(int)d or float=%(float)f',
    {
        str => 'string',
        int => 1,
        float => 1.1e1
    }
);

DESCRIPTION

DBIx::Printf::Named is a named-printf-style prepared statement. It adds a nprintf method to DBI::db package. This module is based on DBIx::Printf by kazuho oku.

nprintf(stmt, { key1 => value1, key2 => value2 })

Builds a SQL statement from given statement with placeholders and values. Following placeholders are supported.

%(key)d         - integer
%(key)f         - floating point
%(key)s         - string
%(key)t         - do not quote, pass thru
%like(fmt) - formats and quotes a string for like expression

%like example

Below is an example of using the %%like placeholder. Since metacharacters of supplied parameters are escaped, the example would always by a prefix search.

$dbh->printf('select * from t where name like %like(%(name)s%%)', { name => $name });

AUTHOR

Masahiro Nagano <kazeburo {at} gmail.com>

SEE ALSO

DBIx::Printf

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.