Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: DBI UPDATE w comma in field value

by Anonymous Monk
on May 22, 2018 at 20:47 UTC ( [id://1215070]=note: print w/replies, xml ) Need Help??


in reply to DBI UPDATE w comma in field value

The join() function can be a big help in constructing SQL statements. Push the SET-parts onto one array as you push the bind-values onto the other. Then construct your SQL with something clear like:

$update = "UPDATE $table SET " . join(",", @sets) . " WHERE ...";

This will insert comma between the elements without adding an extra one on the end, and it lets you create the SQL statement itself in just one place. This will prove to be vastly easier to debug, and to modify in the future. (Notice the placement of blank spaces at the beginning/end of the string literals! Print the resulting statement to STDERR to make sure it's right.)

Replies are listed 'Best First'.
Re^2: DBI UPDATE w comma in field value
by Your Mother (Archbishop) on May 25, 2018 at 21:26 UTC

    I also have to chime in since you're getting upvotes for your vague rehashing of ideas present in the thread already.

    This will prove to be vastly easier to debug, and to modify in the future

    String munging and concatting to generate SQL is a poor practice and makes things harder to debug, modify, and test. Any robust and secure code written to make this stuff work will end up looking a lot like SQL::Abstract so that is exactly where one should go from the beginning.

Re^2: DBI UPDATE w comma in field value
by Anonymous Monk on May 25, 2018 at 17:22 UTC

    Ok, you showed how to join an array. Rocket science!
    Why don't you show exactly what pushing onto the two arrays would look like? And how the placeholders array would then be included in the sql statement?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found