NAME

DBIx::Printf - A printf-style prepared statement

SYNOPSIS

use DBIx::Printf;

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

DESCRIPTION

DBIx::Printf is a printf-style prepared statement. It adds a printf method to DBI::db package.

METHODS

printf(stmt, [values])

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

%d         - integer
%f         - floating point
%s         - string
%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(%s%%)', $name);

AUTHOR

Copyright (c) 2007 Kazuho Oku All rights reserved.

LICENSE

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

See http://www.perl.com/perl/misc/Artistic.html