diff -r 78e92337fa4e -r 14cd7137a3a8 src/server/plugins/postgresql/vfs.c --- a/src/server/plugins/postgresql/vfs.c Mon Apr 18 13:17:50 2022 +0200 +++ b/src/server/plugins/postgresql/vfs.c Mon Apr 18 17:31:45 2022 +0200 @@ -470,6 +470,12 @@ int64_t resource_id, Oid oid) { + // create transaction savepoint + PGresult *result = PQexec(pg->connection, "savepoint del_res;"); + if(PQresultStatus(result) != PGRES_COMMAND_OK) { + return 1; + } + if(oid > 0) { if(lo_unlink(pg->connection, oid) != 1) { return 1; // error @@ -480,7 +486,7 @@ snprintf(resid_str, 32, "%" PRId64, resource_id); const char* params[1] = { resid_str }; - PGresult *result = PQexecParams( + result = PQexecParams( pg->connection, sql_delete_res, 1, // number of parameters @@ -490,9 +496,12 @@ NULL, 0); // 0: result in text format - int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; - if(ret == 1) { - fprintf(stdout, "%s", PQerrorMessage(pg->connection)); + int ret = 0; + if(PQresultStatus(result) != PGRES_COMMAND_OK) { + ret = 1; + // restore savepoint + result = PQexec(pg->connection, "rollback to savepoint del_res;"); + PQclear(result); } PQclear(result); return ret; @@ -516,7 +525,7 @@ 0); // 0: result in text format int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; - PQclear(result); + PQclear(result); return ret; }