~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/ecpg-lo.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Large Objects</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="ECPG - Embedded SQL in C"
 
16
HREF="ecpg.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="Library Functions"
 
19
HREF="ecpg-library.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="C++ Applications"
 
22
HREF="ecpg-cpp.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="SECT1"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="Library Functions"
 
57
HREF="ecpg-library.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="ECPG - Embedded SQL in C"
 
67
HREF="ecpg.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
>Chapter 33. <SPAN
 
75
CLASS="APPLICATION"
 
76
>ECPG</SPAN
 
77
> - Embedded <ACRONYM
 
78
CLASS="ACRONYM"
 
79
>SQL</ACRONYM
 
80
> in C</TD
 
81
><TD
 
82
WIDTH="10%"
 
83
ALIGN="right"
 
84
VALIGN="top"
 
85
><A
 
86
TITLE="ECPG - Embedded SQL in C"
 
87
HREF="ecpg.html"
 
88
>Fast Forward</A
 
89
></TD
 
90
><TD
 
91
WIDTH="10%"
 
92
ALIGN="right"
 
93
VALIGN="top"
 
94
><A
 
95
TITLE="C++ Applications"
 
96
HREF="ecpg-cpp.html"
 
97
ACCESSKEY="N"
 
98
>Next</A
 
99
></TD
 
100
></TR
 
101
></TABLE
 
102
><HR
 
103
ALIGN="LEFT"
 
104
WIDTH="100%"></DIV
 
105
><DIV
 
106
CLASS="SECT1"
 
107
><H1
 
108
CLASS="SECT1"
 
109
><A
 
110
NAME="ECPG-LO"
 
111
>33.12. Large Objects</A
 
112
></H1
 
113
><P
 
114
>   Large objects are not directly supported by ECPG, but ECPG
 
115
   application can manipulate large objects through the libpq large
 
116
   object functions, obtaining the necessary <TT
 
117
CLASS="TYPE"
 
118
>PGconn</TT
 
119
>
 
120
   object by calling the <CODE
 
121
CLASS="FUNCTION"
 
122
>ECPGget_PGconn()</CODE
 
123
>
 
124
   function.  (However, use of
 
125
   the <CODE
 
126
CLASS="FUNCTION"
 
127
>ECPGget_PGconn()</CODE
 
128
> function and touching
 
129
   <TT
 
130
CLASS="TYPE"
 
131
>PGconn</TT
 
132
> objects directly should be done very carefully
 
133
   and ideally not mixed with other ECPG database access calls.)
 
134
  </P
 
135
><P
 
136
>   For more details about the <CODE
 
137
CLASS="FUNCTION"
 
138
>ECPGget_PGconn()</CODE
 
139
>, see
 
140
   <A
 
141
HREF="ecpg-library.html"
 
142
>Section 33.11</A
 
143
>.  For information about the large
 
144
   object function interface, see <A
 
145
HREF="largeobjects.html"
 
146
>Chapter 32</A
 
147
>.
 
148
  </P
 
149
><P
 
150
>   Large object functions have to be called in a transaction block, so
 
151
   when autocommit is off, <TT
 
152
CLASS="COMMAND"
 
153
>BEGIN</TT
 
154
> commands have to
 
155
   be isssued explicitly.
 
156
  </P
 
157
><P
 
158
>   <A
 
159
HREF="ecpg-lo.html#ECPG-LO-EXAMPLE"
 
160
>Example 33-2</A
 
161
> shows an example program that
 
162
   illustrates how to create, write, and read a large object in an
 
163
   ECPG application.
 
164
  </P
 
165
><DIV
 
166
CLASS="EXAMPLE"
 
167
><A
 
168
NAME="ECPG-LO-EXAMPLE"
 
169
></A
 
170
><P
 
171
><B
 
172
>Example 33-2. ECPG Program Accessing Large Objects</B
 
173
></P
 
174
><PRE
 
175
CLASS="PROGRAMLISTING"
 
176
>#include &#60;stdio.h&#62;
 
177
#include &#60;stdlib.h&#62;
 
178
#include &#60;libpq-fe.h&#62;
 
179
#include &#60;libpq/libpq-fs.h&#62;
 
180
 
 
181
EXEC SQL WHENEVER SQLERROR STOP;
 
182
 
 
183
int
 
184
main(void)
 
185
{
 
186
    PGconn     *conn;
 
187
    Oid         loid;
 
188
    int         fd;
 
189
    char        buf[256];
 
190
    int         buflen = 256;
 
191
    char        buf2[256];
 
192
    int         rc;
 
193
 
 
194
    memset(buf, 1, buflen);
 
195
 
 
196
    EXEC SQL CONNECT TO testdb AS con1;
 
197
 
 
198
    conn = ECPGget_PGconn("con1");
 
199
    printf("conn = %p\n", conn);
 
200
 
 
201
    /* create */
 
202
    loid = lo_create(conn, 0);
 
203
    if (loid &#60; 0)
 
204
        printf("lo_create() failed: %s", PQerrorMessage(conn));
 
205
 
 
206
    printf("loid = %d\n", loid);
 
207
 
 
208
    /* write test */
 
209
    fd = lo_open(conn, loid, INV_READ|INV_WRITE);
 
210
    if (fd &#60; 0)
 
211
        printf("lo_open() failed: %s", PQerrorMessage(conn));
 
212
 
 
213
    printf("fd = %d\n", fd);
 
214
 
 
215
    rc = lo_write(conn, fd, buf, buflen);
 
216
    if (rc &#60; 0)
 
217
        printf("lo_write() failed\n");
 
218
 
 
219
    rc = lo_close(conn, fd);
 
220
    if (rc &#60; 0)
 
221
        printf("lo_close() failed: %s", PQerrorMessage(conn));
 
222
 
 
223
    /* read test */
 
224
    fd = lo_open(conn, loid, INV_READ);
 
225
    if (fd &#60; 0)
 
226
        printf("lo_open() failed: %s", PQerrorMessage(conn));
 
227
 
 
228
    printf("fd = %d\n", fd);
 
229
 
 
230
    rc = lo_read(conn, fd, buf2, buflen);
 
231
    if (rc &#60; 0)
 
232
        printf("lo_read() failed\n");
 
233
 
 
234
    rc = lo_close(conn, fd);
 
235
    if (rc &#60; 0)
 
236
        printf("lo_close() failed: %s", PQerrorMessage(conn));
 
237
 
 
238
    /* check */
 
239
    rc = memcmp(buf, buf2, buflen);
 
240
    printf("memcmp() = %d\n", rc);
 
241
 
 
242
    /* cleanup */
 
243
    rc = lo_unlink(conn, loid);
 
244
    if (rc &#60; 0)
 
245
        printf("lo_unlink() failed: %s", PQerrorMessage(conn));
 
246
 
 
247
    EXEC SQL COMMIT;
 
248
    EXEC SQL DISCONNECT ALL;
 
249
    return 0;
 
250
}</PRE
 
251
></DIV
 
252
></DIV
 
253
><DIV
 
254
CLASS="NAVFOOTER"
 
255
><HR
 
256
ALIGN="LEFT"
 
257
WIDTH="100%"><TABLE
 
258
SUMMARY="Footer navigation table"
 
259
WIDTH="100%"
 
260
BORDER="0"
 
261
CELLPADDING="0"
 
262
CELLSPACING="0"
 
263
><TR
 
264
><TD
 
265
WIDTH="33%"
 
266
ALIGN="left"
 
267
VALIGN="top"
 
268
><A
 
269
HREF="ecpg-library.html"
 
270
ACCESSKEY="P"
 
271
>Prev</A
 
272
></TD
 
273
><TD
 
274
WIDTH="34%"
 
275
ALIGN="center"
 
276
VALIGN="top"
 
277
><A
 
278
HREF="index.html"
 
279
ACCESSKEY="H"
 
280
>Home</A
 
281
></TD
 
282
><TD
 
283
WIDTH="33%"
 
284
ALIGN="right"
 
285
VALIGN="top"
 
286
><A
 
287
HREF="ecpg-cpp.html"
 
288
ACCESSKEY="N"
 
289
>Next</A
 
290
></TD
 
291
></TR
 
292
><TR
 
293
><TD
 
294
WIDTH="33%"
 
295
ALIGN="left"
 
296
VALIGN="top"
 
297
>Library Functions</TD
 
298
><TD
 
299
WIDTH="34%"
 
300
ALIGN="center"
 
301
VALIGN="top"
 
302
><A
 
303
HREF="ecpg.html"
 
304
ACCESSKEY="U"
 
305
>Up</A
 
306
></TD
 
307
><TD
 
308
WIDTH="33%"
 
309
ALIGN="right"
 
310
VALIGN="top"
 
311
><ACRONYM
 
312
CLASS="ACRONYM"
 
313
>C++</ACRONYM
 
314
> Applications</TD
 
315
></TR
 
316
></TABLE
 
317
></DIV
 
318
></BODY
 
319
></HTML
 
320
>
 
 
b'\\ No newline at end of file'