dbd/mysql/statement.c

changeset 26
cf847efefdb5
parent 25
2cc3feba9277
child 30
8599f34c139b
equal deleted inserted replaced
25:2cc3feba9277 26:cf847efefdb5
97 lua_pushboolean(L, 0); 97 lua_pushboolean(L, 0);
98 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);
99 return 2; 99 return 2;
100 } 100 }
101 101
102 if (num_bind_params) { 102 if (num_bind_params > 0) {
103 bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); 103 bind = malloc(sizeof(MYSQL_BIND) * num_bind_params);
104 if (bind == NULL) { 104 if (bind == NULL) {
105 luaL_error(L, "Could not alloc bind params\n"); 105 luaL_error(L, "Could not alloc bind params\n");
106 } 106 }
107 107
108 buffer = malloc(num_bind_params * sizeof(size_t)); 108 buffer = (unsigned char *)malloc(num_bind_params * sizeof(double));
109 memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); 109 memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params);
110 } 110 }
111 111
112 for (p = 2; p <= n; p++) { 112 for (p = 2; p <= n; p++) {
113 int type = lua_type(L, p); 113 int type = lua_type(L, p);
124 bind[i].buffer_type = MYSQL_TYPE_NULL; 124 bind[i].buffer_type = MYSQL_TYPE_NULL;
125 bind[i].is_null = (my_bool*)1; 125 bind[i].is_null = (my_bool*)1;
126 break; 126 break;
127 127
128 case LUA_TBOOLEAN: 128 case LUA_TBOOLEAN:
129 boolean = (int *)buffer + offset; 129 boolean = (int *)(buffer + offset);
130 offset += sizeof(int); 130 offset += sizeof(int);
131 *boolean = lua_toboolean(L, p); 131 *boolean = lua_toboolean(L, p);
132 132
133 bind[i].buffer_type = MYSQL_TYPE_LONG; 133 bind[i].buffer_type = MYSQL_TYPE_LONG;
134 bind[i].is_null = (my_bool*)0; 134 bind[i].is_null = (my_bool*)0;
139 case LUA_TNUMBER: 139 case LUA_TNUMBER:
140 /* 140 /*
141 * num needs to be it's own 141 * num needs to be it's own
142 * memory here 142 * memory here
143 */ 143 */
144 num = (double *)buffer + offset; 144 num = (double *)(buffer + offset);
145 offset += sizeof(double); 145 offset += sizeof(double);
146 *num = lua_tonumber(L, p); 146 *num = lua_tonumber(L, p);
147 147
148 bind[i].buffer_type = MYSQL_TYPE_DOUBLE; 148 bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
149 bind[i].is_null = (my_bool*)0; 149 bind[i].is_null = (my_bool*)0;
150 bind[i].buffer = (char *)num; 150 bind[i].buffer = (char *)num;
151 bind[i].length = 0; 151 bind[i].length = 0;
152 break; 152 break;
153 153
154 case LUA_TSTRING: 154 case LUA_TSTRING:
155 str_len = (size_t *)buffer + offset; 155 str_len = (size_t *)(buffer + offset);
156 offset += sizeof(size_t); 156 offset += sizeof(size_t);
157 str = lua_tolstring(L, p, str_len); 157 str = lua_tolstring(L, p, str_len);
158 158
159 bind[i].buffer_type = MYSQL_TYPE_STRING; 159 bind[i].buffer_type = MYSQL_TYPE_STRING;
160 bind[i].is_null = (my_bool*)0; 160 bind[i].is_null = (my_bool*)0;

mercurial