| 7247 | } |
| 7248 | |
| 7249 | void lua_step(sqlite3_context *context, int argc, sqlite3_value **argv) |
| 7250 | { |
| 7251 | lua_func_arg_t *arg = sqlite3_user_data(context); |
| 7252 | struct sqlthdstate *thd = arg->thd; |
| 7253 | char *spname = arg->name; |
| 7254 | struct sqlclntstate *clnt = thd->sqlthd->clnt; |
| 7255 | char *err = NULL; |
| 7256 | struct sp_state *state = sqlite3_aggregate_context(context, sizeof(*state)); |
| 7257 | if (state->sp == NULL) { |
| 7258 | if (clnt->sp && clnt->sp->lua) { |
| 7259 | if (strcmp(clnt->sp->spname, spname) == 0) { |
| 7260 | // first call and have cached lua vm. |
| 7261 | // reset it by parsing again. |
| 7262 | process_src(clnt->sp->lua, clnt->sp->src, &err); |
| 7263 | } |
| 7264 | } |
| 7265 | } |
| 7266 | if (state->sp != clnt->sp) { |
| 7267 | check_sp(spname, clnt, state); |
| 7268 | } |
| 7269 | int rc = lua_step_int(spname, &err, thd, clnt, context, argc, argv); |
| 7270 | if (rc != 0) { |
| 7271 | sqlite3_result_error(context, err, -1); |
| 7272 | } |
| 7273 | free(err); |
| 7274 | if (state->sp != clnt->sp) { |
| 7275 | if (state->sp) { |
| 7276 | swap_sp(&clnt->sp, &state->sp); |
| 7277 | } else { |
| 7278 | state->sp = clnt->sp; |
| 7279 | } |
| 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | void lua_func(sqlite3_context *context, int argc, sqlite3_value **argv) |
| 7284 | { |
nothing calls this directly
no test coverage detected