Mon, 18 Apr 2022 17:31:45 +0200
handle sql error in pg_remove_res
src/server/plugins/postgresql/pgtest.c | file | annotate | diff | comparison | revisions | |
src/server/plugins/postgresql/vfs.c | file | annotate | diff | comparison | revisions |
--- a/src/server/plugins/postgresql/pgtest.c Mon Apr 18 13:17:50 2022 +0200 +++ b/src/server/plugins/postgresql/pgtest.c Mon Apr 18 17:31:45 2022 +0200 @@ -314,8 +314,8 @@ r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); UCX_TEST_ASSERT(r == 0, "rmdir failed");; - //r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); - //UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); + r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); + UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); UCX_TEST_ASSERT(r == 0, "unlink failed");
--- 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; }