If I understand the question correctly, it looks like you are after SQL :: Abstract . First we create an object SQL::Abstract:
use SQL::Abstract;
my $sql = SQL::Abstract->new;
Now, as an example, we will use it to insert some data into a table:
my %record = (
FirstName => 'Buffy',
LastName => 'Summers',
Address => '1630 Revello Drive',
City => 'Sunnydale',
State => 'California',
Occupation => 'Student',
Health => 'Alive',
);
my ($stmt, @bind) = $sql->insert(’staff’,\%record);
It leads to:
$stmt = "INSERT INTO staff
(FirstName, LastName, Address, City,
State, Occupation, Health)
VALUES (?, ?, ?, ?, ?, ?, ?)";
@bind = ('Buffy','Summers','1630 Revello Drive',
'Sunnydale',’California','Student','Alive');
The best part is that we can pass it directly to the DBI:
$dbh->do($stmt, undef, @bind);
, , . , :
my $table = 'People';
my %new_fields = (
Occupation => 'Slayer',
Health => 'Dead',
);
my %where = (
FirstName => 'Buffy',
LastName => 'Summers',
);
my ($stmt, @bind) = $sql->update($table, \%new_fields, \%where);
$dbh->do($stmt, undef, @bind);
:
$stmt = 'UPDATE People SET Health = ?, Occupation = ?
WHERE ( FirstName = ? AND LastName = ? )';
@bind = ('Dead', 'Slayer', 'Buffy', 'Summers');
SQL::Abstract, CPAN. Perl Training Australia Perl, .
,
: Perl Training Australia, , .