Advertisement
Guest User

write_to_database

a guest
Mar 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import pymysql.cursors
  2. from read_file import *
  3.  
  4.  
  5.  
  6.  
  7.  
  8. cnx = pymysql.connect(user='root', password='ptekm8n8', host='127.0.0.1', database='productdb')
  9. cursor = cnx.cursor()
  10.  
  11.  
  12.  
  13.  
  14. def sql_stuff(object):
  15.  
  16.  
  17. query = ('INSERT INTO company (time_capacity) VALUES (%s);')
  18. query1 = ('INSERT INTO productdb (name, unit_cost) VALUES (%s);')
  19.  
  20. cursor.execute(query, (Max_timer))
  21.  
  22.  
  23. for i, u, k in zip(VO, Timer_pr_enhed, name):
  24.  
  25. uquery = ('INSERT INTO productdb (unit_cost, time_produce_minutes, name) VALUES (%s, %s, %s);')
  26. cursor.execute(uquery, (i, u, k))
  27.  
  28. for i, u in zip(Salgspris1, Afsat1):
  29.  
  30. uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 1);')
  31. cursor.execute(uquery, (i, u))
  32.  
  33. for i, u in zip(Salgspris2, Afsat2):
  34.  
  35. uquery = ('INSERT INTO productinfo (unit_value, amount, product_id) VALUES (%s, %s, 2);')
  36. cursor.execute(uquery, (i, u))
  37.  
  38. def udregninger(object):
  39. OMS = []
  40.  
  41. for u, i in zip(Salgspris1, Afsat1):
  42. a = u * i
  43. OMS.append(a)
  44.  
  45. def reset_database(object):
  46.  
  47. reset = ('SET FOREIGN_KEY_CHECKS = 0; truncate company; truncate product_data; truncate productdb; truncate productinfo; SET FOREIGN_KEY_CHECKS = 1; commit')
  48. cursor.execute(reset)
  49.  
  50. reset_database(object)
  51. sql_stuff(object)
  52.  
  53.  
  54.  
  55. cnx.commit()
  56. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement