On Fri, 14 Jan 2005 18:42:41 +0000, wrote: >Hi, >Does anyone have a Perl Script (or other) to transform a MySql insert into an >update (or >vice-versa)???
Just wrote a QAD (Quick and dirty) script see below, has no error handling #!perl # sedit.pl # description : Transform a mysql insert into an update statement # zzapper [EMAIL PROTECTED] # NB does not handle any commas in strings etc $insert_str=q|(fred,joe) values ('$fred','$joe')|; $_=$insert_str; s#^\s*\(([^)]+)\)##; $set_str=$1; s#values\s+\(([^)]+)\)##; $values_str=$1; @set_array=split(/,/,$set_str); @values_array=split(/,/,$values_str); $update_str.=qq|set |; for $setv (@set_array) { $valv=$values_array[$cnt++]; $update_str.=qq|$setv=$valv,|; } $update_str=~s/,$//; print "\ninsert :: $insert_str\n"; print "\nupdate :: $update_str\n"; zzapper (vim, cygwin, wiki & zsh) -- vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]