H
Henry J.
Need to escape single quotes ( i.e., ' -> '' ) in a data file before
sending to DB as part of insert SQLs.
Example 1):
it's mine, it's yours, 12, 42, 2008/10/06 => it''s mine,
it''s yours, 12, 42, 2008/10/06
Example 2):
'it's mine', 'it's yours', 12, 42, '2008/10/06' => 'it''s
mine', 'it''s yours', 12, 42, '2008/10/06'
The tricky part is that the data file may or may not have the string
fields wrapped in single quotes. In Example 1), it is not and single
quotes around fields will be added by another script before sending to
DB, in Example 2), its fields are already enclosed in single quotes
and will be sent to DB as is.
Does anybody have handy perl one-liner or script that tackles this?
Thanks!
sending to DB as part of insert SQLs.
Example 1):
it's mine, it's yours, 12, 42, 2008/10/06 => it''s mine,
it''s yours, 12, 42, 2008/10/06
Example 2):
'it's mine', 'it's yours', 12, 42, '2008/10/06' => 'it''s
mine', 'it''s yours', 12, 42, '2008/10/06'
The tricky part is that the data file may or may not have the string
fields wrapped in single quotes. In Example 1), it is not and single
quotes around fields will be added by another script before sending to
DB, in Example 2), its fields are already enclosed in single quotes
and will be sent to DB as is.
Does anybody have handy perl one-liner or script that tackles this?
Thanks!