def getUserInfo(self): psw = self.LEPassword.text() user = self.LEName.text() idx, username, user_level = None, None, None query = '''SELECT tbl1.id, username, user_level, tbl2.nome FROM public.log_user as tbl1 inner join log_level as tbl2 on tbl1.user_level = tbl2.id where username like '{nome}' and user_psw='{psw}' and activo = True; '''.format(nome=user, psw=psw) toExe = QSqlQuery() bOK = toExe.exec_(query) if bOK: bOK = toExe.first() if bOK: idx = toExe.value(0) username = toExe.value(1) user_level = toExe.value(2) else: QT_msg.aviso( txt= "Username or password doesnt exist, Please try a valid one." ) else: QT_msg.aviso( txt="Please try a valid information dont try SQL Commands.") return bOK, (idx, username, user_level)
def multLineSelect(scpt): """Metodo para executar select de multilinhas""" try: quer = QSqlQuery() b_Exec = quer.exec_(scpt) if b_Exec: quer.last() fldRow = int(quer.at()) + 1 fldCol = quer.record().count() quer.first() valOut = [] for i in range(fldRow): valOut.append(None) colOut = [] for j in range(fldCol): colOut.append(quer.value(j)) valOut[i] = colOut quer.next() return b_Exec, valOut else: verbTxt = quer.lastError().text() msg.error(txt="Error ", verbTxt=verbTxt) valOut = None return b_Exec, valOut except Exception: msg.error(txt="Error ", verbTxt="Nao foi Possivel aceder a Base de Dados") valOut = None return b_Exec, valOut
def getLast(tblName=None, val="id", ordBy="id"): ''' Funcao para trazer o ultimo elemento ou data de uma Tabela na base de dados. Retorna uma tupla, com (Bool e Val) Args: tblName= Nome da tabela que vamos quere o id val = o valor ou nome ordBy= Ordernar por ( e aconselhavel usar o mesmo que o "val") ''' bOK = False scrpt = "select " + val + " from " + tblName + " order by " + ordBy + " DESC LIMIT 1" quer = QSqlQuery() bOK = quer.exec_(scrpt) if not bOK: last = -99 verbTxt = quer.lastError.text() msg.error("error " + str(verbTxt)) return (bOK, last) else: bNums = quer.first() if bNums: last = quer.value(0) else: last = 0 return (bOK, last)
def anySelectScript(scpt=None, fldNum=None): "::>> Metodo para execurar query de select que retorna uma linha" quer = QSqlQuery() b_Exec = quer.exec_(scpt) valOut = [] if b_Exec: if quer.first(): if fldNum is None: fldNum = quer.record().count() for i in range(fldNum): valOut.append(quer.value(i)) else: b_Exec = False else: verbTxt = quer.lastError().text() msg.error(txt="Error ", verbTxt=verbTxt) return b_Exec, valOut
def anySelectScript(scpt=None, fldNum=None): quer = QSqlQuery() b_Exec = quer.exec_(scpt) valOut = [] if b_Exec: quer.first() if quer.isValid(): if fldNum is None: fldNum = quer.record().count() for i in range(fldNum): valOut.append(quer.value(i)) else: b_Exec = False else: verbTxt = quer.lastError().text() msg.error(txt="Error ", verbTxt=verbTxt) return b_Exec, valOut