~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-security

« back to all changes in this revision

Viewing changes to src/test/regress/output/largeobject.source

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- Test large object support
 
3
--
 
4
-- Load a file
 
5
CREATE TABLE lotest_stash_values (loid oid, fd integer);
 
6
-- lo_creat(mode integer) returns oid
 
7
-- The mode arg to lo_creat is unused, some vestigal holdover from ancient times
 
8
-- returns the large object id
 
9
INSERT INTO lotest_stash_values (loid) SELECT lo_creat(42);
 
10
-- NOTE: large objects require transactions
 
11
BEGIN;
 
12
-- lo_open(lobjId oid, mode integer) returns integer
 
13
-- The mode parameter to lo_open uses two constants:
 
14
--   INV_READ  = 0x20000
 
15
--   INV_WRITE = 0x40000
 
16
-- The return value is a file descriptor-like value which remains valid for the
 
17
-- transaction.
 
18
UPDATE lotest_stash_values SET fd = lo_open(loid, CAST(x'20000' | x'40000' AS integer));
 
19
-- loread/lowrite names are wonky, different from other functions which are lo_*
 
20
-- lowrite(fd integer, data bytea) returns integer
 
21
-- the integer is the number of bytes written
 
22
SELECT lowrite(fd, '
 
23
Whose woods these are I think I know,
 
24
His house is in the village though.
 
25
He will not see me stopping here,
 
26
To watch his woods fill up with snow.
 
27
 
 
28
My little horse must think it queer,
 
29
To stop without a farmhouse near,
 
30
Between the woods and frozen lake,
 
31
The darkest evening of the year.
 
32
 
 
33
He gives his harness bells a shake,
 
34
To ask if there is some mistake.
 
35
The only other sound''s the sweep,
 
36
Of easy wind and downy flake.
 
37
 
 
38
The woods are lovely, dark and deep,
 
39
But I have promises to keep,
 
40
And miles to go before I sleep,
 
41
And miles to go before I sleep.
 
42
 
 
43
         -- Robert Frost
 
44
') FROM lotest_stash_values;
 
45
 lowrite 
 
46
---------
 
47
     578
 
48
(1 row)
 
49
 
 
50
-- lo_close(fd integer) returns integer
 
51
-- return value is 0 for success, or <0 for error (actually only -1, but...)
 
52
SELECT lo_close(fd) FROM lotest_stash_values;
 
53
 lo_close 
 
54
----------
 
55
        0
 
56
(1 row)
 
57
 
 
58
END;
 
59
-- Read out a portion
 
60
BEGIN;
 
61
UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS integer));
 
62
-- lo_lseek(fd integer, offset integer, whence integer) returns integer
 
63
-- offset is in bytes, whence is one of three values:
 
64
--  SEEK_SET (= 0) meaning relative to beginning
 
65
--  SEEK_CUR (= 1) meaning relative to current position
 
66
--  SEEK_END (= 2) meaning relative to end (offset better be negative)
 
67
-- returns current position in file
 
68
SELECT lo_lseek(fd, 422, 0) FROM lotest_stash_values;
 
69
 lo_lseek 
 
70
----------
 
71
      422
 
72
(1 row)
 
73
 
 
74
-- loread/lowrite names are wonky, different from other functions which are lo_*
 
75
-- loread(fd integer, len integer) returns bytea
 
76
SELECT loread(fd, 35) FROM lotest_stash_values;
 
77
               loread                
 
78
-------------------------------------
 
79
 The woods are lovely, dark and deep
 
80
(1 row)
 
81
 
 
82
SELECT lo_lseek(fd, -19, 1) FROM lotest_stash_values;
 
83
 lo_lseek 
 
84
----------
 
85
      438
 
86
(1 row)
 
87
 
 
88
SELECT lowrite(fd, 'n') FROM lotest_stash_values;
 
89
 lowrite 
 
90
---------
 
91
       1
 
92
(1 row)
 
93
 
 
94
SELECT lo_tell(fd) FROM lotest_stash_values;
 
95
 lo_tell 
 
96
---------
 
97
     439
 
98
(1 row)
 
99
 
 
100
SELECT lo_lseek(fd, -156, 2) FROM lotest_stash_values;
 
101
 lo_lseek 
 
102
----------
 
103
      422
 
104
(1 row)
 
105
 
 
106
SELECT loread(fd, 35) FROM lotest_stash_values;
 
107
               loread                
 
108
-------------------------------------
 
109
 The woods are lonely, dark and deep
 
110
(1 row)
 
111
 
 
112
SELECT lo_close(fd) FROM lotest_stash_values;
 
113
 lo_close 
 
114
----------
 
115
        0
 
116
(1 row)
 
117
 
 
118
END;
 
119
-- Test resource management
 
120
BEGIN;
 
121
SELECT lo_open(loid, x'40000'::int) from lotest_stash_values;
 
122
 lo_open 
 
123
---------
 
124
       0
 
125
(1 row)
 
126
 
 
127
ABORT;
 
128
-- Test truncation.
 
129
BEGIN;
 
130
UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS integer));
 
131
SELECT lo_truncate(fd, 10) FROM lotest_stash_values;
 
132
 lo_truncate 
 
133
-------------
 
134
           0
 
135
(1 row)
 
136
 
 
137
SELECT loread(fd, 15) FROM lotest_stash_values;
 
138
    loread     
 
139
---------------
 
140
 \012Whose woo
 
141
(1 row)
 
142
 
 
143
SELECT lo_truncate(fd, 10000) FROM lotest_stash_values;
 
144
 lo_truncate 
 
145
-------------
 
146
           0
 
147
(1 row)
 
148
 
 
149
SELECT loread(fd, 10) FROM lotest_stash_values;
 
150
                  loread                  
 
151
------------------------------------------
 
152
 \000\000\000\000\000\000\000\000\000\000
 
153
(1 row)
 
154
 
 
155
SELECT lo_lseek(fd, 0, 2) FROM lotest_stash_values;
 
156
 lo_lseek 
 
157
----------
 
158
    10000
 
159
(1 row)
 
160
 
 
161
SELECT lo_tell(fd) FROM lotest_stash_values;
 
162
 lo_tell 
 
163
---------
 
164
   10000
 
165
(1 row)
 
166
 
 
167
SELECT lo_truncate(fd, 5000) FROM lotest_stash_values;
 
168
 lo_truncate 
 
169
-------------
 
170
           0
 
171
(1 row)
 
172
 
 
173
SELECT lo_lseek(fd, 0, 2) FROM lotest_stash_values;
 
174
 lo_lseek 
 
175
----------
 
176
     5000
 
177
(1 row)
 
178
 
 
179
SELECT lo_tell(fd) FROM lotest_stash_values;
 
180
 lo_tell 
 
181
---------
 
182
    5000
 
183
(1 row)
 
184
 
 
185
SELECT lo_close(fd) FROM lotest_stash_values;
 
186
 lo_close 
 
187
----------
 
188
        0
 
189
(1 row)
 
190
 
 
191
END;
 
192
-- lo_unlink(lobjId oid) returns integer
 
193
-- return value appears to always be 1
 
194
SELECT lo_unlink(loid) from lotest_stash_values;
 
195
 lo_unlink 
 
196
-----------
 
197
         1
 
198
(1 row)
 
199
 
 
200
TRUNCATE lotest_stash_values;
 
201
INSERT INTO lotest_stash_values (loid) SELECT lo_import('@abs_srcdir@/data/tenk.data');
 
202
BEGIN;
 
203
UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS integer));
 
204
-- with the default BLKSZ, LOBLKSZ = 2048, so this positions us for a block
 
205
-- edge case
 
206
SELECT lo_lseek(fd, 2030, 0) FROM lotest_stash_values;
 
207
 lo_lseek 
 
208
----------
 
209
     2030
 
210
(1 row)
 
211
 
 
212
-- this should get half of the value from page 0 and half from page 1 of the
 
213
-- large object
 
214
SELECT loread(fd, 36) FROM lotest_stash_values;
 
215
                             loread                              
 
216
-----------------------------------------------------------------
 
217
 AAA\011FBAAAA\011VVVVxx\0122513\01132\0111\0111\0113\01113\0111
 
218
(1 row)
 
219
 
 
220
SELECT lo_tell(fd) FROM lotest_stash_values;
 
221
 lo_tell 
 
222
---------
 
223
    2066
 
224
(1 row)
 
225
 
 
226
SELECT lo_lseek(fd, -26, 1) FROM lotest_stash_values;
 
227
 lo_lseek 
 
228
----------
 
229
     2040
 
230
(1 row)
 
231
 
 
232
SELECT lowrite(fd, 'abcdefghijklmnop') FROM lotest_stash_values;
 
233
 lowrite 
 
234
---------
 
235
      16
 
236
(1 row)
 
237
 
 
238
SELECT lo_lseek(fd, 2030, 0) FROM lotest_stash_values;
 
239
 lo_lseek 
 
240
----------
 
241
     2030
 
242
(1 row)
 
243
 
 
244
SELECT loread(fd, 36) FROM lotest_stash_values;
 
245
                       loread                        
 
246
-----------------------------------------------------
 
247
 AAA\011FBAAAAabcdefghijklmnop1\0111\0113\01113\0111
 
248
(1 row)
 
249
 
 
250
SELECT lo_close(fd) FROM lotest_stash_values;
 
251
 lo_close 
 
252
----------
 
253
        0
 
254
(1 row)
 
255
 
 
256
END;
 
257
SELECT lo_export(loid, '@abs_builddir@/results/lotest.txt') FROM lotest_stash_values;
 
258
 lo_export 
 
259
-----------
 
260
         1
 
261
(1 row)
 
262
 
 
263
\lo_import 'results/lotest.txt'
 
264
\set newloid :LASTOID
 
265
-- just make sure \lo_export does not barf
 
266
\lo_export :newloid 'results/lotest2.txt'
 
267
-- This is a hack to test that export/import are reversible
 
268
-- This uses knowledge about the inner workings of large object mechanism
 
269
-- which should not be used outside it.  This makes it a HACK
 
270
SELECT pageno, data FROM pg_largeobject WHERE loid = (SELECT loid from lotest_stash_values)
 
271
EXCEPT
 
272
SELECT pageno, data FROM pg_largeobject WHERE loid = :newloid;
 
273
 pageno | data 
 
274
--------+------
 
275
(0 rows)
 
276
 
 
277
SELECT lo_unlink(loid) FROM lotest_stash_values;
 
278
 lo_unlink 
 
279
-----------
 
280
         1
 
281
(1 row)
 
282
 
 
283
\lo_unlink :newloid
 
284
TRUNCATE lotest_stash_values;