-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_sql.py
More file actions
41 lines (33 loc) · 850 Bytes
/
init_sql.py
File metadata and controls
41 lines (33 loc) · 850 Bytes
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
import sqlite3
# connection object
connection_obj = sqlite3.connect('PowerAnalyzer.db')
# cursor object
cursor_obj = connection_obj.cursor()
# Drop the Power_Analyzer table if already exists.
cursor_obj.execute("DROP TABLE IF EXISTS Power_Analyzer")
# Creating table
table = """
CREATE TABLE Power_Analyzer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
location VARCHAR(255),
l1_values TEXT,
l2_values TEXT,
l3_values TEXT,
neutral_values TEXT,
hours FLOAT,
start_time TEXT
);
"""
insert= """
INSERT INTO Power_Analyzer (location, l1_values, hours) VALUES ('New York', '1.23,4.56,7.89', 5.5);
"""
cursor_obj.execute(table)
cursor_obj.execute("""
SELECT * FROM Power_Analyzer;
""")
rows = cursor_obj.fetchall()
for row in rows:
print(row)
connection_obj.commit()
# Close the connection
connection_obj.close()