Advertisement
Guest User

Untitled

a guest
May 24th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import pyhs2
  2. import time
  3. import csv
  4.  
  5. csv_out = open('data.csv', 'wb')
  6. mywriter = csv.writer(csv_out)
  7.  
  8. def generic_user():
  9. gu = 'xxxxxx'
  10. return gu
  11.  
  12. def password():
  13. pw = 'xxxxxxx'
  14. return pw
  15.  
  16.  
  17. with pyhs2.connect(host='xxxxxxxx',
  18. port=10000,
  19. authMechanism='PLAIN',
  20. user=generic_user(),
  21. password=password(),
  22. database='xxxxxxxxxx') as conn:
  23.  
  24. with conn.cursor() as cur:
  25.  
  26. q = raw_input('Enter query: ').replace('csc', 'CSC')
  27. print q
  28.  
  29. #timer start
  30. start_time = time.time()
  31.  
  32. #Execute query
  33. cur.execute(q)
  34.  
  35. col = []
  36.  
  37. for key in cur.getSchema():
  38. col.append(key['columnName'])
  39.  
  40. header = []
  41. header.append(col)
  42.  
  43. for rows in zip(header):
  44. mywriter.writerows(rows)
  45.  
  46. records = cur.fetch()
  47. # print records
  48.  
  49. for rows in zip(records):
  50. mywriter.writerows(rows)
  51.  
  52. pull_time = time.time() - start_time
  53. print pull_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement