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): |     while i < len(tbl_list): | ||||||
|         one_Table_descr = [] |         one_Table_descr = [] | ||||||
|         one_Table_struct = [] |         one_Table_struct = [] | ||||||
|  |         one_Table_relation = [] | ||||||
|         tbl_descr = tbl_list[i]["tableDescription"] |         tbl_descr = tbl_list[i]["tableDescription"] | ||||||
|         tbl_name = tbl_list[i]["tableName"] |         tbl_name = tbl_list[i]["tableName"] | ||||||
|         field_list = tbl_list[i]["fieldList"][i].keys() |         field_list = tbl_list[i]["fieldList"][i].keys() | ||||||
| @@ -34,6 +35,7 @@ def createTables(tbl_list): | |||||||
|         field_names_list = [] |         field_names_list = [] | ||||||
|         struct_fields_list = [] |         struct_fields_list = [] | ||||||
|         while x < len(tbl_list[i]["fieldList"]): |         while x < len(tbl_list[i]["fieldList"]): | ||||||
|  |             #one_Table_relation = [] | ||||||
|             if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes": |             if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes": | ||||||
|                 auto_increment = " AUTO_INCREMENT, " |                 auto_increment = " AUTO_INCREMENT, " | ||||||
|             else: |             else: | ||||||
| @@ -44,9 +46,20 @@ def createTables(tbl_list): | |||||||
|                 index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")" |                 index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")" | ||||||
|             field_names_list.append(tbl_list[i]["fieldList"][x]["fDescription"]) |             field_names_list.append(tbl_list[i]["fieldList"][x]["fDescription"]) | ||||||
|             struct_fields_list.append(tbl_list[i]["fieldList"][x]["fName"]) |             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 |             x = x + 1 | ||||||
|  |             #print(one_Table_relation) | ||||||
|  |  | ||||||
|         qwery_create = qwery_create + index + ");" |         qwery_create = qwery_create + index + ");" | ||||||
|         one_Table_struct.append(struct_fields_list) |         one_Table_struct.append(struct_fields_list) | ||||||
|  |         one_Table_struct.append(one_Table_relation) | ||||||
|         one_Table_descr.append(field_names_list) |         one_Table_descr.append(field_names_list) | ||||||
|         i = i + 1 |         i = i + 1 | ||||||
|         tbl_descr_list.append(one_Table_descr) |         tbl_descr_list.append(one_Table_descr) | ||||||
| @@ -65,16 +78,28 @@ def initDBstructure(): | |||||||
| # выборка данных из заданной таблицы | # выборка данных из заданной таблицы | ||||||
| def selectData(tbl): | def selectData(tbl): | ||||||
|     global tbl_struct_list |     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 |     #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 " |     qwery = "SELECT " | ||||||
|     for item in tbl_struct_list: |     for item in tbl_struct_list: | ||||||
|         if item[0] == tbl: |         if item[0] == tbl: | ||||||
|             for field in item[1]: |             for field in item[1]: | ||||||
|                 qwery = qwery + field + "," |                 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): | def getTablesStructure(tbl): | ||||||
|   | |||||||
							
								
								
									
										74
									
								
								tables.json
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								tables.json
									
									
									
									
									
								
							| @@ -9,42 +9,48 @@ | |||||||
|           "fDescription": "Номер п.п.", |           "fDescription": "Номер п.п.", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "PRIMARY KEY", |           "index": "PRIMARY KEY", | ||||||
|           "autoIncrement": "yes" |           "autoIncrement": "yes", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "login", |           "fName": "login", | ||||||
|           "fDescription": "Логин", |           "fDescription": "Логин", | ||||||
|           "fType": "char(20)", |           "fType": "char(20)", | ||||||
|           "index": "yes", |           "index": "yes", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "password", |           "fName": "password", | ||||||
|           "fDescription": "Пароль", |           "fDescription": "Пароль", | ||||||
|           "fType": "char(20)", |           "fType": "char(20)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "last_name", |           "fName": "last_name", | ||||||
|           "fDescription": "Фамилия", |           "fDescription": "Фамилия", | ||||||
|           "fType": "char(20)", |           "fType": "char(20)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "name", |           "fName": "name", | ||||||
|           "fDescription": "Имя", |           "fDescription": "Имя", | ||||||
|           "fType": "char(20)", |           "fType": "char(20)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "middle_name", |           "fName": "middle_name", | ||||||
|           "fDescription": "Отчество", |           "fDescription": "Отчество", | ||||||
|           "fType": "char(20)", |           "fType": "char(20)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
| @@ -57,35 +63,40 @@ | |||||||
|           "fDescription": "Номер п.п.", |           "fDescription": "Номер п.п.", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "PRIMARY KEY", |           "index": "PRIMARY KEY", | ||||||
|           "autoIncrement": "yes" |           "autoIncrement": "yes", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "doc_name", |           "fName": "doc_name", | ||||||
|           "fDescription": "Наименование", |           "fDescription": "Наименование", | ||||||
|           "fType": "varchar(100)", |           "fType": "varchar(100)", | ||||||
|           "index": "yes", |           "index": "yes", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "description", |           "fName": "description", | ||||||
|           "fDescription": "Описание", |           "fDescription": "Описание", | ||||||
|           "fType": "varchar(200)", |           "fType": "varchar(200)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "users_id", |           "fName": "users_id", | ||||||
|           "fDescription": "Владелец", |           "fDescription": "Владелец", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": ["users.id", "last_name, name, middle_name"] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "parent_id", |           "fName": "parent_id", | ||||||
|           "fDescription": "Имя", |           "fDescription": "Родительский документ", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": ["docs.id", "doc_name"] | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
| @@ -98,35 +109,40 @@ | |||||||
|           "fDescription": "Номер п.п.", |           "fDescription": "Номер п.п.", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "PRIMARY KEY", |           "index": "PRIMARY KEY", | ||||||
|           "autoIncrement": "yes" |           "autoIncrement": "yes", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "region", |           "fName": "region", | ||||||
|           "fDescription": "Регион", |           "fDescription": "Регион", | ||||||
|           "fType": "varchar(100)", |           "fType": "varchar(100)", | ||||||
|           "index": "yes", |           "index": "yes", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "city", |           "fName": "city", | ||||||
|           "fDescription": "Населеннй пункт", |           "fDescription": "Населеннй пункт", | ||||||
|           "fType": "varchar(200)", |           "fType": "varchar(200)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "street", |           "fName": "street", | ||||||
|           "fDescription": "Улица", |           "fDescription": "Улица", | ||||||
|           "fType": "varchar(100)", |           "fType": "varchar(100)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "house", |           "fName": "house", | ||||||
|           "fDescription": "Дом", |           "fDescription": "Дом", | ||||||
|           "fType": "char(6)", |           "fType": "char(6)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
| @@ -139,56 +155,64 @@ | |||||||
|           "fDescription": "Номер п.п.", |           "fDescription": "Номер п.п.", | ||||||
|           "fType": "int(11)", |           "fType": "int(11)", | ||||||
|           "index": "PRIMARY KEY", |           "index": "PRIMARY KEY", | ||||||
|           "autoIncrement": "yes" |           "autoIncrement": "yes", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "int_number", |           "fName": "int_number", | ||||||
|           "fDescription": "Внутренний номер", |           "fDescription": "Внутренний номер", | ||||||
|           "fType": "varchar(11)", |           "fType": "varchar(11)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "ext_co_line", |           "fName": "ext_co_line", | ||||||
|           "fDescription": "Номер внешней линии", |           "fDescription": "Номер внешней линии", | ||||||
|           "fType": "char(2)", |           "fType": "char(2)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "dial_number", |           "fName": "dial_number", | ||||||
|           "fDescription": "Набранный номер", |           "fDescription": "Набранный номер", | ||||||
|           "fType": "varchar(30)", |           "fType": "varchar(30)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "ring", |           "fName": "ring", | ||||||
|           "fDescription": "ХЗ", |           "fDescription": "ХЗ", | ||||||
|           "fType": "varchar(5)", |           "fType": "varchar(5)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "acc_code", |           "fName": "acc_code", | ||||||
|           "fDescription": "АСС код", |           "fDescription": "АСС код", | ||||||
|           "fType": "varchar(20)", |           "fType": "varchar(20)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "call_code", |           "fName": "call_code", | ||||||
|           "fDescription": "Код звонка", |           "fDescription": "Код звонка", | ||||||
|           "fType": "char(2)", |           "fType": "char(2)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "call_direct", |           "fName": "call_direct", | ||||||
|           "fDescription": "Направление", |           "fDescription": "Направление", | ||||||
|           "fType": "varchar(45)", |           "fType": "varchar(45)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
|           "autoIncrement": "no" |           "autoIncrement": "no", | ||||||
|  |           "relation": [] | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sergey Kalinin
					Sergey Kalinin