This repository was archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataHandler.py
More file actions
66 lines (48 loc) · 1.34 KB
/
dataHandler.py
File metadata and controls
66 lines (48 loc) · 1.34 KB
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
import sqlite3 as sql
class dataHandler():
"""
This class is used for file management.
"""
# System db name.
DB_SYSN = "data.db"
# DB Connection.
dbc = object()
# Define if the project is new or not.
new = False
def __init__(self, path):
# Formatting path to db.
tp = path + self.DB_SYSN
# DB Connection.
self.dbc = sql.connect("%s" % tp)
self.q = self.dbc.cursor()
try:
pdata = self.q.execute("SELECT * FROM project").fetchall()
self.new = False
print("Bienvenido de nuevo, %s, iniciando su proyecto %s." % (pdata[0][0], pdata[0][1]) )
except:
self.new = True
self.createDataBase()
def createDataBase(self):
self.q.execute("CREATE TABLE project (UserName TEXT NOT NULL, ProjectName TEXT NOT NULL, cData TEXT NOT NULL, Syntax TEXT NOT NULL);")
self.dbc.commit()
def insertData(self, table, columns, data):
# Format the strings.
fc = self.formatString(columns,data)[0]
fd = self.formatString(columns,data)[1]
qs = "INSERT INTO %s (%s) Values (%s)" % (table, fc, fd)
self.q.execute(qs)
self.dbc.commit()
def formatString(self, columns, data):
cs = ""
for s in columns:
if(s == columns[len(columns)-1]):
cs +="'"+s+"'"
else:
cs +="'"+s+"',"
ds = ""
for s in data:
if(s == data[len(data)-1]):
ds +="'"+s+"'"
else:
ds +="'"+s+"',"
return cs, ds