Change SELECT qwery
This commit is contained in:
		
							
								
								
									
										44
									
								
								dm.py
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								dm.py
									
									
									
									
									
								
							| @@ -1,27 +1,38 @@ | |||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| import json | import json, pymysql | ||||||
|  |  | ||||||
|  | conn = pymysql.connect( | ||||||
|  | db='ats', | ||||||
|  | user='dba', | ||||||
|  | passwd='AlsprofilinE', | ||||||
|  | host='kis', | ||||||
|  | charset='utf8') | ||||||
|  | c = conn.cursor() | ||||||
|  |  | ||||||
|  |  | ||||||
| def createTables(tbl_list): | def createTables(tbl_list): | ||||||
|     global tbl_descr_list |     global tbl_descr_list, tbl_struct_list | ||||||
|     i = 0 |     i = 0 | ||||||
|     tbl_names_list = [] |     tbl_names_list = [] | ||||||
|     tbl_descr_list = [] |     tbl_descr_list = [] | ||||||
|  |     tbl_struct_list = [] | ||||||
|  |  | ||||||
|     while i < len(tbl_list): |     while i < len(tbl_list): | ||||||
|         one_Table_descr = [] |         one_Table_descr = [] | ||||||
|  |         one_Table_struct = [] | ||||||
|         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() | ||||||
|         tbl_names_list.append([tbl_name, tbl_descr]) |         tbl_names_list.append([tbl_name, tbl_descr]) | ||||||
|         one_Table_descr.append(tbl_name) |         one_Table_descr.append(tbl_name) | ||||||
|  |         one_Table_struct.append(tbl_name) | ||||||
|  |  | ||||||
|         x = 0 |         x = 0 | ||||||
|         # список всех полей таблицы |         # список всех полей таблицы | ||||||
|         qwery_create = "CREATE TABLE " + tbl_name + " (" |         qwery_create = "CREATE TABLE " + tbl_name + " (" | ||||||
|         #qwery_select = "SELECT * FROM " |  | ||||||
|         index = "" |         index = "" | ||||||
|         field_names_list = [] |         field_names_list = [] | ||||||
|  |         struct_fields_list = [] | ||||||
|         while x < len(tbl_list[i]["fieldList"]): |         while x < len(tbl_list[i]["fieldList"]): | ||||||
|             if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes": |             if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes": | ||||||
|                 auto_increment = " AUTO_INCREMENT, " |                 auto_increment = " AUTO_INCREMENT, " | ||||||
| @@ -32,14 +43,14 @@ def createTables(tbl_list): | |||||||
|             if tbl_list[i]["fieldList"][x]["index"] == "PRIMARY KEY": |             if tbl_list[i]["fieldList"][x]["index"] == "PRIMARY KEY": | ||||||
|                 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"]) | ||||||
|             x = x + 1 |             x = x + 1 | ||||||
|         qwery_create = qwery_create + index + ");" |         qwery_create = qwery_create + index + ");" | ||||||
|  |         one_Table_struct.append(struct_fields_list) | ||||||
|         one_Table_descr.append(field_names_list) |         one_Table_descr.append(field_names_list) | ||||||
|         #print(qwery_create) |  | ||||||
|         i = i + 1 |         i = i + 1 | ||||||
|         tbl_descr_list.append(one_Table_descr) |         tbl_descr_list.append(one_Table_descr) | ||||||
|     #print(tbl_descr_list) |         tbl_struct_list.append(one_Table_struct) | ||||||
|     return tbl_names_list |     return tbl_names_list | ||||||
|  |  | ||||||
| def initDBstructure(): | def initDBstructure(): | ||||||
| @@ -51,10 +62,19 @@ def initDBstructure(): | |||||||
|  |  | ||||||
|     return tbl_names_list |     return tbl_names_list | ||||||
|  |  | ||||||
| def selectData(table_name): | # выборка данных из заданной таблицы | ||||||
|     # получаем данные из таблицы | def selectData(tbl): | ||||||
|     data_list = ("1","2","3","4","5") |     global tbl_struct_list | ||||||
|     return table_name |     #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() | ||||||
|  |  | ||||||
| # получаем на вход имя таблицы и возвращаем список заголовков полей | # получаем на вход имя таблицы и возвращаем список заголовков полей | ||||||
| def getTablesStructure(tbl): | def getTablesStructure(tbl): | ||||||
| @@ -62,7 +82,5 @@ def getTablesStructure(tbl): | |||||||
|     for item in tbl_descr_list: |     for item in tbl_descr_list: | ||||||
|         if item[0] == tbl: |         if item[0] == tbl: | ||||||
|             return item[1] |             return item[1] | ||||||
|     #print(tbl_descr_list) |  | ||||||
|     #return tbl_descr_list |  | ||||||
|  |  | ||||||
| #initDBstructure() | #initDBstructure() | ||||||
							
								
								
									
										24
									
								
								gui.py
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								gui.py
									
									
									
									
									
								
							| @@ -8,16 +8,16 @@ from PyQt5.QtCore import Qt | |||||||
| from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QListView, QListWidget, QTableWidget , QTableView, QTableWidgetItem | from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QListView, QListWidget, QTableWidget , QTableView, QTableWidgetItem | ||||||
| from PyQt5.QtGui import QIcon | from PyQt5.QtGui import QIcon | ||||||
| from PyQt5.QtSql import * | from PyQt5.QtSql import * | ||||||
| import pymysql | #import pymysql | ||||||
| import dm | import dm | ||||||
|  |  | ||||||
| conn = pymysql.connect( | # conn = pymysql.connect( | ||||||
| db='ats', | # db='ats', | ||||||
| user='dba', | # user='dba', | ||||||
| passwd='AlsprofilinE', | # passwd='AlsprofilinE', | ||||||
| host='kis', | # host='kis', | ||||||
| charset='utf8') | # charset='utf8') | ||||||
| c = conn.cursor() | # c = conn.cursor() | ||||||
|  |  | ||||||
| class MainWin(QMainWindow): | class MainWin(QMainWindow): | ||||||
|  |  | ||||||
| @@ -120,9 +120,7 @@ class MyTable(QTableWidget): | |||||||
|         #print(self.tbl) |         #print(self.tbl) | ||||||
|         n = 0 |         n = 0 | ||||||
|         for item in dm.getTablesStructure(self.tbl): |         for item in dm.getTablesStructure(self.tbl): | ||||||
|             print(item) |  | ||||||
|             # установка заголовков столбцов таблицы |             # установка заголовков столбцов таблицы | ||||||
|             #character = chr(ord('A') + n) |  | ||||||
|             self.setHorizontalHeaderItem(n, QTableWidgetItem(item)) |             self.setHorizontalHeaderItem(n, QTableWidgetItem(item)) | ||||||
|             n = n+1 |             n = n+1 | ||||||
|  |  | ||||||
| @@ -169,14 +167,12 @@ class WorkArea(QWidget): | |||||||
|  |  | ||||||
|         # заполняем правый список данными из выбранной таблицы |         # заполняем правый список данными из выбранной таблицы | ||||||
|         def addData(tbl_name): |         def addData(tbl_name): | ||||||
|             qwery = "SELECT * FROM " + tbl_name |  | ||||||
|             c.execute(qwery) |  | ||||||
|            # удаляем предыдущий виджет таблицы |            # удаляем предыдущий виджет таблицы | ||||||
|             item = splitter1.widget(1) |             item = splitter1.widget(1) | ||||||
|             if item is not None: |             if item is not None: | ||||||
|                 #print(item) |  | ||||||
|                 item.deleteLater() |                 item.deleteLater() | ||||||
|             data = c.fetchall() |  | ||||||
|  |             data = dm.selectData(tbl_name) | ||||||
|             # проверка на наличие записей в таблице |             # проверка на наличие записей в таблице | ||||||
|             if data: |             if data: | ||||||
|                 # количество строк |                 # количество строк | ||||||
|   | |||||||
							
								
								
									
										64
									
								
								tables.json
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								tables.json
									
									
									
									
									
								
							| @@ -74,7 +74,7 @@ | |||||||
|           "autoIncrement": "no" |           "autoIncrement": "no" | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|           "fName": "user_id", |           "fName": "users_id", | ||||||
|           "fDescription": "Владелец", |           "fDescription": "Владелец", | ||||||
|           "fType": "int(6)", |           "fType": "int(6)", | ||||||
|           "index": "no", |           "index": "no", | ||||||
| @@ -129,6 +129,68 @@ | |||||||
|           "autoIncrement": "no" |           "autoIncrement": "no" | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       "tableName": "cdr", | ||||||
|  |       "tableDescription": "Записи о звонках", | ||||||
|  |       "fieldList": [ | ||||||
|  |         { | ||||||
|  |           "fName": "id", | ||||||
|  |           "fDescription": "Номер п.п.", | ||||||
|  |           "fType": "int(11)", | ||||||
|  |           "index": "PRIMARY KEY", | ||||||
|  |           "autoIncrement": "yes" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "int_number", | ||||||
|  |           "fDescription": "Внутренний номер", | ||||||
|  |           "fType": "varchar(11)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "ext_co_line", | ||||||
|  |           "fDescription": "Номер внешней линии", | ||||||
|  |           "fType": "char(2)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "dial_number", | ||||||
|  |           "fDescription": "Набранный номер", | ||||||
|  |           "fType": "varchar(30)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "ring", | ||||||
|  |           "fDescription": "ХЗ", | ||||||
|  |           "fType": "varchar(5)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "acc_code", | ||||||
|  |           "fDescription": "АСС код", | ||||||
|  |           "fType": "varchar(20)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "call_code", | ||||||
|  |           "fDescription": "Код звонка", | ||||||
|  |           "fType": "char(2)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "fName": "call_direct", | ||||||
|  |           "fDescription": "Направление", | ||||||
|  |           "fType": "varchar(45)", | ||||||
|  |           "index": "no", | ||||||
|  |           "autoIncrement": "no" | ||||||
|  |         } | ||||||
|  |       ] | ||||||
|     } |     } | ||||||
|   ] |   ] | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user