Sorry I'm just really happy because I've written some sexy code to contruct SQL queries and I thought I'd share my news LOL
Snippet:
sub foo {
# Build the query.
$query = 'SELECT ' . join (',', @$cols) . ' FROM ' . $table;
# Append the WHERE clause if it exists as a hashref.
if ($where) {
ref $where eq 'HASH' or $self->error ($ERRORS->{NOTHASHREF}, $where);
$query .= ' WHERE ' . join ($bool . ' ', map { $_ . '=' . $self->{dbh}->quote($where->{$_}) } keys %$where);
}
return $query;
}
Hehe, you can try it out with something like:
print foo('Some_Table', { Col1 => 'Val1', Col2 => 'Val2' }, ['Col1', 'Col2', 'Col3'], 'AND' );
Snippet:
Code:
sub foo {
# Build the query.
$query = 'SELECT ' . join (',', @$cols) . ' FROM ' . $table;
# Append the WHERE clause if it exists as a hashref.
if ($where) {
ref $where eq 'HASH' or $self->error ($ERRORS->{NOTHASHREF}, $where);
$query .= ' WHERE ' . join ($bool . ' ', map { $_ . '=' . $self->{dbh}->quote($where->{$_}) } keys %$where);
}
return $query;
}
Hehe, you can try it out with something like:
print foo('Some_Table', { Col1 => 'Val1', Col2 => 'Val2' }, ['Col1', 'Col2', 'Col3'], 'AND' );