| 2620 | return dbstmt; |
| 2621 | } |
| 2622 | static int dbtable_where(lua_State *lua) |
| 2623 | { |
| 2624 | SP sp = getsp(lua); |
| 2625 | |
| 2626 | int nargs = lua_gettop(lua); |
| 2627 | if (nargs != 2) { |
| 2628 | luabb_error(lua, sp, "wrong number of arguments to 'where'"); |
| 2629 | return 2; |
| 2630 | } |
| 2631 | luaL_checkudata(lua, 1, dbtypes.dbtable); |
| 2632 | |
| 2633 | const dbtable_t *tbl = lua_topointer(lua, 1); |
| 2634 | char n1[MAXTABLELEN], separator[2], n2[MAXTABLELEN]; |
| 2635 | query_tbl_name(tbl->table_name, n1, separator, n2); |
| 2636 | const char *condition = lua_tostring(lua, 2); |
| 2637 | strbuf *sql = strbuf_new(); |
| 2638 | if (condition && strlen(condition)) |
| 2639 | strbuf_appendf(sql, "select * from %s%s\"%s\" where %s", n1, separator, |
| 2640 | n2, condition); |
| 2641 | else |
| 2642 | strbuf_appendf(sql, "select * from %s%s\"%s\"", n1, separator, n2); |
| 2643 | db_reset(lua); |
| 2644 | sqlite3_stmt *stmt = NULL; |
| 2645 | int rc = lua_prepare_sql(sp, strbuf_buf(sql), &stmt); |
| 2646 | strbuf_free(sql); |
| 2647 | if (rc) { |
| 2648 | lua_pushnil(lua); |
| 2649 | lua_pushinteger(lua, rc); /* Failure return code. */ |
| 2650 | return 2; |
| 2651 | } |
| 2652 | new_dbstmt(lua, sp, stmt); |
| 2653 | lua_pushnumber(lua, 0); |
| 2654 | return 2; |
| 2655 | } |
| 2656 | |
| 2657 | static inline const char *bad_handle() |
| 2658 | { |
nothing calls this directly
no test coverage detected