# HG changeset patch # User Sergey Mironov # Date 1397160188 0 # Thu Apr 10 20:03:08 2014 +0000 # Node ID ed8914c14ee57ade41fce5c516e62bbf3b38dfe1 # Parent bc4f0f329d75e6b1a216834d05cb17b67dfd86a0 Tweak transactional callabcks * Fix missing .free handlers on db_commit failure * Call .commit's (NULL .rollback) _after_ db_commit * Execute .commit's in 0 to MAX order diff --git a/src/c/urweb.c b/src/c/urweb.c --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3294,7 +3294,7 @@ return 0; } - for (i = ctx->used_transactionals-1; i >= 0; --i) + for (i = 0; i < ctx->used_transactionals; i++) if (ctx->transactionals[i].rollback != NULL) if (ctx->transactionals[i].commit) { ctx->transactionals[i].commit(ctx->transactionals[i].data); @@ -3304,32 +3304,37 @@ } } - for (i = ctx->used_transactionals-1; i >= 0; --i) + if (ctx->transaction_started) { + int code = ctx->app->db_commit(ctx); + + if (code) { + + for (i = ctx->used_transactionals-1; i >= 0; --i) + if (ctx->transactionals[i].free) + ctx->transactionals[i].free(ctx->transactionals[i].data, 0); + + if (code == -1) { + if (!uw_has_error(ctx)) + uw_set_error_message(ctx, "Error running SQL COMMIT (code -1)"); + return 1; + } + else { + uw_set_error_message(ctx, "Error running SQL COMMIT"); + return 0; + } + } + } + + for (i = 0; i < ctx->used_transactionals; i++) if (ctx->transactionals[i].rollback == NULL) if (ctx->transactionals[i].commit) { ctx->transactionals[i].commit(ctx->transactionals[i].data); if (uw_has_error(ctx)) { - uw_rollback(ctx, 0); + assert(!uw_has_error(ctx)); return 0; } } - if (ctx->transaction_started) { - int code = ctx->app->db_commit(ctx); - - if (code) { - if (code == -1) - return 1; - - for (i = ctx->used_transactionals-1; i >= 0; --i) - if (ctx->transactionals[i].free) - ctx->transactionals[i].free(ctx->transactionals[i].data, 0); - - uw_set_error_message(ctx, "Error running SQL COMMIT"); - return 0; - } - } - for (i = 0; i < ctx->used_deltas; ++i) { delta *d = &ctx->deltas[i]; client *c = find_client(d->client);