def Load(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'select id, Login, Password, IsAdmin, DogsOwnerID from users where id = %s' cursor.execute(query, self.id) elif self.Login != '' and self.Password != '': query = 'select id, Login, Password, IsAdmin, DogsOwnerID from users where Login = %s and Password = %s' cursor.execute(query, (self.Login, self.Password)) for row in cursor: self.id = row['id'] self.Login = row['Login'] self.Password = row['Password'] self.IsAdmin = row['IsAdmin'] self.DogsOwnerID = row['DogsOwnerID'] break except MySQLError as err: errCatch(err) return False except Exception as err: errCatch(err) return False return True
def DeleteRequest(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'delete from DogsOwner where id = %s' cursor.execute(query, self.id) except MySQLError as err: errCatch(err)
def UpdateRequeset(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'update DogsOwner set FirstName = %s, LastName = %s, ClubID = %s where id = %s' cursor.execute( query, (self.FirstName, self.LastName, self.ClubID, self.id)) sqlQuery.Commit() except MySQLError as err: errCatch(err)
def Load(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'select id, FirstName, LastName, ClubID from DogsOwner where id = %s' cursor.execute(query, self.id) for row in cursor: self.id = row['id'] self.FirstName = row['FirstName'] self.LastName = row['LastName'] self.ClubID = row['ClubID'] break except MySQLError as err: errCatch(err)
def InsertRequest(self): if self.Login == '' and self.Password == '': return False sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: print(self.Login, self.Password, self.IsAdmin, self.DogsOwnerID) query = 'insert into users(Login, Password, IsAdmin, DogsOwnerID) values (%s, %s, %s, %s)' cursor.execute( query, (self.Login, self.Password, self.IsAdmin, self.DogsOwnerID)) sqlQuery.Commit() except MySQLError as err: errCatch(err) return False return True
def InsertRequest(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: query = 'insert into DogsOwner(FirstName, LastName) values (%s, %s)' cursor.execute(query, (self.FirstName, self.LastName)) sqlQuery.Commit() query = 'select id, FirstName, LastName, ClubID from DogsOwner where FirstName = %s and LastName = %s' cursor.execute(query, (self.FirstName, self.LastName)) for row in cursor: self.id = row['id'] self.FirstName = row['FirstName'] self.LastName = row['LastName'] self.ClubID = row['ClubID'] except MySQLError as err: errCatch(err)
def DeleteRequest(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'delete from users where id = %s' cursor.execute(query, self.id) elif self.Login != '' and self.Password != '': query = 'delete from users where Login = %s and Password = %s' cursor.execute(query, (self.Login, self.Password)) except MySQLError as err: errCatch(err) return False except Exception as err: errCatch(err) return False return True
def UpdateRequeset(self): sqlQuery = SQLController() cursor = sqlQuery.getCursor() try: if self.id != 0: query = 'update users set Login = %s, Password = %s, IsAdmin = %s, DogsOwnerID = %s where id = %s' cursor.execute(query, (self.Login, self.Password, self.IsAdmin, self.DogsOwnerID, self.id)) elif self.Login != '' and self.Password != '': query = 'update users set IsAdmin = %s, DogsOwnerID = %s where Login = %s and Password = %s' cursor.execute(query, (self.IsAdmin, self.DogsOwnerID, self.Login, self.Password)) sqlQuery.Commit() except MySQLError as err: errCatch(err) return False except Exception as err: errCatch(err) return False return True
from Controllers.SQLController import SQLController from PyQt5 import QtWidgets import sys app = QtWidgets.QApplication(sys.argv) sqlquery = SQLController() sqlquery.Select()\ .Buff('id')\ .Buff('Login')\ .Buff('Password')\ .Buff('IsAdmin')\ .Buff('DogsOwnerID')\ .From().Str('users')\ .Where()\ .Str('id = 102') sqlquery.Execute() for row in sqlquery.Cursor: print(row['id'], row['Login'], row['Password'], row['IsAdmin'], row['DogsOwnerID'])