diff -r b705ba343e94 -r b5ec612be4da dbd/db2/statement.c --- a/dbd/db2/statement.c Sat Dec 06 07:35:31 2008 +0000 +++ b/dbd/db2/statement.c Sat Dec 06 08:40:10 2008 +0000 @@ -65,6 +65,7 @@ int offset = 0; resultset_t *resultset = NULL; bindparams_t *bind; /* variable to read the results */ + SQLSMALLINT num_params; SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; @@ -77,6 +78,26 @@ return 2; } + rc = SQLNumParams(statement->stmt, &num_params); + if (rc != SQL_SUCCESS) { + SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); + + lua_pushboolean(L, 0); + lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message); + return 2; + } + + if (num_params != n-1) { + /* + * SQLExecute does not handle this condition, + * and the client library will fill unset params + * with NULLs + */ + lua_pushboolean(L, 0); + lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, num_params, n-1); + return 2; + } + for (p = 2; p <= n; p++) { int i = p - 1; int type = lua_type(L, p);