Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. # SQL.Text := 'select';
  2. # SQL.Add(' bh.chart');
  3. # SQL.Add(' , lb.billing');
  4. # SQL.Add(' , hh.ins_code');
  5. # SQL.Add(' , hh.type as who_billed');
  6. # SQL.Add(' , hh.date_printed as last_billed_date');
  7. # SQL.Add(' , bh.total as balance');
  8. # SQL.Add(' , (');
  9. # SQL.Add(' select max(bd.service_date_1)');
  10. # SQL.Add(' from billing_details bd');
  11. # SQL.Add(' join transaction_classes tc on bd.transaction_code = tc.transaction_code');
  12. # SQL.Add(' where');
  13. # SQL.Add(' bd.billing = bh.billing');
  14. # SQL.Add(' and transaction_class = ''P''');
  15. # SQL.Add(' ) as last_payment_date');
  16. # SQL.Add('from last_billed lb');
  17. # SQL.Add(' join billing_headers bh on bh.billing = lb.billing');
  18. # SQL.Add(' join history_headers hh on lb.unique_id = hh.unique_id');
  19. # SQL.Add('where');
  20. # SQL.Add(' bh.total <> 0');
  21. # SQL.Add('order by hh.ins_code, last_payment_date');
  22. # OpenWithDates(qryActivities);
  23.  
  24. def parse_lines(lines)
  25. lines.each do |line|
  26. a = line.gsub("\t", " ").split("\'")
  27. sql = a.slice(1, a.size - 2)
  28. if sql.nil? or sql.empty?
  29. if a[0].downcase =~ /openwithdates/
  30. # NOP
  31. elsif a[0].downcase =~ /getdateclause/
  32. puts ' bd.entry_date BETWEEN :start_date AND :end_date'
  33. else
  34. puts "-- #{line}"
  35. end
  36. else
  37. sql.each_with_index{|e,i| sql[i] = "'" if e == ""}
  38. puts sql.join('').gsub("''", "'")
  39. end
  40. end
  41. end
  42.  
  43. def load_file(filename)
  44. File.open(filename){|f| f.read.split("\n")}
  45. end
  46.  
  47. if ARGV[0].nil?
  48. puts "usage: ruby convert.rb filename"
  49. exit
  50. end
  51.  
  52. if !File.exist?(ARGV[0])
  53. puts "file does not exist: '#{ARGV[0]}'"
  54. exit
  55. end
  56.  
  57. parse_lines load_file(ARGV[0])
Add Comment
Please, Sign In to add comment