From 4635ed4c57cdc453d085c87ed42e0f3eaa125c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sun, 14 Jun 2026 06:44:39 +0400 Subject: [PATCH] =?UTF-8?q?feat(test):=20action=20'exec'=20=E2=80=94=20INS?= =?UTF-8?q?ERT/UPDATE/DDL=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20db.execute()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /test sql → db.query() → fetchall() → ломается на CREATE TABLE /test exec → db.execute() → commit без fetch → для DDL/INSERT/UPDATE --- site/test_routes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/site/test_routes.py b/site/test_routes.py index bf47e7a..a55c75c 100644 --- a/site/test_routes.py +++ b/site/test_routes.py @@ -38,7 +38,8 @@ def test(): "POST /test status — статус БД (JSON)", "POST /test createdb — создать БД (если нет)", "POST /test tables — список таблиц", - "POST /test sql {...} — выполнить SQL", + "POST /test exec {...} — INSERT/UPDATE/DDL (без fetch)", + "POST /test sql {...} — SELECT (с fetch)", ], }) @@ -78,6 +79,17 @@ def test(): except Exception as e: return jsonify({"error": str(e)}), 500 + if action == "exec": + # Выполнить INSERT/UPDATE/DELETE/DDL через db.execute() + # (не делает fetch, поэтому подходит для CREATE TABLE и т.д.) + sql_text = data.get("sql", "") + if not sql_text: + return jsonify({"error": "no sql"}), 400 + rowcount, err = db.execute(sql_text) + if err: + return jsonify({"error": err}), 500 + return jsonify({"rowcount": rowcount}) + if action == "sql": sql_text = data.get("sql", "") if not sql_text: