1. Python / Говнокод #19900

    −47

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    def setTariff(id_tariff, id_town, id_base_tariff, tariff_name, min_time, min_distance, min_price, payment_by_distance, payment_by_time, priority, begin_time, end_time, is_weekend, date_begin, date_end, description, isActive):
        db = application.db.connect()
        cur = db.cursor()
        try:
            if priority <= 0:
                raise RuntimeError("Приоритет должен быть равным, либо выше 0.")
            cur.execute("UPDATE public.tariff SET id_town=(%(id_town)s) WHERE id_tariff=(%(id_tariff)s)", {"id_town" : id_town, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET id_base_tariff=(%(id_base_tariff)s) WHERE id_tariff=(%(id_tariff)s)", {"id_base_tariff" : id_base_tariff, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET tariff_name=(%(tariff_name)s) WHERE id_tariff=(%(id_tariff)s)", {"tariff_name" : tariff_name, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET min_time=(%(min_time)s) WHERE id_tariff=(%(id_tariff)s)", {"min_time" : min_time, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET min_distance=(%(min_distance)s) WHERE id_tariff=(%(id_tariff)s)", {"min_distance" : min_distance, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET min_price=(%(min_price)s) WHERE id_tariff=(%(id_tariff)s)", {"min_price" : min_price, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET payment_by_distance=(%(payment_by_distance)s) WHERE id_tariff=(%(id_tariff)s)", {"payment_by_distance" : payment_by_distance, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET payment_by_time=(%(payment_by_time)s) WHERE id_tariff=(%(id_tariff)s)", {"payment_by_time" : payment_by_time, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET priority=(%(priority)s) WHERE id_tariff=(%(id_tariff)s)", {"priority" : priority, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET begin_time=(%(begin_time)s) WHERE id_tariff=(%(id_tariff)s)", {"begin_time" : begin_time, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET end_time=(%(end_time)s) WHERE id_tariff=(%(id_tariff)s)", {"end_time" : end_time, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET is_weekend=(%(is_weekend)s) WHERE id_tariff=(%(id_tariff)s)", {"is_weekend" : is_weekend, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET date_begin=(%(date_begin)s) WHERE id_tariff=(%(id_tariff)s)", {"date_begin" : date_begin, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET date_end=(%(date_end)s) WHERE id_tariff=(%(id_tariff)s)", {"date_end" : date_end, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET description=(%(description)s) WHERE id_tariff=(%(id_tariff)s)", {"description" : description, "id_tariff" : id_tariff})
            cur.execute("UPDATE public.tariff SET isActive=(%(isActive)s) WHERE id_tariff=(%(id_tariff)s)", {"isActive" : isActive, "id_tariff" : id_tariff})
            db.commit()
            return True
        except Exception:
            db.rollback()
            raise
        finally:
            db.close()

    Запостил: heyzea1, 28 Апреля 2016

    Комментарии (4) RSS

    • def createUniverse(id_tariff, id_town, id_base_tariff, tariff_name, min_time, min_distance, min_price, payment_by_distance, payment_by_time, priority, begin_time, end_time, is_weekend, date_begin, date_end, description, isActive):
      Ответить
    • Одним запросом никак?
      Ответить
    • жестяк, дикий жестяк ....
      Ответить
      • Зато всё обёрнуто в транзакцию и нет ручной склейки запроса, в отличие от типичного кода на пхп.
        Ответить

    Добавить комментарий