From 37bae4dcdb1d10d661b4697454b9e4cd0afa3d0c Mon Sep 17 00:00:00 2001 From: robverschoor Date: Tue, 2 Jan 2024 18:18:04 +0000 Subject: [PATCH] sp_executesql with NULL argument should not raise error --- contrib/babelfishpg_tsql/src/pl_exec-2.c | 10 ++++++---- test/JDBC/expected/BABEL-2748.out | 4 ---- test/JDBC/expected/BABEL-3092.out | 4 ---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index ded84a7c3a..950269b508 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -928,7 +928,7 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt) stmt->is_scalar_func = is_scalar_func; - /* T-SQL doens't allow call prcedure in function */ + /* T-SQL doesn't allow call procedure in function */ if (estate->func && estate->func->fn_oid != InvalidOid && estate->func->fn_prokind == PROKIND_FUNCTION && estate->func->fn_is_trigger == PLTSQL_NOT_TRIGGER /* check EXEC is running * in the body of * function */ @@ -2127,11 +2127,13 @@ exec_stmt_exec_sp(PLtsql_execstate *estate, PLtsql_stmt_exec_sp *stmt) int save_nestlevel; int scope_level; InlineCodeBlockArgs *args = NULL; - + batch = exec_eval_expr(estate, stmt->query, &isnull, &restype, &restypmod); if (isnull) - ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("batch string argument of sp_executesql is null"))); + { + // When called with a NULL argument, sp_executesql should take no action at all + break; + } batchstr = convert_value_to_string(estate, batch, restype); diff --git a/test/JDBC/expected/BABEL-2748.out b/test/JDBC/expected/BABEL-2748.out index 9e4daaac8f..ee27382cf3 100644 --- a/test/JDBC/expected/BABEL-2748.out +++ b/test/JDBC/expected/BABEL-2748.out @@ -229,10 +229,6 @@ declare @query_str varchar(100); declare @param_def varchar(100); exec sp_executesql @query_str, @param_def; go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: batch string argument of sp_executesql is null)~~ - exec sp_prepexec; go diff --git a/test/JDBC/expected/BABEL-3092.out b/test/JDBC/expected/BABEL-3092.out index af641875fb..6f2073aab9 100644 --- a/test/JDBC/expected/BABEL-3092.out +++ b/test/JDBC/expected/BABEL-3092.out @@ -60,10 +60,6 @@ GO sp_executesql NULL; GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: batch string argument of sp_executesql is null)~~ - CREATE TABLE t_3092_fmtonly(a INT); GO