def end(): try: con = connector() con.closeConnection() except(ConnectorException) as e: return template('query', error=e.str) return template('query')
def query(): # get connector class(singleton) con = connector() # for return value theadList = [] rowDataList = [] # get parameter from request body sql = request.forms.get('sql') if sql is not None: # trim space repSql = " ".join(sql.split()) headerRender = True try: cur = con.getCursor() cur.execute(repSql) rows = cur.fetchall() for row in rows: rowData = [] rowStr = [] colNum = 0 for t in row.cursor_description: if headerRender: theadList.append(t[0]) rowStr = row[colNum] if rowStr is None: rowStr = 'NULL' elif isinstance(rowStr, str): rowStr = rowStr.decode('shift-jis') rowData.append(rowStr) colNum = colNum + 1 headerRender = False rowDataList.append(rowData) except (con.pyodbc.Error) as e: print str(type(e)) print str(e.args).decode('shift-jis') print str(e.message) else: sql = '' return template('query',query=sql , theadList=theadList, tbodyList=rowDataList, suggestItem=get_table_name_list(con)).encode('utf-8')
def open(): con = connector() con.openConnection() return template('query')