How to put File lines into postgres query(pg)

B

beny 18241

Hi,

I have a script which parsing some xml files(works great :))

-----

File.open(file).each do |line|
if line =~ /<prf:CcppAccept>/..line =~ /<\/prf:CcppAccept>/
if line =~ /<rdf:li>(image|audio|video).*<\/rdf:li>/
line.gsub(
'<rdf:li>image/bmp', "INSERT INTO table
VALUES(\'#{dev_name}\',\'bmpinpage\',\'true\')").gsub(
'<rdf:li>audio/mp3', "INSERT INTO table
VALUES(\'#{dev_name}\',\'downloadable.audio.MP3\')").gsub(
'<rdf:li>video/mp4',"INSERT INTO table
VALUES(\'#{dev_name}\',\'downloadable.video.MP4\')").gsub(
"<\/rdf:li>", ";").each do |ss|
print ss
end
end
end
end
----

but now I wanted to put this regexped lines into postgres queries

def query1
conn =
PGconn.new({:host=>'localhost',:user=>'postgres',:dbname=>'data'})
res = conn.exec('#{ss}')
res.each do |row|
row.each do |column|
print column
end
puts
end

but its not working, please can anybody tell how to push this lines into
this postgres querries ??

Regards
beny18241
 

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,776
Messages
2,569,603
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top