http://www.perlmonks.org?node_id=235075

alfie has asked for the wisdom of the Perl Monks concerning the following question:

I have a real strange DBI problem. I'm using DBIx::Abstract for constructing a search function over a message board, but somehow it gives me a real strange error message:

execute called with 2 bind variables when 0 are needed

Has anyone seen this before? This is the code which I am using:

my @what = split(/\s+/, $what); shift @what if $what[0] eq ''; # skip leading empty fields my $first = 1; foreach (@what) { push (@$where, 'AND') unless $first; push (@$where, [ { subject => ['LIKE', "\%$_\%"] }, 'OR', { message => ['LIKE', "\%$_\%"] }, ]); $first = 0; } $dbx->select({ fields => 'reference, subject, name', table => 'boardmessage', where => $where, });

I can't see any mistake in here, still it gives me the above error message. In the debug I found this thing:

DBIx::Abstract::__literal_query('DBIx::Abstract=HASH(0xb92e080)', 'SEL +ECT reference, subject, name FROM boardmessage WHERE ((subject LIKE ? +) OR (message LIKE ?))', '%huhu%', '%huhu%') called at /usr/share/per +l5/DBIx/Abstract.pm line 769

This leave me even more wondering, for there are two ? in the query and two bind values, so I am really wondering where the thing is bailing out? Did I hit a strange error in the module, or am I having something wrong? Please enlighten me, I'm out of ideas here...
--
use signature; signature(" So long\nAlfie");

Replies are listed 'Best First'.
Re: strange DBI problem (bind call difference)
by l2kashe (Deacon) on Feb 13, 2003 at 21:37 UTC
    I am in the process of getting the module working on a host to test myself

    Could you place the majority of the code somewhere? Perhaps your scratchpad? The piece(s) I am most interested in is areyour methods/routines to connect, and actually query the DB.

    Like I said I'm grabbing the module to give it awhirl. So I should have somekind of answer in a bit for you, but seeing more code would be helpful.

    /* And the Creator, against his better judgement, wrote man.c */
Re: strange DBI problem (bind call difference)
by alfie (Pilgrim) on Feb 13, 2003 at 22:27 UTC

    Sorry, dudes -- the problem has been in the part that I stripped off for here for I thought it wouldn't be of too big interest. I had in the fields the following additionally to the above:

    fields => 'reference, subject, name, ' . 'DATE_FORMAT(writtendate, "%Y-%m-%d %H:%i:%s AS writtendat +e',

    and as you might see I fumbled twice in this part -- once forgotten closing quote and once forgotten closing bracket... Unfortunately the error message wasn't too well so I expected the error to be someone else.

    Thanks to everyone who tried to break his/her head upon this problem... This should tell me that trying to find the problem for only one hour and a half is not enough :-/
    --
    use signature; signature(" So long\nAlfie");