Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'odbc'
- # this is the hardest part. never found a way to instatiate the DB connection,
- # but I bet it goes something like.
- username="sa" #sa?
- password="hackme123"
- db_connection = ODBC.connect("reporting_system", user_name, password)
- #store this insert statement as a procedure.
- insert_transaction = db_connection.proc("insert into transaction (account_id, amount, date ) values(?, ?, ?)")
- #line is the variable to be used in the loop.
- for each line in File.open("TRAN.001").read_lines
- if !(line.include? "****ACCOUNT HEADER JUNK" or
- or line == "\n"
- line.split! /\s+/ # regex matching any whitespace,
- # repeated or not, but at least once,
- # and splits it up into an array
- # with ! meanings it saves it back into line
- account_id = line[2]
- amount = line[0] # assings variables based on location in file
- date = line[1]
- insert_transaction.call(account_id, amount, date)
- end
- end
Add Comment
Please, Sign In to add comment