def test_fetch_or_insert(self):
        connection = ConnectionHelper().get_named_connection("test")
        cursors = Cursors(connection)
        binds = {
            "rule_name": "TEST_COND",
            "table_name": "etl_sale",
            "msg": "I don't know",
            "sql_text":
            "select id from etl_sale where etl_file_id = %(ETL_FILE_ID)",
            "narrative": "huh",
            "severity": 3,
            "format_str": "id % is %s",
            # "CORRECTIVE_ACTION" : "Fix it"
        }

        id = UtConditionPersistence.fetch_or_insert(cursors, binds)
        connection.commit()

        assert (id is not None)
Пример #2
0
from pdsutil.DbUtil import ConnectionHelper

connection = ConnectionHelper().get_named_connection("it")
cursor = connection.cursor()
cursor.execute(
    "select distinct ship_to_cust_id from etl_sale order by ship_to_cust_id")
sale_ship_to_ids = cursor.fetchall()
print(sale_ship_to_ids)
cursor.execute(
    "select distinct ship_to_cust_id from etl_customer order by ship_to_cust_id"
)
cust_ship_to_ids = cursor.fetchall()
print(cust_ship_to_ids)
for sale_id_t, cust_id_t in zip(sale_ship_to_ids, cust_ship_to_ids):
    binds = {"to_id": sale_id_t[0], "cust_id": cust_id_t[0]}
    print("cust_id %s to_id %s" % (sale_id_t[0], cust_id_t[0]))
    cursor.execute(
        "update etl_customer set ship_to_cust_id = %(to_id)s where ship_to_cust_id = %(cust_id)s",
        binds)
connection.commit()