dbd/mysql/statement.c

changeset 21
7956401a0c5e
parent 14
98192b7d4e89
child 23
a4825c3e65e9
equal deleted inserted replaced
20:5ab0b30f8fbd 21:7956401a0c5e
23 lua_type = LUA_PUSH_STRING; 23 lua_type = LUA_PUSH_STRING;
24 } 24 }
25 25
26 return lua_type; 26 return lua_type;
27 } 27 }
28
29 /*
30 * num_affected_rows = statement:affected()
31 */
32 static int statement_affected(lua_State *L) {
33 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT);
34
35 if (!statement->stmt) {
36 luaL_error(L, DBI_ERR_INVALID_STATEMENT);
37 }
38
39 lua_pushinteger(L, mysql_stmt_affected_rows(statement->stmt));
40
41 return 1;
42 }
28 43
29 /* 44 /*
30 * success = statement:close() 45 * success = statement:close()
31 */ 46 */
32 static int statement_close(lua_State *L) { 47 static int statement_close(lua_State *L) {
160 error_message = DBI_ERR_BINDING_EXEC; 175 error_message = DBI_ERR_BINDING_EXEC;
161 goto cleanup; 176 goto cleanup;
162 } 177 }
163 178
164 metadata = mysql_stmt_result_metadata(statement->stmt); 179 metadata = mysql_stmt_result_metadata(statement->stmt);
180
181 if (metadata) {
182 mysql_stmt_store_result(statement->stmt);
183 }
165 184
166 cleanup: 185 cleanup:
167 /* 186 /*
168 * free the buffer with a resize to 0 187 * free the buffer with a resize to 0
169 */ 188 */
313 332
314 return statement_fetch_impl(L, statement, named_columns); 333 return statement_fetch_impl(L, statement, named_columns);
315 } 334 }
316 335
317 /* 336 /*
337 * num_rows = statement:rowcount()
338 */
339 static int statement_rowcount(lua_State *L) {
340 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT);
341
342 if (!statement->stmt) {
343 luaL_error(L, DBI_ERR_INVALID_STATEMENT);
344 }
345
346 lua_pushinteger(L, mysql_stmt_num_rows(statement->stmt));
347
348 return 1;
349 }
350
351 /*
318 * iterfunc = statement:rows(named_indexes) 352 * iterfunc = statement:rows(named_indexes)
319 */ 353 */
320
321 static int statement_rows(lua_State *L) { 354 static int statement_rows(lua_State *L) {
322 if (lua_gettop(L) == 1) { 355 if (lua_gettop(L) == 1) {
323 lua_pushvalue(L, 1); 356 lua_pushvalue(L, 1);
324 lua_pushboolean(L, 0); 357 lua_pushboolean(L, 0);
325 } else { 358 } else {
371 return 1; 404 return 1;
372 } 405 }
373 406
374 int dbd_mysql_statement(lua_State *L) { 407 int dbd_mysql_statement(lua_State *L) {
375 static const luaL_Reg statement_methods[] = { 408 static const luaL_Reg statement_methods[] = {
409 {"affected", statement_affected},
376 {"close", statement_close}, 410 {"close", statement_close},
377 {"execute", statement_execute}, 411 {"execute", statement_execute},
378 {"fetch", statement_fetch}, 412 {"fetch", statement_fetch},
413 {"rowcount", statement_rowcount},
379 {"rows", statement_rows}, 414 {"rows", statement_rows},
380 {NULL, NULL} 415 {NULL, NULL}
381 }; 416 };
382 417
383 static const luaL_Reg statement_class_methods[] = { 418 static const luaL_Reg statement_class_methods[] = {

mercurial