mssql's PRINT command and DBI's .execute method

R

rpardee

Hey All,

I need to move data from a text file to a mssql database, so I wrote a
script to read the text file & a sproc to handle the INSERT statement.
The sproc uses t-sql's PRINT command at the end, to give a textual
description of what all it did, like for instance "'No Recruit found
corresponding to Access Code 'X000'--not inserting anything.'"

Please find a simplified version of my script below.

My question is--is there any way to retrieve that textual description
from my ruby script? I'd love to be able to log those...

Thanks!

-Roy

# Begin simplified script

CONNECTSTRING = "dbi:ADO:" +
"provider=SQLOLEDB.1;" +
"Integrated Security=SSPI;" +
"Persist Security Info=False;" +
"Initial Catalog=MENU;" +
"Data Source=ctrhs-dbserver"


this_file =
CSV.open("//server/projects/monkeylips/todays_event_data.txt", "r",
"\t")

DBI.connect(CONNECTSTRING) do |db|
ish = db.prepare("exec InsertEvent @AccCode = ?, @EventName = ?,
@EventDateTime = ?")
this_file.each do |row|

acc_code = row[0]
event_name = row[1]
event_datetime = row[2]

rownum += 1
puts "acc_code is #{acc_code}, event_name is #{event_name},
event_datetime is #{event_datetime}" if rownum < 10
begin
ish.execute(acc_code, event_name, event_datetime)
rescue DBI::DatabaseError => e
if e.errstr.match("they would create duplicate values") then
puts "Not inserting duplicated values '#{values}'"
else
raise e
end
end # rescue block
end # this_file.each
end # DBI.connect
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top