Relations beetwen tables now its working
This commit is contained in:
parent
51b7e43f95
commit
fa3029f48e
33
dm.py
33
dm.py
|
@ -80,26 +80,39 @@ def selectData(tbl):
|
||||||
global tbl_struct_list
|
global tbl_struct_list
|
||||||
#print(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
|
#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
|
||||||
|
# если юольше 1 поля добавить CONCAT
|
||||||
qwery = "SELECT "
|
qwery = "SELECT "
|
||||||
for item in tbl_struct_list:
|
subqwery = ""
|
||||||
|
tsl = tbl_struct_list
|
||||||
|
for item in tsl:
|
||||||
if item[0] == tbl:
|
if item[0] == tbl:
|
||||||
for field in item[1]:
|
for field in item[1]:
|
||||||
qwery = qwery + field + ","
|
qwery = qwery + field + ","
|
||||||
|
|
||||||
#print(item[2])
|
|
||||||
#field = item[2][0]
|
|
||||||
#rel = item[2][1]
|
|
||||||
#print(field + rel)
|
|
||||||
for rel in item[2]:
|
for rel in item[2]:
|
||||||
field = rel[0]
|
field = rel[0]
|
||||||
field_rel = rel[1][0]
|
field_rel = rel[1][0]
|
||||||
field_replace = rel[1][1]
|
field_replace = rel[1][1]
|
||||||
print(field + "->" + field_rel + "->" + field_replace)
|
field_replace = field_replace.replace(",", ",' ',")
|
||||||
qwery = qwery + "(SELECT " + field_replace + ") AS " + field + ","
|
#print(field + "->" + field_rel + "->" + field_replace)
|
||||||
|
# определяем название таблицы для вложенного запроса
|
||||||
|
table1 = field_rel.split('.')[0]
|
||||||
|
field1 = field_rel.split('.')[1]
|
||||||
|
if table1 == tbl:
|
||||||
|
table1 = table1 + "_1"
|
||||||
|
subqwery = tbl + " AS " +table1
|
||||||
|
else:
|
||||||
|
subqwery = table1
|
||||||
|
# составляем подзапрос и подменяем им поле в запросе
|
||||||
|
subqwery = "(SELECT CONCAT(" + field_replace + ") FROM " + subqwery +" WHERE "+ table1 + "." + field1 +"="+ tbl +"."+ field +") AS " + field
|
||||||
|
#print(subqwery)
|
||||||
|
qwery = qwery.replace(field, subqwery)
|
||||||
|
|
||||||
|
#print(item[1])
|
||||||
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
||||||
#c.execute(qwery)
|
c.execute(qwery)
|
||||||
print(qwery)
|
print(qwery)
|
||||||
#return c.fetchall()
|
#tsl.clear()
|
||||||
|
return c.fetchall()
|
||||||
|
|
||||||
# получаем на вход имя таблицы и возвращаем список заголовков полей
|
# получаем на вход имя таблицы и возвращаем список заголовков полей
|
||||||
def getTablesStructure(tbl):
|
def getTablesStructure(tbl):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user