dbd/db2/statement.c

changeset 19
b5ec612be4da
parent 17
21c4feaeafe7
child 21
7956401a0c5e
equal deleted inserted replaced
18:b705ba343e94 19:b5ec612be4da
63 SQLRETURN rc = SQL_SUCCESS; 63 SQLRETURN rc = SQL_SUCCESS;
64 unsigned char *buffer = NULL; 64 unsigned char *buffer = NULL;
65 int offset = 0; 65 int offset = 0;
66 resultset_t *resultset = NULL; 66 resultset_t *resultset = NULL;
67 bindparams_t *bind; /* variable to read the results */ 67 bindparams_t *bind; /* variable to read the results */
68 SQLSMALLINT num_params;
68 69
69 SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; 70 SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
70 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; 71 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
71 SQLINTEGER sqlcode; 72 SQLINTEGER sqlcode;
72 SQLSMALLINT length; 73 SQLSMALLINT length;
73 74
74 if (!statement->stmt) { 75 if (!statement->stmt) {
75 lua_pushboolean(L, 0); 76 lua_pushboolean(L, 0);
76 lua_pushstring(L, DBI_ERR_EXECUTE_INVALID); 77 lua_pushstring(L, DBI_ERR_EXECUTE_INVALID);
78 return 2;
79 }
80
81 rc = SQLNumParams(statement->stmt, &num_params);
82 if (rc != SQL_SUCCESS) {
83 SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length);
84
85 lua_pushboolean(L, 0);
86 lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message);
87 return 2;
88 }
89
90 if (num_params != n-1) {
91 /*
92 * SQLExecute does not handle this condition,
93 * and the client library will fill unset params
94 * with NULLs
95 */
96 lua_pushboolean(L, 0);
97 lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, num_params, n-1);
77 return 2; 98 return 2;
78 } 99 }
79 100
80 for (p = 2; p <= n; p++) { 101 for (p = 2; p <= n; p++) {
81 int i = p - 1; 102 int i = p - 1;

mercurial