@@ -356,13 +356,23 @@ def execute_sql_script(
356356 db_connection .client .rollback ()
357357
358358 def execute_sql_string (
359- self , sqlString : str , sansTran : bool = False , alias : Optional [str ] = None , parameters : Optional [List ] = None
359+ self ,
360+ sqlString : str ,
361+ sansTran : bool = False ,
362+ omitTrailingSemicolon : Optional [bool ] = None ,
363+ alias : Optional [str ] = None ,
364+ parameters : Optional [List ] = None ,
360365 ):
361366 """
362- Executes the sqlString as SQL commands. Useful to pass arguments to your sql.
363- SQL commands are expected to be delimited by a semicolon (';').
367+ Executes the ``sqlString`` as a single SQL command.
364368
365- Use optional `sansTran` to run command without an explicit transaction commit or rollback:
369+ Use optional ``sansTran`` to run command without an explicit transaction commit or rollback.
370+
371+ Use optional ``omitTrailingSemicolon`` parameter for explicit instruction,
372+ if the trailing semicolon (;) at the SQL string end should be removed or not:
373+ - Some database modules (e.g. Oracle) throw an exception, if you leave a semicolon at the string end
374+ - However, there are exceptional cases, when you need it even for Oracle - e.g. at the end of a PL/SQL block.
375+ - If not specified, it's decided based on the current database module in use. For Oracle, the semicolon is removed by default.
366376
367377 Use optional ``alias`` parameter to specify what connection should be used for the query if you have more
368378 than one connection open.
@@ -374,6 +384,7 @@ def execute_sql_string(
374384 | Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table |
375385 | Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | alias=my_alias |
376386 | Execute Sql String | DELETE FROM person_employee_table; DELETE FROM person_table | sansTran=True |
387+ | Execute Sql String | CREATE PROCEDURE proc AS BEGIN DBMS_OUTPUT.PUT_LINE('Hello!'); END; | omitTrailingSemicolon=False |
377388 | @{parameters} | Create List | person_employee_table |
378389 | Execute Sql String | SELECT * FROM %s | parameters=${parameters} |
379390 """
@@ -382,7 +393,7 @@ def execute_sql_string(
382393 try :
383394 cur = db_connection .client .cursor ()
384395 logger .info (f"Executing : Execute SQL String | { sqlString } " )
385- self .__execute_sql (cur , sqlString , parameters = parameters )
396+ self .__execute_sql (cur , sqlString , omit_trailing_semicolon = omitTrailingSemicolon , parameters = parameters )
386397 if not sansTran :
387398 db_connection .client .commit ()
388399 finally :
0 commit comments