Change SELECT qwery

This commit is contained in:
Sergey Kalinin
2017-03-15 15:58:26 +03:00
parent dc40c35424
commit 7eb4f66e53
3 changed files with 104 additions and 28 deletions

44
dm.py
View File

@@ -1,27 +1,38 @@
# -*- 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):
global tbl_descr_list
global tbl_descr_list, tbl_struct_list
i = 0
tbl_names_list = []
tbl_descr_list = []
tbl_struct_list = []
while i < len(tbl_list):
one_Table_descr = []
one_Table_struct = []
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_descr])
one_Table_descr.append(tbl_name)
one_Table_struct.append(tbl_name)
x = 0
# список всех полей таблицы
qwery_create = "CREATE TABLE " + tbl_name + " ("
#qwery_select = "SELECT * FROM "
index = ""
field_names_list = []
struct_fields_list = []
while x < len(tbl_list[i]["fieldList"]):
if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes":
auto_increment = " AUTO_INCREMENT, "
@@ -32,14 +43,14 @@ def createTables(tbl_list):
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"])
struct_fields_list.append(tbl_list[i]["fieldList"][x]["fName"])
x = x + 1
qwery_create = qwery_create + index + ");"
one_Table_struct.append(struct_fields_list)
one_Table_descr.append(field_names_list)
#print(qwery_create)
i = i + 1
tbl_descr_list.append(one_Table_descr)
#print(tbl_descr_list)
tbl_struct_list.append(one_Table_struct)
return tbl_names_list
def initDBstructure():
@@ -51,10 +62,19 @@ def initDBstructure():
return tbl_names_list
def selectData(table_name):
# получаем данные из таблицы
data_list = ("1","2","3","4","5")
return table_name
# выборка данных из заданной таблицы
def selectData(tbl):
global 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()
# получаем на вход имя таблицы и возвращаем список заголовков полей
def getTablesStructure(tbl):
@@ -62,7 +82,5 @@ def getTablesStructure(tbl):
for item in tbl_descr_list:
if item[0] == tbl:
return item[1]
#print(tbl_descr_list)
#return tbl_descr_list
#initDBstructure()