Advertisement
Trescon

Prova_DB

May 9th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import sqlite3
  2. import csv
  3.  
  4. conn = sqlite3.connect('example.db')
  5. c = conn.cursor()
  6. # Lettura file FSCCDET
  7. with open("FSCCDET.csv", newline="") as filecsv:
  8.     lettore = csv.reader(filecsv,delimiter = ";")
  9.     print (" 1- *** FSCCDET.CSV ***")
  10.     dati = [(linea[2] , linea[6] , linea[7]) for linea in lettore ]#if linea[2] =="143628"]
  11.     for articolo in dati:
  12.         print(f"{articolo[:3]}")
  13.  
  14. # Crea Tabella
  15. c.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''')
  16. #c.execute('''CREATE TABLE sellout_2018 (codice_prodotto real , sellout_number real , offerta_number text , data_start text, data_stop text, quantita real, sconto real , valore_sellout , sell_out_pubblic_price real)''')
  17. c.execute('''CREATE TABLE sellout_2018 (codice_prodotto real , sellout_number real , offerta_number text , data_start real, data_stop real, quantita real, sconto real , valore_sellout , sell_out_pubblic_price real)''')
  18.  
  19. # Inserisce una riga di dati
  20. #c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
  21. #c.execute("INSERT INTO sellout_2018 VALUES (144440,253,'O20180649P','2018-04-28','2018-04-29','','',100,3299)")
  22.  
  23. purchases = [('2006-03-28','BUY','IBM',1000,45.00),
  24.              ('2006-04-05','BUY','MSFT',1000,72.00),
  25.              ('2006-04-06','SELL','IBM',500,53.00),
  26.              ]
  27. c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)',purchases)
  28.  
  29. # Salva (commit) i cambiamenti
  30. conn.commit()
  31.  
  32. for row in c.execute('SELECT * FROM stocks ORDER BY price'):
  33.     print (row)
  34.  
  35. purchases1 = [(dati[2],'',dati[4],dati[6],dati[7],'','','','')]    
  36. #purchases1 = [(122222,253,'O2018555P','2018-05-07','2018-05-31',10.20,'',150.50,2000.70)]
  37. c.executemany('INSERT INTO sellout_2018 VALUES (?,?,?,?,?,?,?,?,?)',purchases1)
  38. conn.commit()
  39.  
  40. for row in c.execute('SELECT * FROM sellout_2018 ORDER BY data_start'):
  41.     print (row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement