def updateRow(choosenDB,tableName,rowID): message = "" dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB,tableName); tablesList = t1.getTablesNames(); dbNames = dbmanager.getDatabaseNames(); tableColNames = table1.getColNames() rowData = table1.getRowData(rowID) if request.GET.get('updateRow','').strip(): rowData = [] for colName in tableColNames: rowData.append([colName,request.GET.get("%s" %colName,'').strip()]) message = table1.updateRow(rowData,rowID) #return message if message == "Succesfull": message = "The record was updated successfully" output = template('./templates/manageData/editRow',dbNames=dbNames,choosenDB=choosenDB,tablesList=tablesList,tableName=tableName,message=message,rowData=rowData,rowID=rowID) return output;
def manageDataInsert(choosenDB,tableName): message = "Succesfull" dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB,tableName); tablesList = t1.getTablesNames(); dbNames = dbmanager.getDatabaseNames(); tableColNames = table1.getColNames() if request.GET.get('addRow','').strip(): rowData = [] for colName in tableColNames: rowData.append(request.GET.get("%s" %colName,'').strip()) message = table1.insertRow(rowData) if message == "Succesfull": redirect("../%s" %tableName) output = template('./templates/manageData/insertRow',dbNames=dbNames,choosenDB=choosenDB,tablesList=tablesList,tableName=tableName,message=message,tableColNames=tableColNames) return output;
def manageTable(choosenDB, tableName): message = "Succesfull" dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB, tableName) if request.GET.get('deleteCol', '').strip(): message = table1.deleteCol(request.GET.get('deleteCol', '').strip()) if request.GET.get('add_col_btn', '').strip(): ColName = request.GET.get('ColName', '').strip() colType = request.GET.get('colType', '').strip() isNull = request.GET.get('isNull', '').strip() isAI = request.GET.get('isAI', '').strip() defaultValue = request.GET.get('defaultValue', '').strip() message = table1.addColumn(ColName, colType, isNull, defaultValue) tablesList = t1.getTablesNames() tColsInfo = table1.getAllColsInfo() dbNames = dbmanager.getDatabaseNames() output = template('./templates/manageTable/manageTable', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, tColsInfo=tColsInfo, message=message) return output
def manageTable(choosenDB,tableName): message = "Succesfull" dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB,tableName); if request.GET.get('deleteCol','').strip(): message = table1.deleteCol(request.GET.get('deleteCol','').strip()) if request.GET.get('add_col_btn','').strip(): ColName = request.GET.get('ColName','').strip() colType = request.GET.get('colType','').strip() isNull = request.GET.get('isNull','').strip() isAI = request.GET.get('isAI','').strip() defaultValue = request.GET.get('defaultValue','').strip() message = table1.addColumn(ColName,colType,isNull,defaultValue) tablesList = t1.getTablesNames(); tColsInfo = table1.getAllColsInfo(); dbNames = dbmanager.getDatabaseNames(); output = template('./templates/manageTable/manageTable',dbNames=dbNames,choosenDB=choosenDB,tablesList=tablesList,tableName=tableName,tColsInfo=tColsInfo,message=message) return output;
def manageDataInsert(choosenDB, tableName): message = "Succesfull" dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB, tableName) tablesList = t1.getTablesNames() dbNames = dbmanager.getDatabaseNames() tableColNames = table1.getColNames() if request.GET.get('addRow', '').strip(): rowData = [] for colName in tableColNames: rowData.append(request.GET.get("%s" % colName, '').strip()) message = table1.insertRow(rowData) if message == "Succesfull": redirect("../%s" % tableName) output = template('./templates/manageData/insertRow', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, message=message, tableColNames=tableColNames) return output
def createIndexConfirm(choosenDB, tableName): dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames() tablesList = t1.getTablesNames() table1 = table(choosenDB, tableName) tableColNames = table1.getColNames() index_name = request.POST.get('IndexName', '').strip() index_tbl_name = request.POST.get('tableN', '').strip() index_col_list = request.POST.getall('col') indexManager1 = indexManager(choosenDB) message = indexManager1.createIndex(index_name, index_tbl_name, index_col_list) output = template('./templates/createIndex/createIndexConf', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, tableColNames=tableColNames, message=message) return output
def do_upload(choosenDB, tableName): dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames() tablesList = t1.getTablesNames() table1 = table(choosenDB, tableName) data = request.files.data if data and data.file: raw = data.file.read() filename = data.filename with open("./temp/importFiles/%s" % (filename), 'w') as open_file: open_file.write(raw) message = table1.importCSV("./temp/importFiles/%s" % (filename)) else: message = "You missed a field." output = template('./templates/importData/importDataUpload', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, message=message) return output
def manageData(choosenDB,tableName): message = "Succesfull" dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB,tableName); if request.GET.get('deleteCol','').strip(): rowID = int(request.GET.get('deleteCol','').strip()) table1.deleteRow(rowID) tablesList = t1.getTablesNames(); dbNames = dbmanager.getDatabaseNames(); tableColNames = table1.getColNames() pageNo = request.GET.get('pageNo','').strip() if pageNo: pageNo = int(pageNo) tableData = table1.getData((pageNo-1)*30); else: pageNo = 1 tableData = table1.getData(0); noOfPages = (table1.getNumberofPages()/30) + 1 output = template('./templates/manageData/manageData',dbNames=dbNames,choosenDB=choosenDB,tablesList=tablesList,tableName=tableName,message=message,tableColNames=tableColNames,tableData=tableData,noOfPages=noOfPages,pageNo=pageNo) return output;
def createIndexTableChosen(choosenDB,tableName): dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames(); tablesList = t1.getTablesNames(); table1 = table(choosenDB,tableName); tableColNames = table1.getColNames() output = template('./templates/createIndex/createIndexTC',dbNames=dbNames,choosenDB=choosenDB,tablesList = tablesList,tableName=tableName,tableColNames=tableColNames) return output;
def createView2(choosenDB): dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) dbNames = dbmanager.getDatabaseNames(); tablesList = t1.getTablesNames(); tableName = request.GET.get('tableN','').strip() viewName = request.GET.get('ViewName','').strip() table1 = table(choosenDB,tableName); tableColNames = ",".join(table1.getColNames()) Viewquery = "CREATE VIEW %s AS \nSELECT %s \nFROM %s" %(viewName,tableColNames,tableName) output = template('./templates/createView/createView2',dbNames=dbNames,choosenDB=choosenDB,Viewquery=Viewquery) return output;
def createIndexTableChosen(choosenDB, tableName): dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames() tablesList = t1.getTablesNames() table1 = table(choosenDB, tableName) tableColNames = table1.getColNames() output = template('./templates/createIndex/createIndexTC', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, tableColNames=tableColNames) return output
def createView2(choosenDB): dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) dbNames = dbmanager.getDatabaseNames() tablesList = t1.getTablesNames() tableName = request.GET.get('tableN', '').strip() viewName = request.GET.get('ViewName', '').strip() table1 = table(choosenDB, tableName) tableColNames = ",".join(table1.getColNames()) Viewquery = "CREATE VIEW %s AS \nSELECT %s \nFROM %s" % ( viewName, tableColNames, tableName) output = template('./templates/createView/createView2', dbNames=dbNames, choosenDB=choosenDB, Viewquery=Viewquery) return output
def createIndexConfirm(choosenDB,tableName): dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB); if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames(); tablesList = t1.getTablesNames(); table1 = table(choosenDB,tableName); tableColNames = table1.getColNames() index_name = request.POST.get('IndexName','').strip() index_tbl_name = request.POST.get('tableN','').strip() index_col_list = request.POST.getall('col') indexManager1 = indexManager(choosenDB) message = indexManager1.createIndex(index_name,index_tbl_name,index_col_list) output = template('./templates/createIndex/createIndexConf',dbNames=dbNames,choosenDB=choosenDB,tablesList = tablesList,tableName=tableName,tableColNames=tableColNames,message = message) return output;
def manageData(choosenDB, tableName): message = "Succesfull" dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB, tableName) if request.GET.get('deleteCol', '').strip(): rowID = int(request.GET.get('deleteCol', '').strip()) table1.deleteRow(rowID) tablesList = t1.getTablesNames() dbNames = dbmanager.getDatabaseNames() tableColNames = table1.getColNames() pageNo = request.GET.get('pageNo', '').strip() if pageNo: pageNo = int(pageNo) tableData = table1.getData((pageNo - 1) * 30) else: pageNo = 1 tableData = table1.getData(0) noOfPages = (table1.getNumberofPages() / 30) + 1 output = template('./templates/manageData/manageData', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, message=message, tableColNames=tableColNames, tableData=tableData, noOfPages=noOfPages, pageNo=pageNo) return output
def do_upload(choosenDB,tableName): dbmanager = databaseManager(); if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") dbNames = dbmanager.getDatabaseNames(); tablesList = t1.getTablesNames(); table1 = table(choosenDB,tableName); data = request.files.data if data and data.file: raw = data.file.read() filename = data.filename with open("./temp/importFiles/%s" %(filename),'w') as open_file: open_file.write(raw) message = table1.importCSV("./temp/importFiles/%s" %(filename)) else: message = "You missed a field." output = template('./templates/importData/importDataUpload',dbNames=dbNames,choosenDB=choosenDB,tablesList=tablesList,message = message) return output;
def updateRow(choosenDB, tableName, rowID): message = "" dbmanager = databaseManager() if not dbmanager.doesDBExists(choosenDB.replace('.db', '')): redirect("/error") t1 = database1(choosenDB) if not t1.doesTableExist(tableName): redirect("/error") table1 = table(choosenDB, tableName) tablesList = t1.getTablesNames() dbNames = dbmanager.getDatabaseNames() tableColNames = table1.getColNames() rowData = table1.getRowData(rowID) if request.GET.get('updateRow', '').strip(): rowData = [] for colName in tableColNames: rowData.append( [colName, request.GET.get("%s" % colName, '').strip()]) message = table1.updateRow(rowData, rowID) #return message if message == "Succesfull": message = "The record was updated successfully" output = template('./templates/manageData/editRow', dbNames=dbNames, choosenDB=choosenDB, tablesList=tablesList, tableName=tableName, message=message, rowData=rowData, rowID=rowID) return output
def exportDataDownload(choosenDB, tableName): table1 = table(choosenDB, tableName) table1.generateCSVFile() return static_file(tableName + ".csv", root='temp/exportFiles', download=tableName + ".csv")
def exportDataDownload(choosenDB,tableName): table1 = table(choosenDB,tableName); table1.generateCSVFile() return static_file(tableName+".csv", root='temp/exportFiles', download=tableName+".csv")