def new_object(self, client_id, account): sql = "INSERT INTO accounts VALUES (DEFAULT,%s,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client_id, account.value)) connection.commit() record = cursor.fetchone() return Account(record[0], record[1], record[2])
def update_object(self, change): sql = "UPDATE accounts SET value=%s WHERE account_id=%s RETURNING *" cursor = connection.cursor() cursor.execute(sql, (change.value, change.account_id)) connection.commit() return ""
def new_object(self, client, null=None): sql = "INSERT INTO clients VALUES (DEFAULT,%s,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.username, client.password)) connection.commit() record = cursor.fetchone() return Client(record[0], record[1], record[2])
def update_object(self, change): sql = "UPDATE clients SET username=%s,password=%s WHERE client_id=%s RETURNING *" cursor = connection.cursor() cursor.execute(sql, (change.username, change.password, change.client_id)) connection.commit() return ""
def delete_object(self, client_id, null=None): try: ClientDAO.get_object(self, client_id) except ClientNotFound as c: raise c sql = "DELETE FROM clients WHERE client_id = %s" cursor = connection.cursor() cursor.execute(sql, [client_id]) connection.commit()
def delete_object(self, client_id, account_id): try: account = AccountDAO().get_object(client_id, account_id) except AccountNotFound as a: raise a sql = "DELETE FROM accounts WHERE client_id = %s and account_id = %s" cursor = connection.cursor() cursor.execute(sql, (client_id, account_id)) connection.commit() return ""