src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 298
8f5c556120a5
parent 297
14cd7137a3a8
child 304
33911d44111d
equal deleted inserted replaced
297:14cd7137a3a8 298:8f5c556120a5
470 int64_t resource_id, 470 int64_t resource_id,
471 Oid oid) 471 Oid oid)
472 { 472 {
473 // create transaction savepoint 473 // create transaction savepoint
474 PGresult *result = PQexec(pg->connection, "savepoint del_res;"); 474 PGresult *result = PQexec(pg->connection, "savepoint del_res;");
475 if(PQresultStatus(result) != PGRES_COMMAND_OK) { 475 ExecStatusType execStatus = PQresultStatus(result);
476 PQclear(result);
477 if(execStatus != PGRES_COMMAND_OK) {
476 return 1; 478 return 1;
477 } 479 }
478 480
479 if(oid > 0) { 481 if(oid > 0) {
480 if(lo_unlink(pg->connection, oid) != 1) { 482 if(lo_unlink(pg->connection, oid) != 1) {
483 // restore savepoint
484 result = PQexec(pg->connection, "rollback to savepoint del_res;");
485 PQclear(result);
481 return 1; // error 486 return 1; // error
482 } 487 }
483 } 488 }
484 489
485 char resid_str[32]; 490 char resid_str[32];
494 params, // parameter value 499 params, // parameter value
495 NULL, 500 NULL,
496 NULL, 501 NULL,
497 0); // 0: result in text format 502 0); // 0: result in text format
498 503
504 execStatus = PQresultStatus(result);
505 PQclear(result);
499 int ret = 0; 506 int ret = 0;
500 if(PQresultStatus(result) != PGRES_COMMAND_OK) { 507
508 if(execStatus != PGRES_COMMAND_OK) {
501 ret = 1; 509 ret = 1;
502 // restore savepoint 510 // restore savepoint
503 result = PQexec(pg->connection, "rollback to savepoint del_res;"); 511 result = PQexec(pg->connection, "rollback to savepoint del_res;");
504 PQclear(result); 512 PQclear(result);
505 } 513 } else {
506 PQclear(result); 514 // we don't need the savepoint anymore
515 result = PQexec(pg->connection, "release savepoint del_res;");
516 PQclear(result);
517 }
518
507 return ret; 519 return ret;
508 } 520 }
509 521
510 int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength) { 522 int pg_update_resource(PgVFS *pg, int64_t resource_id, int64_t contentlength) {
511 char resid_str[32]; 523 char resid_str[32];

mercurial