fluffos/docs/efun/async/async_db_exec.md
Claude b0f61c3313 Preserve this_player() in resolve() and async_* callbacks (#1104)
resolve(), async_read(), async_write(), async_getdir() and
async_db_exec() ran their callbacks with no user context, so
this_player() returned 0 and input_to()/printf() were unusable there.

Follow the call_out() precedent: capture command_giver (ref-held) when
the request is registered and restore it around the callback, skipping
destructed objects, gated on the same 'this_player in call_out'
setting. The pending-request holders account for the new ref in the
DEBUGMALLOC walkers.

The new test registers callbacks from two different living objects and
asserts each callback sees its own registrant, which fails without the
per-request capture.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lv2Gw2AWqtyN3nNEgob1He
2026-07-11 14:56:46 -04:00

957 B
Raw Permalink Blame History

title
async / async_db_exec

async_db_exec

NAME

async_db_exec() - executes an sql statement then executes a callback

SYNOPSIS

void async_db_exec( int handle, string sql_query, function callback );

DESCRIPTION

This function will execute the passed sql statement for the given data
base handle.

Returns the database handle to the callback function provided.

The callback should follow this format:

```c
async_db_exec(
    handle,
    sql_query, 
    function (int rows) { // number of matched rows
        mixed *results = db_fetch(handle, 1);
        db_close(handle);
    }
);
```

NOTE

When the 'this_player in call_out' driver setting is enabled,
this_player() inside the callback is preserved from the time the
request was made, like call_out().

SEE ALSO

db_commit(3), db_exec(3), db_fetch(3), db_rollback(3), valid_database(4)