{"id":505608,"date":"2026-12-01T16:37:37","date_gmt":"2026-12-01T13:37:37","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=505608"},"modified":"2026-12-01T16:37:37","modified_gmt":"2026-12-01T13:37:37","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=505608","title":{"rendered":"\u0422\u0430\u0440\u0438\u0444 \u043f\u043e\u0434\u043e\u0440\u043e\u0436\u0430\u043b \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u0430\u0437\u0430. \u0421 \u043a\u0430\u043a\u043e\u0439 \u0441\u0443\u043c\u043c\u043e\u0439 \u0441\u0432\u0435\u0440\u044f\u0442\u044c \u043f\u043b\u0430\u0442\u0451\u0436?"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u043b \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0434\u0430\u0432\u0446\u0430 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430 199 \u20bd. \u041f\u043e\u043a\u0430 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u0430, \u0446\u0435\u043d\u0430 \u0442\u0430\u0440\u0438\u0444\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0434\u043e 249 \u20bd. \u041f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b \u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 199 \u20bd. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043d\u043e\u0432\u043e \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u0446\u0435\u043d\u0443 \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430, \u043e\u043d \u0443\u0432\u0438\u0434\u0438\u0442 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432 50 \u20bd \u0443 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0446\u0435\u043d\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u043a\u0430\u0437\u0430. \u041f\u0440\u0438 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u0438 \u0432\u0430\u043b\u044e\u0442\u0443, \u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e. \u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0440\u0438\u0444\u0430 \u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b \u0431\u0443\u0434\u0443\u0442 \u0441\u0442\u043e\u0438\u0442\u044c 249 \u20bd. \u0423 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0446\u0435\u043d\u0430 199 \u20bd.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u0430 \u0437\u0430\u043a\u0430\u0437\u0430 \u0435\u0449\u0451 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442. \u041d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u0438\u043d \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0443 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u041a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0441\u0432\u0435\u0440\u043a\u0438 \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438 \u043f\u043e\u0434\u043b\u0438\u043d\u043d\u043e\u0441\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430, \u0430 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430\u0448\u043b\u0438 \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0421\u0443\u043c\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \u0432\u0430\u043b\u044e\u0442\u044b. \u0414\u043b\u044f <code>RUB<\/code> \u044d\u0442\u043e \u043a\u043e\u043f\u0435\u0439\u043a\u0438. \u041a\u043e\u0434 \u0432\u0430\u043b\u044e\u0442\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430\u043a\u0430\u0437\u0430.<\/p>\n<pre><code class=\"python\">import sqlite3db = sqlite3.connect(\":memory:\")db.execute(\"\"\"    CREATE TABLE orders (        order_id TEXT PRIMARY KEY NOT NULL,        amount_minor INTEGER NOT NULL CHECK (amount_minor &gt; 0),        currency TEXT NOT NULL,        payment_ref TEXT UNIQUE    )\"\"\")def create_order(order_id, amount_minor, currency):    with db:        db.execute(\"\"\"            INSERT INTO orders (order_id, amount_minor, currency)            VALUES (?, ?, ?)        \"\"\", (order_id, amount_minor, currency))def confirm(order_id, payment_ref, amount_minor, currency):    if not isinstance(payment_ref, str) or not payment_ref.strip():        raise ValueError(\"\u041d\u0443\u0436\u0435\u043d \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043b\u0430\u0442\u0435\u0436\u0430\")    if type(amount_minor) is not int or amount_minor &lt;= 0:        raise ValueError(\"\u041d\u0443\u0436\u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043b\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \u0432\u0430\u043b\u044e\u0442\u044b\")    with db:        changed = db.execute(\"\"\"            UPDATE orders            SET payment_ref = ?            WHERE order_id = ? AND payment_ref IS NULL              AND amount_minor = ? AND currency = ?        \"\"\", (payment_ref, order_id, amount_minor, currency)).rowcount    return changed == 1tariff_price = 19900create_order(\"A\", tariff_price, \"RUB\")tariff_price = 24900create_order(\"B\", tariff_price, \"RUB\")print(confirm(\"A\", \"pay-1\", 24900, \"RUB\"))  # False: \u0434\u0440\u0443\u0433\u0430\u044f \u0441\u0443\u043c\u043c\u0430print(confirm(\"A\", \"pay-1\", 19900, \"USD\"))  # False: \u0434\u0440\u0443\u0433\u0430\u044f \u0432\u0430\u043b\u044e\u0442\u0430print(confirm(\"A\", \"pay-1\", 19900, \"RUB\"))  # True: \u0437\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043dprint(confirm(\"A\", \"pay-1\", 19900, \"RUB\"))  # False: \u043f\u043e\u0432\u0442\u043e\u0440 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043b \u0437\u0430\u043a\u0430\u0437print(confirm(\"B\", \"pay-2\", 24900, \"RUB\"))  # True: \u0437\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043ddb.close()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u0434 \u0432 Python 3 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c <code>sqlite3<\/code>. \u0417\u0430\u043a\u0430\u0437 <code>A<\/code> \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u043f\u043e \u0441\u0432\u043e\u0438\u043c 199 \u20bd, \u0445\u043e\u0442\u044f \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0443\u0436\u0435 249 \u20bd.<\/p>\n<p>\u0415\u0441\u043b\u0438 <code>UPDATE<\/code> \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u0442\u0440\u043e\u043a\u0443, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0435\u0441\u0442\u044c \u043b\u0438 \u0437\u0430\u043a\u0430\u0437 \u0438 \u043a\u0430\u043a\u043e\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0432 \u043d\u0451\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d. \u0421\u043e\u0432\u043f\u0430\u043b\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0441\u0443\u043c\u043c\u0430 \u0438 \u0432\u0430\u043b\u044e\u0442\u0430 \u2014 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0436\u0435 \u0443\u0447\u0442\u0451\u043d. \u0414\u0440\u0443\u0433\u043e\u0439 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0438\u043b\u0438 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0434\u043b\u044f \u0441\u0432\u0435\u0440\u043a\u0438. \u0415\u0441\u043b\u0438 <code>UPDATE<\/code> \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u044b\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u0430\u043a\u0430\u0437\u043e\u043c, SQLite \u0432\u0435\u0440\u043d\u0451\u0442 <code>sqlite3.IntegrityError<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0442\u0443 \u0436\u0435 \u0411\u0414 \u0432\u043d\u0443\u0442\u0440\u0438 <code>with db<\/code>, \u043a\u043e\u0433\u0434\u0430 <code>changed == 1<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u043c\u0435\u0442\u043a\u0430 \u043e\u0431 \u043e\u043f\u043b\u0430\u0442\u0435 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u0438 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a. <a href=\"https:\/\/docs.aws.amazon.com\/prescriptive-guidance\/latest\/cloud-design-patterns\/transactional-outbox.html\" rel=\"noopener nofollow\">Transactional outbox<\/a><\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437 \u0434\u043e \u0441\u043c\u0435\u043d\u044b \u0442\u0430\u0440\u0438\u0444\u0430 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u043b\u0435. \u0414\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043e\u0431\u0430 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043a\u0440\u044b\u0442\u044c\u0441\u044f \u043f\u043e 199 \u20bd, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043f\u043e 249 \u20bd.<\/p>\n<p><a href=\"https:\/\/docs.python.org\/3\/library\/sqlite3.html#sqlite3.Cursor.rowcount\" rel=\"noopener nofollow\">Python: <code>sqlite3.Cursor.rowcount<\/code><\/a><\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1114624\/\">https:\/\/habr.com\/ru\/articles\/1114624\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c \u043e\u0442\u043a\u0440\u044b\u043b \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0434\u0430\u0432\u0446\u0430 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430 199 \u20bd. \u041f\u043e\u043a\u0430 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u0430, \u0446\u0435\u043d\u0430 \u0442\u0430\u0440\u0438\u0444\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0434\u043e 249 \u20bd. \u041f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b \u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 199 \u20bd. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043d\u043e\u0432\u043e \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u0446\u0435\u043d\u0443 \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430, \u043e\u043d \u0443\u0432\u0438\u0434\u0438\u0442 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432 50 \u20bd \u0443 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430.\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0446\u0435\u043d\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u043a\u0430\u0437\u0430. \u041f\u0440\u0438 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u0438 \u0432\u0430\u043b\u044e\u0442\u0443, \u0430 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e. \u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0440\u0438\u0444\u0430 \u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u043a\u0430\u0437\u044b \u0431\u0443\u0434\u0443\u0442 \u0441\u0442\u043e\u0438\u0442\u044c 249 \u20bd. \u0423 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0446\u0435\u043d\u0430 199 \u20bd.\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u0430 \u0437\u0430\u043a\u0430\u0437\u0430 \u0435\u0449\u0451 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442. \u041d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u0438\u043d \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0443 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u041a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0441\u0432\u0435\u0440\u043a\u0438 \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438 \u043f\u043e\u0434\u043b\u0438\u043d\u043d\u043e\u0441\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430, \u0430 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430\u0448\u043b\u0438 \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0421\u0443\u043c\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \u0432\u0430\u043b\u044e\u0442\u044b. \u0414\u043b\u044f RUB \u044d\u0442\u043e \u043a\u043e\u043f\u0435\u0439\u043a\u0438. \u041a\u043e\u0434 \u0432\u0430\u043b\u044e\u0442\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430\u043a\u0430\u0437\u0430.import sqlite3db = sqlite3.connect(&#171;:memory:&#187;)db.execute(&#171;&#187;&#187;    CREATE TABLE orders (        order_id TEXT PRIMARY KEY NOT NULL,        amount_minor INTEGER NOT NULL CHECK (amount_minor &gt; 0),        currency TEXT NOT NULL,        payment_ref TEXT UNIQUE    )&#187;&#187;&#187;)def create_order(order_id, amount_minor, currency):    with db:        db.execute(&#171;&#187;&#187;            INSERT INTO orders (order_id, amount_minor, currency)            VALUES (?, ?, ?)        &#171;&#187;&#187;, (order_id, amount_minor, currency))def confirm(order_id, payment_ref, amount_minor, currency):    if not isinstance(payment_ref, str) or not payment_ref.strip():        raise ValueError(&#171;\u041d\u0443\u0436\u0435\u043d \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043b\u0430\u0442\u0435\u0436\u0430&#187;)    if type(amount_minor) is not int or amount_minor &lt;= 0:        raise ValueError(&#171;\u041d\u0443\u0436\u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043b\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0432 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \u0432\u0430\u043b\u044e\u0442\u044b&#187;)    with db:        changed = db.execute(&#171;&#187;&#187;            UPDATE orders            SET payment_ref = ?            WHERE order_id = ? AND payment_ref IS NULL              AND amount_minor = ? AND currency = ?        &#171;&#187;&#187;, (payment_ref, order_id, amount_minor, currency)).rowcount    return changed == 1tariff_price = 19900create_order(&#171;A&#187;, tariff_price, &#171;RUB&#187;)tariff_price = 24900create_order(&#171;B&#187;, tariff_price, &#171;RUB&#187;)print(confirm(&#171;A&#187;, &#171;pay-1&#187;, 24900, &#171;RUB&#187;))  # False: \u0434\u0440\u0443\u0433\u0430\u044f \u0441\u0443\u043c\u043c\u0430print(confirm(&#171;A&#187;, &#171;pay-1&#187;, 19900, &#171;USD&#187;))  # False: \u0434\u0440\u0443\u0433\u0430\u044f \u0432\u0430\u043b\u044e\u0442\u0430print(confirm(&#171;A&#187;, &#171;pay-1&#187;, 19900, &#171;RUB&#187;))  # True: \u0437\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043dprint(confirm(&#171;A&#187;, &#171;pay-1&#187;, 19900, &#171;RUB&#187;))  # False: \u043f\u043e\u0432\u0442\u043e\u0440 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043b \u0437\u0430\u043a\u0430\u0437print(confirm(&#171;B&#187;, &#171;pay-2&#187;, 24900, &#171;RUB&#187;))  # True: \u0437\u0430\u043a\u0430\u0437 \u043e\u043f\u043b\u0430\u0447\u0435\u043ddb.close()\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u0434 \u0432 Python 3 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c sqlite3. \u0417\u0430\u043a\u0430\u0437 A \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u044b\u043c \u043f\u043e \u0441\u0432\u043e\u0438\u043c 199 \u20bd, \u0445\u043e\u0442\u044f \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0443\u0436\u0435 249 \u20bd.\u0415\u0441\u043b\u0438 UPDATE \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u0442\u0440\u043e\u043a\u0443, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0435\u0441\u0442\u044c \u043b\u0438 \u0437\u0430\u043a\u0430\u0437 \u0438 \u043a\u0430\u043a\u043e\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0432 \u043d\u0451\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d. \u0421\u043e\u0432\u043f\u0430\u043b\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0441\u0443\u043c\u043c\u0430 \u0438 \u0432\u0430\u043b\u044e\u0442\u0430 \u2014 \u043f\u043b\u0430\u0442\u0451\u0436 \u0443\u0436\u0435 \u0443\u0447\u0442\u0451\u043d. \u0414\u0440\u0443\u0433\u043e\u0439 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0451\u0436 \u0438\u043b\u0438 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0434\u043b\u044f \u0441\u0432\u0435\u0440\u043a\u0438. \u0415\u0441\u043b\u0438 UPDATE \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u044b\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u0430\u043a\u0430\u0437\u043e\u043c, SQLite \u0432\u0435\u0440\u043d\u0451\u0442 sqlite3.IntegrityError.\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0442\u0443 \u0436\u0435 \u0411\u0414 \u0432\u043d\u0443\u0442\u0440\u0438 with db, \u043a\u043e\u0433\u0434\u0430 changed == 1. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u043c\u0435\u0442\u043a\u0430 \u043e\u0431 \u043e\u043f\u043b\u0430\u0442\u0435 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u0438 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a. Transactional outbox\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437 \u0434\u043e \u0441\u043c\u0435\u043d\u044b \u0442\u0430\u0440\u0438\u0444\u0430 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u043b\u0435. \u0414\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043e\u0431\u0430 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043a\u0430\u0437 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043a\u0440\u044b\u0442\u044c\u0441\u044f \u043f\u043e 199 \u20bd, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043f\u043e 249 \u20bd.Python: sqlite3.Cursor.rowcount\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1114624\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-505608","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/505608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=505608"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/505608\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=505608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=505608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=505608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}