Exemplo n.º 1
0
def view(statement, row_id):
    try:
        connect = Connection.connection()
        cursor = connect.cursor()
        cursor.execute(statement, (row_id,))
        records = cursor.fetchall()
        return records
    except Exception as error:
        print("Selection Error: ", error)
        return None
    finally:
        # closing database connection.
        cursor.close()
        connect.close()
        print("Connection Closed!")
Exemplo n.º 2
0
def delete(statement, row_id):
    try:
        connect = Connection.connection()
        cursor = connect.cursor()
        cursor.execute(statement, (row_id, ))
        connect.commit()
        print("Deletion Successful!")
        return True
    except Exception as error:
        print("Deletion Error: ", error)
        return False
    finally:
        # closing database connection.
        cursor.close()
        connect.close()
        print("Connection Closed!")
Exemplo n.º 3
0
def update(statement, value):
    try:
        connect = Connection.connection()
        cursor = connect.cursor()
        cursor.execute(statement, value)
        connect.commit()
        print("Modification Successful!")
        return True
    except Exception as error:
        print("Modification Error: ", error)
        return False
    finally:
        # closing database connection.
        cursor.close()
        connect.close()
        print("Connection Closed!")
Exemplo n.º 4
0
def read_multiple_with_2_param(statement, row_id_1, row_id_2):
    try:
        connect = Connection.connection()
        cursor = connect.cursor()
        cursor.execute(statement, (
            row_id_1,
            row_id_2,
        ))
        records = cursor.fetchall()
        return records
    except Exception as error:
        print("Selection Error: ", error)
        return None
    finally:
        # closing database connection.
        cursor.close()
        connect.close()
        print("Connection Closed!")
Exemplo n.º 5
0
def create_multiple(statement, value):
    try:
        connect = Connection.connection()
        cursor = connect.cursor()
        data = pd.read_csv(value)
        print(data)
        df = pd.DataFrame(data,
                          columns=[
                              'PropertyUID', 'Price', 'PropertyType',
                              'YearBuilt', 'TenureType', 'Bedroom', 'Bathroom',
                              'ExtraRoom', 'Parking', 'Size', 'FloorPlan',
                              'Unit', 'Area', 'Street', 'District', 'State',
                              'Postcode', 'Township', 'Contract',
                              'ContractPeriod', 'OwnershipID'
                          ])
        print(df)
        for row in df.itertuples():
            print(row)
            cursor.execute(statement, row.PropertyUID, row.Price,
                           row.PropertyType, row.YearBuilt, row.TenureType,
                           row.Bedroom, row.Bathroom, row.ExtraRoom,
                           row.Parking, row.Size, row.FloorPlan, row.Unit,
                           row.Area, row.Street, row.District, row.State,
                           row.Postcode, row.Township, row.Contract,
                           row.ContractPeriod, row.OwnershipID)
        connect.commit()
        print("Insertion Successful!")
        return True
    except Exception as error:
        print("Insertion Error: ", error)
        return False
    finally:
        # closing database connection.
        cursor.close()
        connect.close()
        print("Connection Closed!")