Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
cfbcb6bb
Commit
cfbcb6bb
authored
Nov 21, 2000
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the world safe for unsigned OIDs.
parent
a70e74b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
35 deletions
+28
-35
contrib/lo/lo.c
contrib/lo/lo.c
+17
-24
contrib/lo/lo.sql.in
contrib/lo/lo.sql.in
+11
-11
No files found.
contrib/lo/lo.c
View file @
cfbcb6bb
/*
/*
* PostgreSQL type definitions for managed LargeObjects.
* PostgreSQL type definitions for managed LargeObjects.
*
*
* $
Id: lo.c,v 1.5 2000/11/20 20:36:55
tgl Exp $
* $
Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.6 2000/11/21 21:51:58
tgl Exp $
*
*
*/
*/
#include "postgres.h"
#include <stdio.h>
#include <stdio.h>
#include <postgres.h>
#include "utils/palloc.h"
#include <utils/palloc.h>
/* Required for largeobjects */
/* Required for largeobjects */
#include
<libpq/libpq-fs.h>
#include
"libpq/libpq-fs.h"
#include
<libpq/be-fsstubs.h>
#include
"libpq/be-fsstubs.h"
/* Required for SPI */
/* Required for SPI */
#include
<executor/spi.h>
#include
"executor/spi.h"
/* Required for triggers */
/* Required for triggers */
#include <commands/trigger.h>
#include "commands/trigger.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* required for tolower() */
/*
/*
* This is the internal storage format for managed large objects
* This is the internal storage format for managed large objects
...
@@ -40,7 +43,7 @@ Blob *lo(Oid oid); /* Return Blob based on oid */
...
@@ -40,7 +43,7 @@ Blob *lo(Oid oid); /* Return Blob based on oid */
Datum
lo_manage
(
PG_FUNCTION_ARGS
);
/* Trigger handler */
Datum
lo_manage
(
PG_FUNCTION_ARGS
);
/* Trigger handler */
/*
/*
* This creates a large object, and set
'
s its OID to the value in the
* This creates a large object, and sets its OID to the value in the
* supplied string.
* supplied string.
*
*
* If the string is empty, then a new LargeObject is created, and its oid
* If the string is empty, then a new LargeObject is created, and its oid
...
@@ -55,20 +58,13 @@ lo_in(char *str)
...
@@ -55,20 +58,13 @@ lo_in(char *str)
if
(
strlen
(
str
)
>
0
)
if
(
strlen
(
str
)
>
0
)
{
{
count
=
sscanf
(
str
,
"%u"
,
&
oid
);
count
=
sscanf
(
str
,
"%d"
,
&
oid
);
if
(
count
<
1
)
if
(
count
<
1
)
{
elog
(
ERROR
,
"lo_in: error in parsing
\"
%s
\"
"
,
str
);
elog
(
ERROR
,
"lo_in: error in parsing
\"
%s
\"
"
,
str
);
return
(
NULL
);
}
if
(
oid
<
0
)
if
(
oid
==
InvalidOid
)
{
elog
(
ERROR
,
"lo_in: illegal oid
\"
%s
\"
"
,
str
);
elog
(
ERROR
,
"lo_in: illegal oid
\"
%s
\"
"
,
str
);
return
(
NULL
);
}
}
}
else
else
{
{
...
@@ -79,10 +75,7 @@ lo_in(char *str)
...
@@ -79,10 +75,7 @@ lo_in(char *str)
oid
=
DatumGetObjectId
(
DirectFunctionCall1
(
lo_creat
,
oid
=
DatumGetObjectId
(
DirectFunctionCall1
(
lo_creat
,
Int32GetDatum
(
INV_READ
|
INV_WRITE
)));
Int32GetDatum
(
INV_READ
|
INV_WRITE
)));
if
(
oid
==
InvalidOid
)
if
(
oid
==
InvalidOid
)
{
elog
(
ERROR
,
"lo_in: InvalidOid returned from lo_creat"
);
elog
(
ERROR
,
"lo_in: InvalidOid returned from lo_creat"
);
return
(
NULL
);
}
}
}
result
=
(
Blob
*
)
palloc
(
sizeof
(
Blob
));
result
=
(
Blob
*
)
palloc
(
sizeof
(
Blob
));
...
@@ -104,7 +97,7 @@ lo_out(Blob * addr)
...
@@ -104,7 +97,7 @@ lo_out(Blob * addr)
return
(
NULL
);
return
(
NULL
);
result
=
(
char
*
)
palloc
(
32
);
result
=
(
char
*
)
palloc
(
32
);
sprintf
(
result
,
"%
d
"
,
*
addr
);
sprintf
(
result
,
"%
u
"
,
*
addr
);
return
(
result
);
return
(
result
);
}
}
...
@@ -190,7 +183,7 @@ lo_manage(PG_FUNCTION_ARGS)
...
@@ -190,7 +183,7 @@ lo_manage(PG_FUNCTION_ARGS)
if
((
orig
!=
newv
&&
(
orig
==
NULL
||
newv
==
NULL
))
||
(
orig
!=
NULL
&&
newv
!=
NULL
&&
strcmp
(
orig
,
newv
)))
if
((
orig
!=
newv
&&
(
orig
==
NULL
||
newv
==
NULL
))
||
(
orig
!=
NULL
&&
newv
!=
NULL
&&
strcmp
(
orig
,
newv
)))
DirectFunctionCall1
(
lo_unlink
,
DirectFunctionCall1
(
lo_unlink
,
ObjectIdGetDatum
(
(
Oid
)
atoi
(
orig
)));
ObjectIdGetDatum
(
atooid
(
orig
)));
if
(
newv
)
if
(
newv
)
pfree
(
newv
);
pfree
(
newv
);
...
@@ -211,7 +204,7 @@ lo_manage(PG_FUNCTION_ARGS)
...
@@ -211,7 +204,7 @@ lo_manage(PG_FUNCTION_ARGS)
if
(
orig
!=
NULL
)
if
(
orig
!=
NULL
)
{
{
DirectFunctionCall1
(
lo_unlink
,
DirectFunctionCall1
(
lo_unlink
,
ObjectIdGetDatum
(
(
Oid
)
atoi
(
orig
)));
ObjectIdGetDatum
(
atooid
(
orig
)));
pfree
(
orig
);
pfree
(
orig
);
}
}
...
...
contrib/lo/lo.sql.in
View file @
cfbcb6bb
--
--
-- PostgreSQL code for LargeObjects
-- PostgreSQL code for LargeObjects
--
--
-- $Id: lo.sql.in,v 1.
5 2000/11/20 20:36:55
tgl Exp $
-- $Id: lo.sql.in,v 1.
6 2000/11/21 21:51:58
tgl Exp $
--
--
--
--
-- Create the data type
-- Create the data type
...
@@ -33,6 +33,15 @@ create function lo_oid(lo)
...
@@ -33,6 +33,15 @@ create function lo_oid(lo)
as 'MODULE_PATHNAME'
as 'MODULE_PATHNAME'
language 'c';
language 'c';
-- same function, named to allow it to be used as a type coercion, eg:
-- create table a (image lo);
-- select image::oid from a;
--
create function oid(lo)
returns oid
as 'MODULE_PATHNAME', 'lo_oid'
language 'c';
-- this allows us to convert an oid to a managed lo object
-- this allows us to convert an oid to a managed lo object
-- ie: insert into test values (lo_import('/fullpath/file')::lo);
-- ie: insert into test values (lo_import('/fullpath/file')::lo);
create function lo(oid)
create function lo(oid)
...
@@ -44,13 +53,4 @@ create function lo(oid)
...
@@ -44,13 +53,4 @@ create function lo(oid)
create function lo_manage()
create function lo_manage()
returns opaque
returns opaque
as 'MODULE_PATHNAME'
as 'MODULE_PATHNAME'
language 'C';
language 'c';
-- This allows us to map lo to oid
--
-- eg:
-- create table a (image lo);
-- select image::oid from a;
--
create function oid(lo) returns oid as 'select lo_oid($1)' language 'sql';
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment