Informix Error -766
Cause and resolution
String must be null terminated.
With IBM Informix ESQL/C, if you use a host variable in an INSERT statement or in the WHERE clause of an SQL statement, and the database is ANSI compliant, the string must be null terminated.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-766 fires when an ESQL/C host variable used in an INSERT statement or a WHERE clause isn't
null-terminated, on an ANSI-compliant database — per the official guidance, ANSI compliance
specifically requires this; the same code might work without null termination on a non-ANSI
database.
- A fixed-length character buffer used as a host variable without a trailing null
terminator, per the official guidance — the direct, common cause, especially with
char[]buffers that were filled without leaving room for (or setting) the terminator. - A string built via non-null-terminating operations (a fixed-width copy that fills the
entire buffer with data, with no space left for
\0), producing a buffer ESQL/C can't correctly treat as a C string. - Code that worked on a non-ANSI database reused against an ANSI-compliant one, surfacing this requirement for the first time.
Solutions / Resolution
- Ensure every host variable string used in an
INSERTorWHEREclause is null-terminated, per the official guidance, on an ANSI-compliant database. - Size character buffers to leave room for the null terminator, and explicitly set it after
filling the buffer's data:
char status[11]; /* 10 chars of data + 1 for '\0' */ strncpy(status, "shipped", sizeof(status) - 1); status[sizeof(status) - 1] = '\0'; - Check whether the target database is ANSI-compliant, if this requirement is unexpected:
SELECT name, is_ansi FROM sysmaster:sysdatabases WHERE name = 'target_db';
Examples
A non-null-terminated buffer
char status[10];
memset(status, ' ', 10);
memcpy(status, "shipped", 7);
/* no null terminator anywhere in the 10-byte buffer */
EXEC SQL UPDATE orders SET status = :status WHERE order_id = :order_id;
/* -766, on an ANSI-compliant database */
Corrected
char status[11];
strncpy(status, "shipped", sizeof(status) - 1);
status[sizeof(status) - 1] = '\0';
EXEC SQL UPDATE orders SET status = :status WHERE order_id = :order_id;
Diagnostic Checks
- Check the target database's ANSI-compliance status.
- Review the host variable's buffer size and how it's populated, confirming a null terminator is always present within the allocated size.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -766 in this set yet.
ANSI-compliant databases require null-terminated host-variable strings — size buffers with room
for \0 and set it explicitly after filling the data.