Tue, 02 Dec 2008 08:10:54 +0000
Bugfix: PSQL array returns were not being indexed properly.
Changes:
* statement:fetch() returns an iterator
* statement:row() added to replace old statement:fetch() behaviour
* statement:fetch() and statement:row() now take an optional boolean value to either return an array(false, default) or a hashmap (true)
1 | 1 | #include "dbd_mysql.h" |
2 | ||
3 | static lua_push_type_t mysql_to_lua_push(unsigned int mysql_type) { | |
4 | lua_push_type_t lua_type; | |
5 | ||
6 | switch(mysql_type) { | |
7 | case MYSQL_TYPE_NULL: | |
8 | lua_type = LUA_PUSH_NIL; | |
9 | break; | |
10 | ||
11 | case MYSQL_TYPE_TINY: | |
12 | case MYSQL_TYPE_SHORT: | |
13 | case MYSQL_TYPE_LONG: | |
14 | lua_type = LUA_PUSH_INTEGER; | |
15 | break; | |
16 | ||
17 | case MYSQL_TYPE_DOUBLE: | |
18 | case MYSQL_TYPE_LONGLONG: | |
19 | lua_type = LUA_PUSH_NUMBER; | |
20 | break; | |
21 | ||
22 | default: | |
23 | lua_type = LUA_PUSH_STRING; | |
24 | } | |
25 | ||
26 | return lua_type; | |
27 | } | |
28 | ||
2 | 29 | /* |
30 | * success = statement:close() | |
31 | */ | |
1 | 32 | static int statement_close(lua_State *L) { |
33 | statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); | |
34 | ||
35 | if (statement->metadata) { | |
36 | mysql_free_result(statement->metadata); | |
3 | 37 | statement->metadata = NULL; |
1 | 38 | } |
39 | ||
40 | if (statement->stmt) { | |
3 | 41 | mysql_stmt_close(statement->stmt); |
42 | statement->stmt = NULL; | |
1 | 43 | } |
44 | ||
3 | 45 | lua_pushboolean(L, 1); |
1 | 46 | return 1; |
47 | } | |
48 | ||
2 | 49 | /* |
3 | 50 | * success,err = statement:execute(...) |
2 | 51 | */ |
1 | 52 | static int statement_execute(lua_State *L) { |
53 | int n = lua_gettop(L); | |
54 | statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); | |
55 | int num_bind_params = n - 1; | |
3 | 56 | int expected_params; |
1 | 57 | |
58 | MYSQL_BIND *bind = NULL; | |
59 | MYSQL_RES *metadata = NULL; | |
60 | ||
61 | char *error_message = NULL; | |
10 | 62 | char *errstr = NULL; |
1 | 63 | |
64 | int p; | |
65 | ||
3 | 66 | if (!statement->stmt) { |
67 | lua_pushboolean(L, 0); | |
4 | 68 | lua_pushstring(L, DBI_ERR_EXECUTE_INVALID); |
3 | 69 | return 2; |
70 | } | |
71 | ||
72 | expected_params = mysql_stmt_param_count(statement->stmt); | |
73 | ||
74 | if (expected_params != num_bind_params) { | |
75 | /* | |
10 | 76 | * mysql_stmt_bind_param does not handle this condition, |
3 | 77 | * and the client library will segfault if these do no match |
78 | */ | |
79 | lua_pushboolean(L, 0); | |
4 | 80 | lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, expected_params, num_bind_params); |
3 | 81 | return 2; |
82 | } | |
83 | ||
1 | 84 | bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); |
85 | memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); | |
86 | ||
87 | for (p = 2; p <= n; p++) { | |
88 | int type = lua_type(L, p); | |
89 | int i = p - 2; | |
90 | ||
91 | const char *str = NULL; | |
7
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
92 | size_t *str_len = NULL; |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
93 | double *num = NULL; |
9 | 94 | int *boolean = NULL; |
10 | 95 | char err[64]; |
1 | 96 | |
97 | switch(type) { | |
98 | case LUA_TNIL: | |
99 | bind[i].buffer_type = MYSQL_TYPE_NULL; | |
100 | bind[i].is_null = (my_bool*)1; | |
101 | break; | |
102 | ||
9 | 103 | case LUA_TBOOLEAN: |
104 | boolean = (int *)malloc(sizeof(int)); | |
105 | *boolean = lua_toboolean(L, p); | |
106 | bind[i].buffer_type = MYSQL_TYPE_LONG; | |
107 | bind[i].is_null = (my_bool*)0; | |
108 | bind[i].buffer = (char *)boolean; | |
109 | bind[i].length = 0; | |
110 | break; | |
111 | ||
1 | 112 | case LUA_TNUMBER: |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
113 | /* |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
114 | * num needs to be it's own |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
115 | * memory here |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
116 | */ |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
117 | num = (double *)malloc(sizeof(double)); |
9 | 118 | *num = lua_tonumber(L, p); |
1 | 119 | |
120 | bind[i].buffer_type = MYSQL_TYPE_DOUBLE; | |
121 | bind[i].is_null = (my_bool*)0; | |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
122 | bind[i].buffer = (char *)num; |
1 | 123 | bind[i].length = 0; |
124 | break; | |
125 | ||
126 | case LUA_TSTRING: | |
7
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
127 | str_len = malloc(sizeof(size_t)); |
9 | 128 | str = lua_tolstring(L, p, str_len); |
1 | 129 | |
130 | bind[i].buffer_type = MYSQL_TYPE_STRING; | |
131 | bind[i].is_null = (my_bool*)0; | |
132 | bind[i].buffer = (char *)str; | |
7
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
133 | bind[i].length = str_len; |
1 | 134 | break; |
135 | ||
136 | default: | |
10 | 137 | snprintf(err, sizeof(err)-1, DBI_ERR_BINDING_TYPE_ERR, lua_typename(L, type)); |
138 | errstr = err; | |
139 | error_message = DBI_ERR_BINDING_PARAMS; | |
1 | 140 | goto cleanup; |
141 | } | |
142 | } | |
143 | ||
144 | if (mysql_stmt_bind_param(statement->stmt, bind)) { | |
4 | 145 | error_message = DBI_ERR_BINDING_PARAMS; |
1 | 146 | goto cleanup; |
147 | } | |
148 | ||
149 | if (mysql_stmt_execute(statement->stmt)) { | |
4 | 150 | error_message = DBI_ERR_BINDING_EXEC; |
1 | 151 | goto cleanup; |
152 | } | |
153 | ||
154 | metadata = mysql_stmt_result_metadata(statement->stmt); | |
155 | ||
156 | cleanup: | |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
157 | if (bind) { |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
158 | int i; |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
159 | |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
160 | for (i = 0; i < num_bind_params; i++) { |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
161 | /* |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
162 | * Free the memory associated with |
7
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
163 | * the allocation of double and string |
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
164 | * bind params. If the interface are |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
165 | * extended with other types they |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
166 | * will need to be added here |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
167 | */ |
9 | 168 | if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE || bind[i].buffer_type == MYSQL_TYPE_LONG) { |
7
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
169 | if (bind[i].buffer) |
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
170 | free(bind[i].buffer); |
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
171 | } else if (bind[i].buffer_type == MYSQL_TYPE_STRING) { |
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
172 | if (bind[i].length) |
4480ae002881
Bugfix - the size of strings for bind params pointed to the same memory
nrich@ii.net
parents:
6
diff
changeset
|
173 | free(bind[i].length); |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
174 | } |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
175 | } |
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
176 | |
1 | 177 | free(bind); |
6
22046b996150
Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.
nrich@ii.net
parents:
4
diff
changeset
|
178 | } |
1 | 179 | |
180 | if (error_message) { | |
3 | 181 | lua_pushboolean(L, 0); |
10 | 182 | lua_pushfstring(L, error_message, errstr ? errstr : mysql_stmt_error(statement->stmt)); |
3 | 183 | return 2; |
1 | 184 | } |
185 | ||
186 | statement->metadata = metadata; | |
187 | ||
3 | 188 | lua_pushboolean(L, 1); |
1 | 189 | return 1; |
190 | } | |
191 | ||
11
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
192 | static int statement_fetch_impl(lua_State *L, statement_t *statement, int named_columns) { |
1 | 193 | int column_count; |
194 | MYSQL_BIND *bind = NULL; | |
195 | const char *error_message = NULL; | |
196 | ||
197 | if (!statement->stmt) { | |
4 | 198 | luaL_error(L, DBI_ERR_FETCH_INVALID); |
3 | 199 | return 0; |
200 | } | |
201 | ||
202 | if (!statement->metadata) { | |
4 | 203 | luaL_error(L, DBI_ERR_FETCH_NO_EXECUTE); |
3 | 204 | return 0; |
1 | 205 | } |
206 | ||
207 | if (!statement->metadata) { | |
208 | lua_pushnil(L); | |
209 | return 1; | |
210 | } | |
211 | ||
212 | column_count = mysql_num_fields(statement->metadata); | |
213 | ||
214 | if (column_count > 0) { | |
215 | int i; | |
216 | MYSQL_FIELD *fields; | |
217 | ||
218 | bind = malloc(sizeof(MYSQL_BIND) * column_count); | |
219 | memset(bind, 0, sizeof(MYSQL_BIND) * column_count); | |
220 | ||
221 | fields = mysql_fetch_fields(statement->metadata); | |
222 | ||
223 | for (i = 0; i < column_count; i++) { | |
224 | unsigned int length = fields[i].length; | |
225 | ||
226 | char *buffer = (char *)malloc(length); | |
227 | memset(buffer, 0, length); | |
228 | ||
229 | bind[i].buffer_type = fields[i].type; | |
230 | bind[i].buffer = buffer; | |
231 | bind[i].buffer_length = length; | |
232 | } | |
233 | ||
234 | if (mysql_stmt_bind_result(statement->stmt, bind)) { | |
4 | 235 | error_message = DBI_ERR_BINDING_RESULTS; |
1 | 236 | goto cleanup; |
237 | } | |
238 | ||
239 | if (!mysql_stmt_fetch(statement->stmt)) { | |
240 | int d = 1; | |
241 | ||
242 | lua_newtable(L); | |
243 | for (i = 0; i < column_count; i++) { | |
244 | lua_push_type_t lua_push = mysql_to_lua_push(fields[i].type); | |
245 | const char *name = fields[i].name; | |
246 | ||
247 | if (lua_push == LUA_PUSH_NIL) { | |
248 | if (named_columns) { | |
249 | LUA_PUSH_ATTRIB_NIL(name); | |
250 | } else { | |
251 | LUA_PUSH_ARRAY_NIL(d); | |
252 | } | |
253 | } else if (lua_push == LUA_PUSH_INTEGER) { | |
254 | if (named_columns) { | |
255 | LUA_PUSH_ATTRIB_INT(name, *(int *)(bind[i].buffer)); | |
256 | } else { | |
257 | LUA_PUSH_ARRAY_INT(d, *(int *)(bind[i].buffer)); | |
258 | } | |
259 | } else if (lua_push == LUA_PUSH_NUMBER) { | |
260 | if (named_columns) { | |
261 | LUA_PUSH_ATTRIB_FLOAT(name, *(double *)(bind[i].buffer)); | |
262 | } else { | |
263 | LUA_PUSH_ARRAY_FLOAT(d, *(double *)(bind[i].buffer)); | |
264 | } | |
265 | } else if (lua_push == LUA_PUSH_STRING) { | |
266 | if (named_columns) { | |
267 | LUA_PUSH_ATTRIB_STRING(name, bind[i].buffer); | |
268 | } else { | |
269 | LUA_PUSH_ARRAY_STRING(d, bind[i].buffer); | |
270 | } | |
271 | } else if (lua_push == LUA_PUSH_BOOLEAN) { | |
272 | if (named_columns) { | |
273 | LUA_PUSH_ATTRIB_BOOL(name, *(int *)(bind[i].buffer)); | |
274 | } else { | |
275 | LUA_PUSH_ARRAY_BOOL(d, *(int *)(bind[i].buffer)); | |
276 | } | |
277 | } else { | |
4 | 278 | luaL_error(L, DBI_ERR_UNKNOWN_PUSH); |
1 | 279 | } |
280 | } | |
281 | } else { | |
282 | lua_pushnil(L); | |
283 | } | |
284 | } | |
285 | ||
286 | cleanup: | |
287 | if (bind) { | |
288 | int i; | |
289 | ||
290 | for (i = 0; i < column_count; i++) { | |
291 | free(bind[i].buffer); | |
292 | } | |
293 | ||
294 | free(bind); | |
295 | } | |
296 | ||
297 | if (error_message) { | |
298 | luaL_error(L, error_message, mysql_stmt_error(statement->stmt)); | |
299 | return 0; | |
300 | } | |
301 | ||
302 | return 1; | |
303 | } | |
304 | ||
11
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
305 | static int next_iterator(lua_State *L) { |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
306 | statement_t *statement = (statement_t *)luaL_checkudata(L, lua_upvalueindex(1), DBD_MYSQL_STATEMENT); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
307 | int named_columns = lua_toboolean(L, lua_upvalueindex(2)); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
308 | |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
309 | return statement_fetch_impl(L, statement, named_columns); |
1 | 310 | } |
311 | ||
2 | 312 | /* |
11
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
313 | * iterfunc = statement:fetch(named_indexes) |
2 | 314 | */ |
11
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
315 | |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
316 | static int statement_fetch(lua_State *L) { |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
317 | if (lua_gettop(L) == 1) { |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
318 | lua_pushvalue(L, 1); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
319 | lua_pushboolean(L, 0); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
320 | } else { |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
321 | lua_pushvalue(L, 1); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
322 | lua_pushboolean(L, lua_toboolean(L, 2)); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
323 | } |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
324 | |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
325 | lua_pushcclosure(L, next_iterator, 2); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
326 | return 1; |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
327 | } |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
328 | |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
329 | /* |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
330 | * table = statement:row(named_indexes) |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
331 | */ |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
332 | static int statement_row(lua_State *L) { |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
333 | statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
334 | int named_columns = lua_toboolean(L, 2); |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
335 | |
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
336 | return statement_fetch_impl(L, statement, named_columns); |
1 | 337 | } |
338 | ||
2 | 339 | /* |
340 | * __gc | |
341 | */ | |
1 | 342 | static int statement_gc(lua_State *L) { |
343 | /* always free the handle */ | |
344 | statement_close(L); | |
345 | ||
346 | return 0; | |
347 | } | |
348 | ||
349 | int dbd_mysql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { | |
350 | unsigned long sql_len = strlen(sql_query); | |
351 | ||
352 | statement_t *statement = NULL; | |
353 | ||
354 | MYSQL_STMT *stmt = mysql_stmt_init(conn->mysql); | |
355 | ||
356 | if (!stmt) { | |
3 | 357 | lua_pushnil(L); |
4 | 358 | lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, mysql_error(conn->mysql)); |
3 | 359 | return 2; |
1 | 360 | } |
361 | ||
362 | if (mysql_stmt_prepare(stmt, sql_query, sql_len)) { | |
3 | 363 | lua_pushnil(L); |
4 | 364 | lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, mysql_stmt_error(stmt)); |
3 | 365 | return 2; |
1 | 366 | } |
367 | ||
368 | statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); | |
369 | statement->mysql = conn->mysql; | |
370 | statement->stmt = stmt; | |
371 | statement->metadata = NULL; | |
372 | ||
373 | luaL_getmetatable(L, DBD_MYSQL_STATEMENT); | |
374 | lua_setmetatable(L, -2); | |
375 | ||
376 | return 1; | |
377 | } | |
378 | ||
379 | int dbd_mysql_statement(lua_State *L) { | |
2 | 380 | static const luaL_Reg statement_methods[] = { |
381 | {"close", statement_close}, | |
382 | {"execute", statement_execute}, | |
383 | {"fetch", statement_fetch}, | |
11
b3e05e361f46
Bugfix: PSQL array returns were not being indexed properly.
nrich@ii.net
parents:
10
diff
changeset
|
384 | {"row", statement_row}, |
2 | 385 | {NULL, NULL} |
386 | }; | |
387 | ||
388 | static const luaL_Reg statement_class_methods[] = { | |
389 | {NULL, NULL} | |
390 | }; | |
391 | ||
1 | 392 | luaL_newmetatable(L, DBD_MYSQL_STATEMENT); |
393 | luaL_register(L, 0, statement_methods); | |
394 | lua_pushvalue(L,-1); | |
395 | lua_setfield(L, -2, "__index"); | |
396 | ||
397 | lua_pushcfunction(L, statement_gc); | |
398 | lua_setfield(L, -2, "__gc"); | |
399 | ||
400 | luaL_register(L, DBD_MYSQL_STATEMENT, statement_class_methods); | |
401 | ||
402 | return 1; | |
403 | } |