dbd/db2/statement.c

changeset 21
7956401a0c5e
parent 19
b5ec612be4da
child 23
a4825c3e65e9
equal deleted inserted replaced
20:5ab0b30f8fbd 21:7956401a0c5e
17 default: 17 default:
18 lua_type = LUA_PUSH_STRING; 18 lua_type = LUA_PUSH_STRING;
19 } 19 }
20 20
21 return lua_type; 21 return lua_type;
22 }
23
24 /*
25 * num_affected_rows = statement:affected()
26 */
27 static int statement_affected(lua_State *L) {
28 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT);
29 SQLRETURN rc = SQL_SUCCESS;
30 SQLINTEGER affected;
31
32 if (!statement->stmt) {
33 luaL_error(L, DBI_ERR_INVALID_STATEMENT);
34 }
35
36 rc = SQLRowCount(statement->stmt, &affected);
37
38
39 lua_pushinteger(L, affected);
40
41 return 1;
22 } 42 }
23 43
24 /* 44 /*
25 * success = statement:close() 45 * success = statement:close()
26 */ 46 */
333 353
334 return statement_fetch_impl(L, statement, named_columns); 354 return statement_fetch_impl(L, statement, named_columns);
335 } 355 }
336 356
337 /* 357 /*
358 * num_rows = statement:rowcount()
359 */
360 static int statement_rowcount(lua_State *L) {
361 luaL_error(L, DBI_ERR_NOT_IMPLEMENTED, DBD_DB2_STATEMENT, "rowcount");
362
363 return 0;
364 }
365
366 /*
338 * iterfunc = statement:rows(named_indexes) 367 * iterfunc = statement:rows(named_indexes)
339 */ 368 */
340 static int statement_rows(lua_State *L) { 369 static int statement_rows(lua_State *L) {
341 if (lua_gettop(L) == 1) { 370 if (lua_gettop(L) == 1) {
342 lua_pushvalue(L, 1); 371 lua_pushvalue(L, 1);
379 return 2; 408 return 2;
380 } 409 }
381 410
382 /* 411 /*
383 * turn off deferred prepare 412 * turn off deferred prepare
384 * statements will be sent to the server at prepare timr, 413 * statements will be sent to the server at prepare time,
385 * and therefor we can catch errors then rather 414 * and therefore we can catch errors now rather
386 * than at execute time 415 * than at execute time
387 */ 416 */
388 rc = SQLSetStmtAttr(stmt,SQL_ATTR_DEFERRED_PREPARE,(SQLPOINTER)SQL_DEFERRED_PREPARE_OFF,0); 417 rc = SQLSetStmtAttr(stmt,SQL_ATTR_DEFERRED_PREPARE,(SQLPOINTER)SQL_DEFERRED_PREPARE_OFF,0);
389 418
390 rc = SQLPrepare(stmt, (SQLCHAR *)sql_query, SQL_NTS); 419 rc = SQLPrepare(stmt, (SQLCHAR *)sql_query, SQL_NTS);
408 return 1; 437 return 1;
409 } 438 }
410 439
411 int dbd_db2_statement(lua_State *L) { 440 int dbd_db2_statement(lua_State *L) {
412 static const luaL_Reg statement_methods[] = { 441 static const luaL_Reg statement_methods[] = {
442 {"affected", statement_affected},
413 {"close", statement_close}, 443 {"close", statement_close},
414 {"execute", statement_execute}, 444 {"execute", statement_execute},
415 {"fetch", statement_fetch}, 445 {"fetch", statement_fetch},
446 {"rowcount", statement_rowcount},
416 {"rows", statement_rows}, 447 {"rows", statement_rows},
417 {NULL, NULL} 448 {NULL, NULL}
418 }; 449 };
419 450
420 static const luaL_Reg statement_class_methods[] = { 451 static const luaL_Reg statement_class_methods[] = {

mercurial