forked from pradeesi/Store_MQTT_Data_in_Database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_DB_Tables.py
44 lines (36 loc) · 988 Bytes
/
initialize_DB_Tables.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
#------------------------------------------
#--- Author: Pradeep Singh
#--- Date: 20th January 2017
#--- Version: 1.0
#--- Python Ver: 2.7
#--- Details At: https://iotbytes.wordpress.com/store-mqtt-data-from-sensors-into-sql-database/
#------------------------------------------
import sqlite3
# SQLite DB Name
DB_Name = "IoT.db"
# SQLite DB Table Schema
TableSchema="""
drop table if exists DHT22_Temperature_Data ;
create table DHT22_Temperature_Data (
id integer primary key autoincrement,
SensorID text,
Date_n_Time text,
Temperature text
);
drop table if exists DHT22_Humidity_Data ;
create table DHT22_Humidity_Data (
id integer primary key autoincrement,
SensorID text,
Date_n_Time text,
Humidity text
);
"""
#Connect or Create DB File
conn = sqlite3.connect(DB_Name)
curs = conn.cursor()
#Create Tables
sqlite3.complete_statement(TableSchema)
curs.executescript(TableSchema)
#Close DB
curs.close()
conn.close()