def showDepartmentDetails(): query = "select * from department" query = main.processQuery(query) cursor = mysql.connect().cursor() cursor.execute(query) data = cursor.fetchall() encodedData = [] for row in data: encodedrow = [] for item in row: if (isinstance(item, unicode)): encodedrow.append(item.encode("utf-8")) else: encodedrow.append(item) encodedData.append(encodedrow) departmentTable = "" for row in encodedData: departmentTable = departmentTable + "<tr>" for cell in row: departmentTable = departmentTable + "<td>" + str(cell) + "</td>" departmentTable = departmentTable + "</tr>" print(departmentTable) return jsonify(departmentTable)
def getQuery(): query = request.form['query'] print(query) #processQuery converts the input query to mysql query query = main.processQuery(query) #execute mysql query cursor = mysql.connect().cursor() cursor.execute(query) data = cursor.fetchall() #converting from unicode to UTF-8 encodedData = [] for row in data: encodedrow = [] for item in row: if (isinstance(item, unicode)): encodedrow.append(item.encode("utf-8")) else: encodedrow.append(item) encodedData.append(encodedrow) #creating html table for Query result htmlResult = "<span class='terminal-text-precommand'>user@snlp-sql</span><span class='terminal-text-command'>:~$ : <span class='terminal-text-command'>" + query + "</span><hr /><table class='table-bordered display-table'>" for tableRow in encodedData: htmlResult = htmlResult + "<tr>" for tablecell in tableRow: htmlResult = htmlResult + "<td>" + str(tablecell) + "</td>" htmlResult = htmlResult + "</tr>" htmlResult = htmlResult + "</table>" #converts html to jason format return jsonify(htmlResult)