4 Large objects are not directly supported by ECPG, but ECPG application
5 can manipulate large objects through the libpq large object functions,
6 obtaining the necessary PGconn object by calling the ECPGget_PGconn()
7 function. (However, use of the ECPGget_PGconn() function and touching
8 PGconn objects directly should be done very carefully and ideally not
9 mixed with other ECPG database access calls.)
11 For more details about the ECPGget_PGconn(), see Section 34.11. For
12 information about the large object function interface, see Chapter 33.
14 Large object functions have to be called in a transaction block, so
15 when autocommit is off, BEGIN commands have to be issued explicitly.
17 Example 34.2 shows an example program that illustrates how to create,
18 write, and read a large object in an ECPG application.
20 Example 34.2. ECPG Program Accessing Large Objects
24 #include <libpq/libpq-fs.h>
26 EXEC SQL WHENEVER SQLERROR STOP;
39 memset(buf, 1, buflen);
41 EXEC SQL CONNECT TO testdb AS con1;
42 EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL CO
45 conn = ECPGget_PGconn("con1");
46 printf("conn = %p\n", conn);
49 loid = lo_create(conn, 0);
51 printf("lo_create() failed: %s", PQerrorMessage(conn));
53 printf("loid = %d\n", loid);
56 fd = lo_open(conn, loid, INV_READ|INV_WRITE);
58 printf("lo_open() failed: %s", PQerrorMessage(conn));
60 printf("fd = %d\n", fd);
62 rc = lo_write(conn, fd, buf, buflen);
64 printf("lo_write() failed\n");
66 rc = lo_close(conn, fd);
68 printf("lo_close() failed: %s", PQerrorMessage(conn));
71 fd = lo_open(conn, loid, INV_READ);
73 printf("lo_open() failed: %s", PQerrorMessage(conn));
75 printf("fd = %d\n", fd);
77 rc = lo_read(conn, fd, buf2, buflen);
79 printf("lo_read() failed\n");
81 rc = lo_close(conn, fd);
83 printf("lo_close() failed: %s", PQerrorMessage(conn));
86 rc = memcmp(buf, buf2, buflen);
87 printf("memcmp() = %d\n", rc);
90 rc = lo_unlink(conn, loid);
92 printf("lo_unlink() failed: %s", PQerrorMessage(conn));
95 EXEC SQL DISCONNECT ALL;