Reducing Code (again)

Discussion in 'Ruby' started by Jigar Gosar, Mar 3, 2008.

  1. Jigar Gosar

    Jigar Gosar Guest

    Following is some code that I came up with, for small db processing. I
    have a feeling that I could be further reduced to be more concise.
    Something feels off, I can't put my finger on it. Or maybe for such a
    small task its pretty decent.

    Le me know.
    thanks.


    module MSDB
    DELETE_RESPONSE_TIME_LOG_QUERY = "delete from responsetimelog"

    def copy_results suffix
    transaction do |con|
    con.do "select * into responsetimelog_#{suffix} from
    responsetimelog"
    con.do DELETE_RESPONSE_TIME_LOG_QUERY
    end
    end

    def clear_response_time_log
    transaction do |con|
    con.do DELETE_RESPONSE_TIME_LOG_QUERY
    end
    end

    private
    def transaction
    DBI.connect("...") do |con|
    yield con
    con.commit
    end
    end
    end
     
    Jigar Gosar, Mar 3, 2008
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.