Added title for tables

This commit is contained in:
Sergey Kalinin
2017-03-14 17:01:30 +03:00
parent 5c26c1b898
commit dc40c35424
3 changed files with 58 additions and 44 deletions

32
dm.py
View File

@@ -2,20 +2,26 @@
import json
def createTables(tbl_list):
global tbl_descr_list
i = 0
tbl_names_list = []
tbl_descr_list = []
while i < len(tbl_list):
one_Table_descr = []
tbl_descr = tbl_list[i]["tableDescription"]
tbl_name = tbl_list[i]["tableName"]
field_list = tbl_list[i]["fieldList"][i].keys()
tbl_names_list.append(tbl_name)
tbl_names_list.append([tbl_name, tbl_descr])
one_Table_descr.append(tbl_name)
x = 0
# список всех полей таблицы
qwery_create = "CREATE TABLE " + tbl_name + " ("
qwery_select = "SELECT * FROM "
#qwery_select = "SELECT * FROM "
index = ""
field_names_list = []
while x < len(tbl_list[i]["fieldList"]):
if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes":
auto_increment = " AUTO_INCREMENT, "
@@ -23,21 +29,26 @@ def createTables(tbl_list):
auto_increment = ", "
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + " " + \
tbl_list[i]["fieldList"][x]["fType"] + auto_increment
if tbl_list[i]["fieldList"][x]["index"] == "PRIMARY KEY":
index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")"
field_names_list.append(tbl_list[i]["fieldList"][x]["fDescription"])
x = x + 1
qwery_create = qwery_create + index + ");"
print(qwery_create)
one_Table_descr.append(field_names_list)
#print(qwery_create)
i = i + 1
tbl_descr_list.append(one_Table_descr)
#print(tbl_descr_list)
return tbl_names_list
def initDBstructure():
global tbl_descr_list
table_list = open("tables.json", "r", encoding="utf-8")
data = json.load(table_list, encoding="utf-8")
tbl_list = data["tables"]
tbl_names_list = createTables(tbl_list)
return tbl_names_list
def selectData(table_name):
@@ -45,4 +56,13 @@ def selectData(table_name):
data_list = ("1","2","3","4","5")
return table_name
initDBstructure()
# получаем на вход имя таблицы и возвращаем список заголовков полей
def getTablesStructure(tbl):
global tbl_descr_list
for item in tbl_descr_list:
if item[0] == tbl:
return item[1]
#print(tbl_descr_list)
#return tbl_descr_list
#initDBstructure()