MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / dbtable_where

Function dbtable_where

lua/sp.c:2622–2655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2620 return dbstmt;
2621}
2622static 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
2657static inline const char *bad_handle()
2658{

Callers

nothing calls this directly

Calls 15

lua_gettopFunction · 0.85
luabb_errorFunction · 0.85
luaL_checkudataFunction · 0.85
lua_topointerFunction · 0.85
query_tbl_nameFunction · 0.85
db_resetFunction · 0.85
lua_prepare_sqlFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushintegerFunction · 0.85
new_dbstmtFunction · 0.85
lua_pushnumberFunction · 0.85
strbuf_newFunction · 0.50

Tested by

no test coverage detected