Commit b972daaf authored by Leo Gordon's avatar Leo Gordon
Browse files

allow JOIN to appear in the constraint and act wisely - so we do not need...

allow JOIN to appear in the constraint and act wisely - so we do not need extra complicated syntax for joining
parent 96c477f5
......@@ -131,10 +131,11 @@ sub count_all {
my $sql = "SELECT COUNT(*) FROM $table_name";
if($constraint) {
$sql .= " WHERE $constraint ";
# in case $constraint contains any kind of JOIN (regular, LEFT, RIGHT, etc) do not put WHERE in front:
$sql .= (($constraint=~/\bJOIN\b/i) ? ' ' : ' WHERE ') . $constraint;
}
# print STDOUT $sql,"\n";
# warn "SQL: $sql\n";
my $sth = $self->prepare($sql);
$sth->execute;
......@@ -154,10 +155,11 @@ sub fetch_all {
my $sql = "SELECT $columns_csv FROM $table_name";
if($constraint) {
$sql .= " WHERE $constraint ";
# in case $constraint contains any kind of JOIN (regular, LEFT, RIGHT, etc) do not put WHERE in front:
$sql .= (($constraint=~/\bJOIN\b/i) ? ' ' : ' WHERE ') . $constraint;
}
# print STDOUT $sql,"\n";
# warn "SQL: $sql\n";
my $sth = $self->prepare($sql);
$sth->execute;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment