Ticket #513 (fixed bug)
handle_arrays() only works once
- Created: 2011-10-19 00:34:37
- Reported by: Franz
- Assigned to: Franz
- Milestone: 2.0-alpha1
- Component: database
- Priority: high
In the database class of the current database layer, the function handle_arrays() takes care of array parameters (mainly for use in IN clauses).
However, the query only gets modified before we prepare it with PDO to be executed, possibly multiple times. The parameter array is also manipulated.
The problem arises when calling a query like that again - the query is already prepared to a fixed number of parameters (the number being that of the first call), while the new parameters are being ignored. In fact, handle_arrays() will have no effect on the query in that case and will likely wreak havoc.
I don't know whether it is legal or even possible to modify the queryString attribute of a PDOStatement object. If so, we could probably find a hack-ish way to solve this problem.
If not, I would suggest to throw an exception if we try to run a query again that had array parameters. It is a limitation, but there doesn't seem to be another way (except throwing away the prepared statement and preparing another one).
Franz 2011-10-19 00:43:33
Ah, regenerating the statement if necessary seems to work fine.
Reines 2011-10-19 14:15:21
Changing the SQL parameter for PDOStatement wont work no. I would go with simply regenerating the statement (only if required, i.e. if we have arrays).
Franz 2011-10-19 14:55:50
I have done this exactly that way in my latest refactorings (https://github.com/lie2815/database/tree/refactor).
Franz 2011-10-26 21:50:53
- Status changed from open to fixed.
I now merged my refactorings.
For the query types that support multiple runs (SELECT, INSERT etc.), this works beautifully now.