FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

Multiple "whereIn" statements causes problems #73

Closed stevevance closed 7 years ago

stevevance commented 7 years ago

I have two whereIn statements, and the second one causes the entire SELECT statement to fail.

My code:

$property_classes = ["2-11"];
$zoning_classes = ["RT-4"];

$select = $pdo->select(["*"])
         ->from("property_table AS p");
$select->whereIn("property_class_15", $property_classes);
$select->whereIn("zone_class", $zoning_classes);

print_r on $select outputs:

[values:protected] => Array
                (
                    [0] => RT-4
                    [1] => 2-11
                    [2] => TRUE
                )

            [table:protected] => propertytaxes_09_15_combined2 AS p
            [whereClause:protected] => Slim\PDO\Clause\WhereClause Object
                (
                    [container:protected] => Array
                        (
                            [0] =>  AND zone_class IN ( ? )
                            [1] =>  AND property_class_15 IN ( ? , ? )
                            [2] =>  AND ST_Intersects(p.geom, ST_Transform(ST_MakeEnvelope(-87.7193069458008,41.931360904903066,-87.7081596851349,41.93654878172632, 4326), 3435)) = ?
                        )

                )

Notice that property_class_15 has two ? yet it only has 1 corresponding value in the values array (2-11). If the property_class_15 has 2 corresponding values, then there will be three ?.

Why is the second whereIn statement increasing the number of placeholders by 1?

procket-org commented 7 years ago

abstract class StatementContainer

 protected function getPlaceholders()
    {
        $placeholders = $this->placeholders;

        // reset($this->placeholders);  change to
        $this->placeholders = array();

        return '( '.implode(' , ', $placeholders).' )';
    }
stevevance commented 7 years ago

Thanks @tonylevid - that change worked for me!

FaaPz commented 7 years ago

PR #75 merged. Patch release coming soon. 😉