forked from pradeesi/Store_MQTT_Data_in_Database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_DB_Tables.py
45 lines (37 loc) · 1004 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
45
# ------------------------------------------
# --- 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 MySQLdb
# SQLite DB Name
DB_Name = "iot_test"
# 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 = MySQLdb.connect(DB_Name)
curs = conn.cursor()
# Create Tables
MySQLdb.complete_statement(TableSchema)
curs.executescript(TableSchema)
# Close DB
curs.close()
conn.close()