Guest User

Untitled

a guest
May 25th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. require 'odbc'
  2.  
  3. # this is the hardest part. never found a way to instatiate the DB connection,
  4. # but I bet it goes something like.
  5.  
  6. username="sa" #sa?
  7. password="hackme123"
  8. db_connection = ODBC.connect("reporting_system", user_name, password)
  9.  
  10. #store this insert statement as a procedure.
  11. insert_transaction = db_connection.proc("insert into transaction (account_id, amount, date ) values(?, ?, ?)")
  12.  
  13. #line is the variable to be used in the loop.
  14. for each line in File.open("TRAN.001").read_lines
  15.  
  16. if !(line.include? "****ACCOUNT HEADER JUNK" or
  17. or line == "\n"
  18.  
  19. line.split! /\s+/ # regex matching any whitespace,
  20. # repeated or not, but at least once,
  21. # and splits it up into an array
  22. # with ! meanings it saves it back into line
  23.  
  24. account_id = line[2]
  25. amount = line[0] # assings variables based on location in file
  26. date = line[1]
  27.  
  28. insert_transaction.call(account_id, amount, date)
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment