This runs some Lua code in context of on-going SQL stmt. Should not * start/commit/rollback ongoing transaction. Calling SQL stmt will cleanup on * error. */
| 7018 | * start/commit/rollback ongoing transaction. Calling SQL stmt will cleanup on |
| 7019 | * error. */ |
| 7020 | static int run_func(struct sqlclntstate *clnt, int argcnt, char **err, int final) |
| 7021 | { |
| 7022 | Lua L = clnt->sp->lua; |
| 7023 | int rc = lua_pcall(L, argcnt, LUA_MULTRET, 0); |
| 7024 | join_threads(clnt->sp); |
| 7025 | if (final || rc) { |
| 7026 | reset_stmts(clnt->sp); |
| 7027 | drop_temp_tables(clnt->sp); |
| 7028 | } |
| 7029 | if (rc) { |
| 7030 | if (lua_gettop(L) > 0 && !lua_isnil(L, -1)) { |
| 7031 | *err = strdup(luabb_tostring(L, -1)); |
| 7032 | } else { |
| 7033 | *err = strdup("UDF failed"); |
| 7034 | } |
| 7035 | } |
| 7036 | return rc; |
| 7037 | } |
| 7038 | |
| 7039 | /* TODO: This needs to be more robust - perhaps a hash table of Lua VMs per UDF |
| 7040 | * allowing us to invoke multiple UDFs per SQL statement. Also, test running |
no test coverage detected