Informix Error -26051: EXECUTE IMMEDIATE and PREPARE cannot take NULL statement
Cause and resolution
EXECUTE IMMEDIATE and PREPARE cannot take NULL statement
Expression that specifies SQL statement text in either EXECUTE IMMEDIATE or PREPARE evaluates to a NULL value. Make sure to pass the text of a valid SQL statement to these statements.
This error can be prevented by testing the expression passed to either EXECUTE IMMEDIATE or PREPARE for a NULL value:
Example (1)
DEFINE qStr CHAR(255); ... LET qStr = <expression>; </expression>
-- validate if <expression> above evalutes to NULL IF (qStr IS NOT NULL) THEN EXECUTE IMMEDIATE qStr; ELSE ... END IF; </expression>
Example (2)
DEFINE def_lc1 INTEGER; DEFINE lc1 INTEGER;
LET def_lc1 = 10;
SELECT c1 INTO lc1 FROM t1 WHERE c2 = 10;
-- validate if query above returns a NULL value to lc1 -- if it is NULL then logic below should use default -- lc1 (def_lc1) to avoid concatenation that returns NULL
IF (lc1 IS NOT NULL) THEN PREPARE stmtId FROM "select c2[" || lc1 || "] FROM t2"; ELSE PREPARE stmtId FROM "select c2[" || def_lc1 || "] FROM t2"; END IF;
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-26051 fires when the SQL-statement-text expression passed to EXECUTE IMMEDIATE/
PREPARE evaluates to null — per the official guidance.
- The expression passed to
EXECUTE IMMEDIATE/PREPAREevaluates to a null value, per the official guidance — the direct, only cause.
Solutions / Resolution
- Test the expression for null before passing it, per the official guidance.
Examples
Guarding against a NULL statement text
DEFINE qStr CHAR(255);
LET qStr = expr;
IF (qStr IS NOT NULL) THEN
EXECUTE IMMEDIATE qStr;
ELSE
...
END IF;
Diagnostic Checks
- Check the expression passed to
EXECUTE IMMEDIATE/PREPARE, and confirm it's guarded against evaluating to null.
Related Errors / Related Topics
- -26058 — "EXECUTE IMMEDIATE and PREPARE in SPL cannot allow multiple SQL statements."
A related
EXECUTE IMMEDIATE/PREPARErestriction, on multiple statements rather than a null one. - -26059 — "Unsupported data type in EXECUTE IMMEDIATE or PREPARE statement." A related
EXECUTE IMMEDIATE/PREPARErestriction, on the variable's data type rather than a null value.
An EXECUTE IMMEDIATE/PREPARE expression evaluated to null — test the expression for
null before passing it.