src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 297
14cd7137a3a8
parent 296
78e92337fa4e
child 298
8f5c556120a5
equal deleted inserted replaced
296:78e92337fa4e 297:14cd7137a3a8
468 VFSContext *ctx, 468 VFSContext *ctx,
469 PgVFS *pg, 469 PgVFS *pg,
470 int64_t resource_id, 470 int64_t resource_id,
471 Oid oid) 471 Oid oid)
472 { 472 {
473 // create transaction savepoint
474 PGresult *result = PQexec(pg->connection, "savepoint del_res;");
475 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
476 return 1;
477 }
478
473 if(oid > 0) { 479 if(oid > 0) {
474 if(lo_unlink(pg->connection, oid) != 1) { 480 if(lo_unlink(pg->connection, oid) != 1) {
475 return 1; // error 481 return 1; // error
476 } 482 }
477 } 483 }
478 484
479 char resid_str[32]; 485 char resid_str[32];
480 snprintf(resid_str, 32, "%" PRId64, resource_id); 486 snprintf(resid_str, 32, "%" PRId64, resource_id);
481 487
482 const char* params[1] = { resid_str }; 488 const char* params[1] = { resid_str };
483 PGresult *result = PQexecParams( 489 result = PQexecParams(
484 pg->connection, 490 pg->connection,
485 sql_delete_res, 491 sql_delete_res,
486 1, // number of parameters 492 1, // number of parameters
487 NULL, 493 NULL,
488 params, // parameter value 494 params, // parameter value
489 NULL, 495 NULL,
490 NULL, 496 NULL,
491 0); // 0: result in text format 497 0); // 0: result in text format
492 498
493 int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; 499 int ret = 0;
494 if(ret == 1) { 500 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
495 fprintf(stdout, "%s", PQerrorMessage(pg->connection)); 501 ret = 1;
502 // restore savepoint
503 result = PQexec(pg->connection, "rollback to savepoint del_res;");
504 PQclear(result);
496 } 505 }
497 PQclear(result); 506 PQclear(result);
498 return ret; 507 return ret;
499 } 508 }
500 509
514 NULL, 523 NULL,
515 NULL, 524 NULL,
516 0); // 0: result in text format 525 0); // 0: result in text format
517 526
518 int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1; 527 int ret = PQresultStatus(result) == PGRES_COMMAND_OK ? 0 : 1;
519 PQclear(result); 528 PQclear(result);
520 return ret; 529 return ret;
521 } 530 }
522 531
523 /* -------------------------- VFS functions -------------------------- */ 532 /* -------------------------- VFS functions -------------------------- */
524 533

mercurial