How to get record(s) affected in frappe.db.sql?


I am making one tool similar to bulk update?

Based on update, I am updating values, How I can get record(s) affected in Update and Delete Query?

I have used debug=True, but it’s not returning expected result.

In [4]: a=frappe.db.sql(“Delete from tabCustom Doc where name=‘{document_name}’ limit 1”,debug=True)
— query explain —
“rows”: 1,
“select_type”: “SIMPLE”,
“Extra”: “Using where”,
“ref”: null,
“key_len”: “562”,
“possible_keys”: “PRIMARY”,
“key”: “PRIMARY”,
“table”: “tabMatrix Recrun”,
“type”: “range”,
“id”: 1
— query explain end —
Delete from tabCustom Doc where name=‘{document_name}’ limit 1


Does this help?

Thanks, its really helpful.

But row_count is returning last transaction row count, so I will check it on testing instance as many queries are running simultaneously on testing server.

My code:

				frappe.db.sql("Delete from tabCustom Doc where name=’{document_name}’ limit 1")
				row_count=frappe.db.sql("select ROW_COUNT()");

you could simply do select count (*)

1 Like