-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinish_csv_to_sqlite_data1.py
More file actions
44 lines (30 loc) · 1.07 KB
/
Copy pathfinish_csv_to_sqlite_data1.py
File metadata and controls
44 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sqlite3
import csv
'''def create_table_if_not_exist()'''
conn = sqlite3.connect('D:/2021_8_16_oborot/test.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE IF NOT EXISTS data1
(name_UL text, inn_UL int, oborot_2019 real, rashod_2019 real)''')
#commit the changes to db
conn.commit()
#close the connection
conn.close()
# Select from the temperature table
'''query_Table = "SELECT * FROM data1"
query_Results = cursor_Object.execute(query_Table)'''
# Print the Temperature records
'''for result in query_Results:
print(result)
connection_Object.close()'''
con = sqlite3.connect('D:/2021_8_16_oborot/test.db')
cur = con.cursor()
a_file = open('D:/2021_8_16_oborot/17_your_csv_file.csv', 'r', encoding='utf-8')
rows = csv.reader(a_file)
#cur.executemany("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?)", rows)
#cur.executemany("INSERT INTO data VALUES (?, ?, ?, ?)", (name_UL, inn_UL, oborot, rashod))
cur.executemany("INSERT INTO data1 VALUES (?, ?, ?, ?)", rows)
cur.execute("SELECT * FROM data1")
print(cur.fetchall())
con.commit()
con.close()