Advertisement
Guest User

write_to_database

a guest
Mar 7th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import pymysql.cursors
  2. from read_file import *
  3. import csv
  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.     query = ('INSERT INTO company (time_capacity) VALUES (%s);')
  17.     query1 = ('INSERT INTO productdb (name, unit_cost) VALUES (%s);')
  18.    
  19.     cursor.execute(query, (Max_timer))
  20.    
  21.     for i in VO:
  22.         uquery = ('INSERT INTO productdb (unit_cost) VALUES (%s);')
  23.         cursor.execute(uquery, i)
  24.        
  25.         for k in Timer_pr_enhed:
  26.             aquery = ('UPDATE productdb SET time_produce_minutes=%s WHERE unit_cost IS NOT NULL;')
  27.             cursor.execute(aquery, k)
  28.             continue
  29.    
  30. def time(object):
  31.     for k in Timer_pr_enhed:
  32.         aquery = ('UPDATE productdb SET time_produce_minutes=%s WHERE unit_cost IS NOT NULL;')
  33.         cursor.execute(aquery, k)
  34.         continue
  35.    
  36.    
  37.            
  38.    
  39.        
  40.        
  41.    
  42.    
  43. def reset_database(object):
  44.        
  45.     reset = ('SET FOREIGN_KEY_CHECKS = 0; truncate company; truncate product_data; truncate productdb; truncate productinfo; SET FOREIGN_KEY_CHECKS = 1;  commit')
  46.     cursor.execute(reset)
  47.    
  48.    
  49. sql_stuff(object)
  50. time(object)
  51. ##reset_database(object)    
  52.    
  53. cnx.commit()
  54. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement