0

While trying to update a non-existing column in a single statement throws an exception:

session.execute("UPDATE users SET wrong_column = test@test.com;")

If I do the same with multiple statements, the exception is not raised:

session.execute("UPDATE users SET email = test@test.com; UPDATE users SET wrong_column = test@test.com;")

One stackoverflow solution proposed is to split the query by the delimiter ;:

But this does not work in my particular case as my query also consist of a few functions that have a delimiter in the RETURN ... ; statement and then again the END; statement, so the split would break the query. (I know I could also try to split the query with sqlparse but installing an extra library for that also seems weird to me)

Is there really no better way to check if all statements in a raw query were executed without error?

I also tried to find something in the CursorResult object that is returned by the session.execute func, but I could not find anything.

(I'm working with a MySQL DB in case it matters)

sahasrara62
  • 10,069
  • 3
  • 29
  • 44
Basiti
  • 143
  • 1
  • 11
  • 2
    I can't find any supportive docs, but my gut feel is that `execute` is designed for single statements. If you want to execute multiple text statements you might be better off using the DB-API cursor, as shown in some of the answers to the Q&A that you linked. – snakecharmerb Feb 09 '23 at 19:26
  • Thanks @snakecharmerb This worked totally fine: ``` cursor = db_session.connection().connection.cursor() cursor.execute(query) ``` – Basiti Feb 27 '23 at 12:14

0 Answers0