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

Discussion in 'Ruby' started by rpardee@comcast.net, Aug 26, 2005.

  1. Guest

    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
    , Aug 26, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kristian
    Replies:
    0
    Views:
    499
    Kristian
    Nov 13, 2003
  2. Raphael Bauduin

    dbi -> sqlrelay -> mssql performance

    Raphael Bauduin, Jun 27, 2003, in forum: Ruby
    Replies:
    1
    Views:
    150
    Stefan Schmiedl
    Jul 1, 2003
  3. Replies:
    1
    Views:
    171
  4. doug
    Replies:
    1
    Views:
    123
    Julia De Silva
    Jun 7, 2005
  5. Replies:
    7
    Views:
    96
    Ben Morrow
    Dec 6, 2006
Loading...

Share This Page