Guest User

Untitled

a guest
Apr 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "dbi"
  4. require "date"
  5.  
  6. begin
  7.  
  8. # Connect to the MySQL server
  9. dbh = DBI.connect("dbi:Mysql:tracking:sfpmysql01","root","1force1")
  10. update_statement = dbh.prepare("INSERT INTO tbl_tracking_pixel (MEMBER_ID, ESRC, ISRC, PLOC, VISITOR_ID, PAGE_ID, created_date) VALUES (?,?,?,?,?,?,?)")
  11.  
  12. if File.exist?("/mgr/tmp/pixeldata/VerifyUser.log")
  13. file = File.new("/mgr/tmp/pixeldata/VerifyUser.log", "r")
  14. file.readlines.each {|line|
  15. line_array = line.split(" ")
  16. created_date = line_array[3].to_s + '-' + '04' + '-' + line_array[2].to_s + ' ' + line_array[4].to_s + ':00'
  17. opts_array = line_array[6].split("~~")
  18. member_id = opts_array[1]
  19. esrc = opts_array[2]
  20. isrc = opts_array[3]
  21. ploc = opts_array[4]
  22. visitor_id = opts_array[5]
  23. page_id = opts_array[6]
  24.  
  25. update_statement.execute(member_id, esrc, isrc, ploc, visitor_id, page_id, created_date);
  26. }
  27.  
  28. update_statement.finish;
  29. file.close
  30. else
  31. puts "File not found!"
  32. end
  33.  
  34.  
  35. dbh.finish
  36.  
  37. puts "Ok, your work is done here Jason. Coffee?"
  38.  
  39.  
  40. # In case things go wrong, catch it and post the error.
  41. rescue DBI::DatabaseError => dberr
  42. puts "An error occured"
  43. puts "Error code: #{dberr.err}"
  44. puts "Error messages: #{dberr.errstr}"
  45.  
  46. # In case things go wrong, be sure to close the database connection.
  47. ensure
  48. # Disconnect from server
  49. dbh.disconnect if dbh
  50.  
  51. end
Add Comment
Please, Sign In to add comment