-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_database.py
150 lines (95 loc) · 3.31 KB
/
create_database.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
This module creates sqlite database
"""
import sqlite3
import random
import datetime
import time
con = sqlite3.connect('iot_wqms_data.db')
# con = sqlite3.connect(':memory:') # when db locks
cursor = con.cursor()
def create_table():
cursor.execute(
""" CREATE TABLE IF NOT EXISTS iot_wqms_table(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
Time TIMESdTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
temperature REAL,
turbidity REAL,
ph REAL,
water_level REAL) """)
print('...inside create db fxn')
# if not included, creates only DB without any table
create_table()
# def dynamic_data_entry():
# con = sqlite3.connect('aquaBase.db')
# cursor = con.cursor()
# temp = random.randrange(10,20)
# humidity = random.randrange(10, 30)
# ph = random.randint(0, 10)
# salinity = random.randint(50, 120)
# cursor.execute(""" INSERT INTO aquaBaseTable(temp, humidity, ph, salinity) VALUES (?, ?, ?, ?) """,
# (temp, humidity, ph, salinity))
# con.commit() #commit function only associated with the connection
# def read_data_from_db():
# con = sqlite3.connect('aquaBase.db')
# cursor = con.cursor()
# cursor.execute(" SELECT * FROM aquaBaseTable ")
# copy_data = cursor.fetchall()
# # for row in copy_data:
# # print(row)
# # data_lis__name__, representing the current file t = list(copy_data)
# return copy_data
# create_table()
# for i in range(5):
# dynamic_data_entry()
# time.sleep(1)
# for row in read_data_from_db():
# print(row):memory::memory::memory:memory::memory::memory::memory::
# read_data_from_db()
# data_entry()
# cursor.close()
# con.close() #stops the database and prevent memory usage
######################################################### End of Data_base #####################################
# insert = """
# INSERT INTO aquaBase(temp, humidity, ph, salinity)
# VALUES(100,200,300,400)
# """
# cursor.execute(insert)
# data_entry()
# def get_values():
# cursor.execute("SELECT * FROM aquaBase")
# return list(cursor.fetchall())
# get_values()
# print(create_table())aquaBaseTable
# print(data_entry())
# print(get_values())
# query = """
# CREATE TABLE IF NOT EXISTS aquaBase(
# id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
# Time TIMESdTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
# temp REAL,
# humidity REAL,
# ph REAL,
# salinity REAL
# )
# """
# cursor.execute(query)
# insert = """
# INSERT INTO aquaBase(temp, humidity, ph, salinity)
# VALUES(24,50,45.3,40.3)
# """
# sal = 40
# p=25
# hum=44
# temp=35
# insert3 = """INSERT INTO aquaBase(temp, humidity, ph, salinity)
# VALUES(?, ?, ?, ?)"""
# cursor.execute(insert)
# cursor.execute(insert3, (temp,hum, p, sal))
# def get_values():
# select = """
# SELECT * FROM aqua_a
# """
# cursor.execute(select)
# return list(cursor.fetchall())
# print(get_values())