Skip to content

Commit

Permalink
sp_executesql with NULL argument should not raise error
Browse files Browse the repository at this point in the history
  • Loading branch information
robverschoor committed Jan 2, 2024
1 parent 5c67087 commit 37bae4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
10 changes: 6 additions & 4 deletions contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions test/JDBC/expected/BABEL-2748.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/JDBC/expected/BABEL-3092.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37bae4d

Please sign in to comment.