Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Values concatenation for SQL query

by LanX (Saint)
on Mar 10, 2015 at 12:11 UTC ( [id://1119474]=note: print w/replies, xml ) Need Help??


in reply to Values concatenation for SQL query

you most probably want to pass an array @values with 3 arguments or 3 separated $scalars, and not one concatenated string.

edit
what's wrong with...

$sth->execute( "${middle}%" , $last, $first );

?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Values concatenation for SQL query
by Anonymous Monk on Mar 10, 2015 at 12:28 UTC
    I know that works, I would like to know why it wouldn’t accepted the way I am trying to do it, and if there is a way of doing it.

      If you have three placeholders, DBI expects three values to be passed in for the three placeholders. There is no way around it.

      Maybe you want a way to extract three values out of your one concatenated string, but you haven't described your problem in a way that I can easily infer that from what you've told us so far.

      If you have the three values separated already, I recommend keeping them separate.

      > why it wouldn’t accept

      because with 3 ? exactly 3 scalar arguments are expected and you only pass one

      > if there is a way of doing it.

      As already explained you could pass an array @values which is initialized with something like @values=($a,$b,$c)

      > the way I am trying to do it

      are you probably trying to code like in Tcl where (IIRC) comma space separated strings and arrays belong to the same data type? That's not Perl, sorry.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      PS: Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1119474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found