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.)
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.
| [reply] |
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?
| [reply] |
|