kimlid2810 has asked for the wisdom of the Perl Monks concerning the following question:
from what i've seen till now, it works, but i don't know if it is from some divine intervention or something else, because i am not really sure, if $val will always have the order of the values in the corresponding order of the keys in the $str. Moreover, since this is the best i can think of, and i am sure someone has come with something better, can you suggest anything else for formatting an sql insertion query for a table of 60+ columns? What i really care about is the ease of read for the code. Thank you for your time :)my %test = ( "`test`.`id`" => "NULL", "`test`.`hash`" => "MD5()", "`test`.`power`" => "HASH()", "`test`.`allegiance`" => "?", ); my $str = join(", ", map { "$_" } keys %test); my $val = join(", ", values %test); my $query = "INSERT INTO `test` ($str) VALUES ($val)";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI and mysql query formatting
by tangent (Parson) on Dec 05, 2013 at 15:17 UTC | |
by kcott (Archbishop) on Dec 06, 2013 at 11:00 UTC | |
by tangent (Parson) on Dec 06, 2013 at 11:20 UTC | |
by afoken (Chancellor) on Dec 08, 2013 at 14:37 UTC | |
by tangent (Parson) on Dec 08, 2013 at 18:38 UTC | |
|
Re: DBI and mysql query formatting
by afoken (Chancellor) on Dec 08, 2013 at 15:12 UTC |