2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2025, PostgreSQL Global Development Group
6 * src/bin/psql/large_obj.c
49 * Prepare to do a large-object operation. We *must* be inside a transaction
50 * block for all these operations, so start one if needed.
52 * Returns true if okay, false if failed. *own_transaction is set to indicate
53 * if we started our own transaction or not.
61 *own_transaction =
false;
65 pg_log_error(
"%s: not connected to a database", operation);
74 /* need to start our own xact */
78 *own_transaction =
true;
81 /* use the existing xact */
84 pg_log_error(
"%s: current transaction is aborted", operation);
87 pg_log_error(
"%s: unknown transaction status", operation);
95 * Clean up after a successful LO operation
104 /* close out our own xact */
118 * Clean up after a failed LO operation
127 /* close out our own xact */
132 return false;
/* always */
139 * Write a large object to a file
145 bool own_transaction;
154 /* of course this status is documented nowhere :( */
173 * Copy large object from file to database
181 bool own_transaction;
196 /* insert description if given */
201 size_t slen = strlen(comment_arg);
206 sprintf(cmdbuf,
"COMMENT ON LARGE OBJECT %u IS '", loid);
207 bufptr = cmdbuf + strlen(cmdbuf);
236 * removes a large object out of the database
243 bool own_transaction;
PGresult * PSQLexec(const char *query)
#define pg_attribute_printf(f, a)
void ResetCancelConn(void)
void SetCancelConn(PGconn *conn)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
int lo_unlink(PGconn *conn, Oid lobjId)
Oid lo_import(PGconn *conn, const char *filename)
int lo_export(PGconn *conn, Oid lobjId, const char *filename)
void * pg_malloc_extended(size_t size, int flags)
#define MCXT_ALLOC_NO_OOM
static bool start_lo_xact(const char *operation, bool *own_transaction)
bool do_lo_export(const char *loid_arg, const char *filename_arg)
static bool fail_lo_xact(const char *operation, bool own_transaction)
static void print_lo_result(const char *fmt,...) pg_attribute_printf(1
static bool finish_lo_xact(const char *operation, bool own_transaction)
bool do_lo_import(const char *filename_arg, const char *comment_arg)
bool do_lo_unlink(const char *loid_arg)
#define pg_log_error(...)
bool SetVariable(VariableSpace space, const char *name, const char *value)