Since I have now learned that it is possible to input values in hex in
postgres, I submit this patch to clean up the ugly workaround I did in the
largeobject regression test to try to input hex values. It does not
change the functionality of the test at all, it just makes it more
readable.
In detail, before when I needed to write hex values, for example
0x20000 | 0x40000,
for the flags to lo_open, I would write it:
CAST((2 | 4) * 16^4 AS integer)
Now, I write it:
CAST(x'20000' | x'40000' AS integer)
which is more like the C and other language consumers of the API, and also
is more obvious what I am trying to do, IMHO.
--
Real Programs don't use shared text. Otherwise, how can they use
functions for scratch space after they are finished calling them?
Index: src/test/regress/input/largeobject.source
===================================================================
RCS file:
/home/jeremyd/local/postgres/cvsuproot/pgsql/src/test/regress/input/largeobject.source,v
retrieving revision 1.1
diff -c -r1.1 largeobject.source
*** src/test/regress/input/largeobject.source 20 Jan 2007 17:15:44 -0000
1.1
--- src/test/regress/input/largeobject.source 2 Mar 2007 21:35:32 -0000
***************
*** 14,24 ****
-- lo_open(lobjId oid, mode integer) returns integer
-- The mode parameter to lo_open uses two constants:
! -- INV_READ = 0x20000 = 2 * 16^4
! -- INV_WRITE = 0x40000 = 4 * 16^4
-- The return value is a file descriptor-like value which remains valid for
the
-- transaction.
! UPDATE lotest_stash_values SET fd = lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- loread/lowrite names are wonky, different from other functions which are
lo_*
-- lowrite(fd integer, data bytea) returns integer
--- 14,24 ----
-- lo_open(lobjId oid, mode integer) returns integer
-- The mode parameter to lo_open uses two constants:
! -- INV_READ = 0x20000
! -- INV_WRITE = 0x40000
-- The return value is a file descriptor-like value which remains valid for
the
-- transaction.
! UPDATE lotest_stash_values SET fd = lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- loread/lowrite names are wonky, different from other functions which are
lo_*
-- lowrite(fd integer, data bytea) returns integer
***************
*** 55,61 ****
-- Read out a portion
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- lo_lseek(fd integer, offset integer, whence integer) returns integer
-- offset is in bytes, whence is one of three values:
--- 55,61 ----
-- Read out a portion
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- lo_lseek(fd integer, offset integer, whence integer) returns integer
-- offset is in bytes, whence is one of three values:
***************
*** 92,98 ****
INSERT INTO lotest_stash_values (loid) SELECT
lo_import('@abs_srcdir@/data/tenk.data');
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- with the default BLKSZ, LOBLKSZ = 2048, so this positions us for a block
-- edge case
--- 92,98 ----
INSERT INTO lotest_stash_values (loid) SELECT
lo_import('@abs_srcdir@/data/tenk.data');
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- with the default BLKSZ, LOBLKSZ = 2048, so this positions us for a block
-- edge case
Index: src/test/regress/output/largeobject.source
===================================================================
RCS file:
/home/jeremyd/local/postgres/cvsuproot/pgsql/src/test/regress/output/largeobject.source,v
retrieving revision 1.1
diff -c -r1.1 largeobject.source
*** src/test/regress/output/largeobject.source 20 Jan 2007 17:15:44 -0000
1.1
--- src/test/regress/output/largeobject.source 2 Mar 2007 21:36:24 -0000
***************
*** 11,21 ****
BEGIN;
-- lo_open(lobjId oid, mode integer) returns integer
-- The mode parameter to lo_open uses two constants:
! -- INV_READ = 0x20000 = 2 * 16^4
! -- INV_WRITE = 0x40000 = 4 * 16^4
-- The return value is a file descriptor-like value which remains valid for
the
-- transaction.
! UPDATE lotest_stash_values SET fd = lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- loread/lowrite names are wonky, different from other functions which are
lo_*
-- lowrite(fd integer, data bytea) returns integer
-- the integer is the number of bytes written
--- 11,21 ----
BEGIN;
-- lo_open(lobjId oid, mode integer) returns integer
-- The mode parameter to lo_open uses two constants:
! -- INV_READ = 0x20000
! -- INV_WRITE = 0x40000
-- The return value is a file descriptor-like value which remains valid for
the
-- transaction.
! UPDATE lotest_stash_values SET fd = lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- loread/lowrite names are wonky, different from other functions which are
lo_*
-- lowrite(fd integer, data bytea) returns integer
-- the integer is the number of bytes written
***************
*** 58,64 ****
END;
-- Read out a portion
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- lo_lseek(fd integer, offset integer, whence integer) returns integer
-- offset is in bytes, whence is one of three values:
-- SEEK_SET (= 0) meaning relative to beginning
--- 58,64 ----
END;
-- Read out a portion
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- lo_lseek(fd integer, offset integer, whence integer) returns integer
-- offset is in bytes, whence is one of three values:
-- SEEK_SET (= 0) meaning relative to beginning
***************
*** 127,133 ****
TRUNCATE lotest_stash_values;
INSERT INTO lotest_stash_values (loid) SELECT
lo_import('@abs_srcdir@/data/tenk.data');
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST((2 | 4) * 16^4 AS
integer));
-- with the default BLKSZ, LOBLKSZ = 2048, so this positions us for a block
-- edge case
SELECT lo_lseek(fd, 2030, 0) FROM lotest_stash_values;
--- 127,133 ----
TRUNCATE lotest_stash_values;
INSERT INTO lotest_stash_values (loid) SELECT
lo_import('@abs_srcdir@/data/tenk.data');
BEGIN;
! UPDATE lotest_stash_values SET fd=lo_open(loid, CAST(x'20000' | x'40000' AS
integer));
-- with the default BLKSZ, LOBLKSZ = 2048, so this positions us for a block
-- edge case
SELECT lo_lseek(fd, 2030, 0) FROM lotest_stash_values;
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq