dbd/mysql/statement.c

changeset 25
2cc3feba9277
parent 23
a4825c3e65e9
child 26
cf847efefdb5
equal deleted inserted replaced
24:abb9499bef51 25:2cc3feba9277
68 int n = lua_gettop(L); 68 int n = lua_gettop(L);
69 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); 69 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT);
70 int num_bind_params = n - 1; 70 int num_bind_params = n - 1;
71 int expected_params; 71 int expected_params;
72 72
73 unsigned char b[1024]; 73 unsigned char *buffer = NULL;
74 unsigned char *buffer = &b[0];
75 int offset = 0; 74 int offset = 0;
76 75
77 MYSQL_BIND *bind = NULL; 76 MYSQL_BIND *bind = NULL;
78 MYSQL_RES *metadata = NULL; 77 MYSQL_RES *metadata = NULL;
79 78
98 lua_pushboolean(L, 0); 97 lua_pushboolean(L, 0);
99 lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, expected_params, num_bind_params); 98 lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, expected_params, num_bind_params);
100 return 2; 99 return 2;
101 } 100 }
102 101
103 bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); 102 if (num_bind_params) {
104 103 bind = malloc(sizeof(MYSQL_BIND) * num_bind_params);
105 if (bind == NULL) { 104 if (bind == NULL) {
106 luaL_error(L, "Could not alloc bind params\n"); 105 luaL_error(L, "Could not alloc bind params\n");
107 } 106 }
108 107
109 memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); 108 buffer = malloc(num_bind_params * sizeof(size_t));
109 memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params);
110 }
110 111
111 for (p = 2; p <= n; p++) { 112 for (p = 2; p <= n; p++) {
112 int type = lua_type(L, p); 113 int type = lua_type(L, p);
113 int i = p - 2; 114 int i = p - 2;
114 115
186 } 187 }
187 188
188 cleanup: 189 cleanup:
189 if (bind) { 190 if (bind) {
190 free(bind); 191 free(bind);
192 }
193
194 if (buffer) {
195 free(buffer);
191 } 196 }
192 197
193 if (error_message) { 198 if (error_message) {
194 lua_pushboolean(L, 0); 199 lua_pushboolean(L, 0);
195 lua_pushfstring(L, error_message, errstr ? errstr : mysql_stmt_error(statement->stmt)); 200 lua_pushfstring(L, error_message, errstr ? errstr : mysql_stmt_error(statement->stmt));

mercurial