-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
45 lines (42 loc) · 2.06 KB
/
db.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
#import mysql.connector
#from mysql.connector import Error
#from mysql.connector import errorcode
import pymysql
#def AddDrive(Drive, Serial, GivenName):
# try:
# mydb = mysql.connector.connect(
# host="localhost",
# user="photosynk",
# passwd="password"
# )
# mydb.autocommit = false
# mycursor = mydb.cursor()
# sql = "INSERT INTO Drives (Drive, Serial, GivenName) VALUES (%s, %s, %s)"
# val = (Drive, Serial, GivenName)
# mycursor.execute(sql, val)
# mydb.commit()
# except mysql.connector.Error as error :
# print("Failed to update record to database rollback: {}".format(error))
# #reverting changes because of exception
# conn.rollback()
# finally:
# #closing database connection.
# if(conn.is_connected()):
# cursor.close()
# conn.close()
# print("connection is closed")
mydb = pymysql.connect(host="localhost", user="photosynk", passwd="password")
mycursor = mydb.cursor()
mycursor.execute("CREATE DATABASE IF NOT EXISTS photosynk")
mydb = pymysql.connect(
host="localhost",
user="photosynk",
passwd="password",
database="photosynk"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE TABLE IF NOT EXISTS Log (DateTime DATETIME, Message VARCHAR(255))")
#mycursor.execute("CREATE TABLE IF NOT EXISTS Files (DateTime DATETIME, Camera VARCHAR(255), Hash VARCHAR(255), FileName VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS Files (DateTime DATETIME, Make VARCHAR(255), Model VARCHAR(255), GPSCoords VARCHAR(255), Hash VARCHAR(255), FileName VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS Errors (DateTime DATETIME, Make VARCHAR(255), Model VARCHAR(255), GPSCoords VARCHAR(255), Hash VARCHAR(255), FileName VARCHAR(255), Error VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS Drives (DateTime DATETIME, Drive VARCHAR(255), SerialNumber VARCHAR(255), GivenName VARCHAR(255))")