Add relations beetwen tables
This commit is contained in:
31
dm.py
31
dm.py
@@ -20,6 +20,7 @@ def createTables(tbl_list):
|
||||
while i < len(tbl_list):
|
||||
one_Table_descr = []
|
||||
one_Table_struct = []
|
||||
one_Table_relation = []
|
||||
tbl_descr = tbl_list[i]["tableDescription"]
|
||||
tbl_name = tbl_list[i]["tableName"]
|
||||
field_list = tbl_list[i]["fieldList"][i].keys()
|
||||
@@ -34,6 +35,7 @@ def createTables(tbl_list):
|
||||
field_names_list = []
|
||||
struct_fields_list = []
|
||||
while x < len(tbl_list[i]["fieldList"]):
|
||||
#one_Table_relation = []
|
||||
if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes":
|
||||
auto_increment = " AUTO_INCREMENT, "
|
||||
else:
|
||||
@@ -44,9 +46,20 @@ def createTables(tbl_list):
|
||||
index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")"
|
||||
field_names_list.append(tbl_list[i]["fieldList"][x]["fDescription"])
|
||||
struct_fields_list.append(tbl_list[i]["fieldList"][x]["fName"])
|
||||
if tbl_list[i]["fieldList"][x]["relation"]:
|
||||
#struct_fields_list.append(tbl_list[i]["fieldList"][x]["relation"])
|
||||
#print(tbl_list[i]["fieldList"][x]["relation"])
|
||||
#one_Table_relation.append(tbl_list[i]["fieldList"][x]["fName"])
|
||||
relation_list=[tbl_list[i]["fieldList"][x]["fName"]]
|
||||
relation_list.append(tbl_list[i]["fieldList"][x]["relation"])
|
||||
|
||||
one_Table_relation.append(relation_list)
|
||||
x = x + 1
|
||||
#print(one_Table_relation)
|
||||
|
||||
qwery_create = qwery_create + index + ");"
|
||||
one_Table_struct.append(struct_fields_list)
|
||||
one_Table_struct.append(one_Table_relation)
|
||||
one_Table_descr.append(field_names_list)
|
||||
i = i + 1
|
||||
tbl_descr_list.append(one_Table_descr)
|
||||
@@ -65,16 +78,28 @@ def initDBstructure():
|
||||
# выборка данных из заданной таблицы
|
||||
def selectData(tbl):
|
||||
global tbl_struct_list
|
||||
#print(tbl_struct_list)
|
||||
#select docs.doc_name, docs.description, (select CONCAT(last_name, ' ', name, ' ', middle_name) AS user from users where id = docs.users_id) as user from docs
|
||||
qwery = "SELECT "
|
||||
for item in tbl_struct_list:
|
||||
if item[0] == tbl:
|
||||
for field in item[1]:
|
||||
qwery = qwery + field + ","
|
||||
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
||||
c.execute(qwery)
|
||||
|
||||
return c.fetchall()
|
||||
#print(item[2])
|
||||
#field = item[2][0]
|
||||
#rel = item[2][1]
|
||||
#print(field + rel)
|
||||
for rel in item[2]:
|
||||
field = rel[0]
|
||||
field_rel = rel[1][0]
|
||||
field_replace = rel[1][1]
|
||||
print(field + "->" + field_rel + "->" + field_replace)
|
||||
qwery = qwery + "(SELECT " + field_replace + ") AS " + field + ","
|
||||
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
||||
#c.execute(qwery)
|
||||
print(qwery)
|
||||
#return c.fetchall()
|
||||
|
||||
# получаем на вход имя таблицы и возвращаем список заголовков полей
|
||||
def getTablesStructure(tbl):
|
||||
|
Reference in New Issue
Block a user