final sub problem

K

Kev Jackson

I've almost finished, but there's something I don't know how to do.

with
str = "INSERT INTO PEOPLE (USER_ID, NAME) VALUES (1, 'Fred')"

str.sub!(/PEOPLE/, 'KITTENS')

the replaced word is unquoted (ie)

irb(main):001:0> str = "INSERT INTO PEOPLE (USER_ID, NAME) VALUES (1,
'Fred')"
=> "INSERT INTO PEOPLE (USER_ID, NAME) VALUES (1, 'Fred')"
irb(main):002:0> str.sub!(/PEOPLE/, 'KITTENS')
=> "INSERT INTO KITTENS (USER_ID, NAME) VALUES (1, 'Fred')"
irb(main):003:0>

But the same doesn't apply with:

str = "INSERT INTO TEST (DATE) VALUES (01/01/2000)
str.sub!(/(\d*\/\d*\/\d*)/,'TO_DATE(\'\1\', \'MM/DD/YYYY\')')

irb(main):003:0> str = "INSERT INTO TEST (DATE) VALUES (01/01/2000)
irb(main):004:0" "
=> "INSERT INTO TEST (DATE) VALUES (01/01/2000)\n"
irb(main):005:0> str.sub!(/(\d*\/\d*\/\d*)/,'TO_DATE(\'\1\',
\'MM/DD/YYYY\')')
=> "INSERT INTO TEST (DATE) VALUES (TO_DATE('01/01/2000', 'MM/DD/YYYY'))\n"
irb(main):006:0>

In irb its fine (see above), but in my script, str is actually one
element of an array

eg
data[23]=data[23].sub!(/(\d*\/\d*\/\d*)/,'TO_DATE(\'\1\', \'MM/DD/YYYY\')')

after joining the array back to get my sql statement, I find (to my
outright disgust it must be said), that the damn value is quoted:

[snip]'DDS818/017/001',0, 'TO_DATE('01/01/2000',
'MM/DD/YYYY')',3,4,16,4,1,5,3,25,1,15,[snip]

And I'm pretty certain Oracle is going to crap itself with that quoted
string.

is there a way of ensuring that when joining, certain values are not quoted?

Kev
 
K

Kev Jackson

sorry disregard last post, sub! was leaving in quotes because my regexp
didn't explicitly exclude them, excluding them solved it
wrong...
data[23].sub!(/(\d*\/\d*\/\d*)/,'TO_DATE(\'\1\', \'MM/DD/YYYY\')')
right...
data[23].sub!(/'(\d*\/\d*\/\d*)'/,'TO_DATE(\'\1\', \'MM/DD/YYYY\')')

/me needs to learn regexp/ruby regexps to stop making an arse of myself
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top