Pathologically Eclectic Rubbish Lister | |
PerlMonks |
How to mock results to repeated $sth->execute() calls (DBD::Mock::Session)by tirwhan (Abbot) |
on Dec 11, 2005 at 12:43 UTC ( [id://515827]=perlquestion: print w/replies, xml ) | Need Help?? |
tirwhan has asked for the wisdom of the Perl Monks concerning the following question: Hi monks, I'm trying to write a test which mocks a database connection. The code prepares the SQL statement and then executes it several times with differing bind parameters. This is what I tried using DBD::Mock:
Running this code with the current version of DBD::Mock gives an error on the second execute because of a wrong number of bound parameters:
There's a bug report in RT regarding this problem. Trying to apply the 'fix' from the bug report gets me a little further:
But it now returns the result from the first session entry even when called with the second value. If I move the prepare call into the loop it works correctly with and without the "fix", but that's not what I want to do in my code ;-). I tried using mock_add_results instead of DBD::Mock::Session, but that didn't work either. I've looked through the DBD::Mock code for a bit, but it doesn't seem obvious to me how to add this behaviour and I'm in a bit of a rush to get this test written. Is there any way I can do this either with DBD::Mock or another module (short of setting up my own test database)? Thanks in advance. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Back to
Seekers of Perl Wisdom
|
|