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
f3576c33
Commit
f3576c33
authored
Oct 08, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cosmetic changes to dblink.
parent
7d937cd4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
45 deletions
+46
-45
contrib/dblink/dblink.c
contrib/dblink/dblink.c
+46
-45
No files found.
contrib/dblink/dblink.c
View file @
f3576c33
...
@@ -60,9 +60,10 @@
...
@@ -60,9 +60,10 @@
typedef
struct
remoteConn
typedef
struct
remoteConn
{
{
PGconn
*
con
;
/* Hold the remote connection */
PGconn
*
conn
;
/* Hold the remote connection */
bool
remoteTrFlag
;
/* Indicates whether or not a transaction
int
autoXactCursors
;
/* Indicates the number of open cursors,
* on remote database is in progress */
* non-zero means we opened the xact
* ourselves */
}
remoteConn
;
}
remoteConn
;
/*
/*
...
@@ -70,7 +71,7 @@ typedef struct remoteConn
...
@@ -70,7 +71,7 @@ typedef struct remoteConn
*/
*/
static
remoteConn
*
getConnectionByName
(
const
char
*
name
);
static
remoteConn
*
getConnectionByName
(
const
char
*
name
);
static
HTAB
*
createConnHash
(
void
);
static
HTAB
*
createConnHash
(
void
);
static
void
createNewConnection
(
const
char
*
name
,
remoteConn
*
co
n
);
static
void
createNewConnection
(
const
char
*
name
,
remoteConn
*
rcon
n
);
static
void
deleteConnection
(
const
char
*
name
);
static
void
deleteConnection
(
const
char
*
name
);
static
char
**
get_pkey_attnames
(
Oid
relid
,
int16
*
numatts
);
static
char
**
get_pkey_attnames
(
Oid
relid
,
int16
*
numatts
);
static
char
*
get_sql_insert
(
Oid
relid
,
int2vector
*
pkattnums
,
int16
pknumatts
,
char
**
src_pkattvals
,
char
**
tgt_pkattvals
);
static
char
*
get_sql_insert
(
Oid
relid
,
int2vector
*
pkattnums
,
int16
pknumatts
,
char
**
src_pkattvals
,
char
**
tgt_pkattvals
);
...
@@ -99,7 +100,7 @@ much like ecpg e.g. a mapping between a name and a PGconn object.
...
@@ -99,7 +100,7 @@ much like ecpg e.g. a mapping between a name and a PGconn object.
typedef
struct
remoteConnHashEnt
typedef
struct
remoteConnHashEnt
{
{
char
name
[
NAMEDATALEN
];
char
name
[
NAMEDATALEN
];
remoteConn
*
rcon
;
remoteConn
*
rcon
n
;
}
remoteConnHashEnt
;
}
remoteConnHashEnt
;
/* initial number of connection hashes */
/* initial number of connection hashes */
...
@@ -162,10 +163,10 @@ typedef struct remoteConnHashEnt
...
@@ -162,10 +163,10 @@ typedef struct remoteConnHashEnt
#define DBLINK_GET_CONN \
#define DBLINK_GET_CONN \
do { \
do { \
char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
rcon = getConnectionByName(conname_or_str); \
rcon
n
= getConnectionByName(conname_or_str); \
if(rcon) \
if(rcon
n
) \
{ \
{ \
conn = rcon
->co
n; \
conn = rcon
n->con
n; \
} \
} \
else \
else \
{ \
{ \
...
@@ -197,7 +198,7 @@ dblink_connect(PG_FUNCTION_ARGS)
...
@@ -197,7 +198,7 @@ dblink_connect(PG_FUNCTION_ARGS)
char
*
msg
;
char
*
msg
;
MemoryContext
oldcontext
;
MemoryContext
oldcontext
;
PGconn
*
conn
=
NULL
;
PGconn
*
conn
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
if
(
PG_NARGS
()
==
2
)
if
(
PG_NARGS
()
==
2
)
{
{
...
@@ -210,7 +211,7 @@ dblink_connect(PG_FUNCTION_ARGS)
...
@@ -210,7 +211,7 @@ dblink_connect(PG_FUNCTION_ARGS)
oldcontext
=
MemoryContextSwitchTo
(
TopMemoryContext
);
oldcontext
=
MemoryContextSwitchTo
(
TopMemoryContext
);
if
(
connname
)
if
(
connname
)
rcon
=
(
remoteConn
*
)
palloc
(
sizeof
(
remoteConn
));
rcon
n
=
(
remoteConn
*
)
palloc
(
sizeof
(
remoteConn
));
conn
=
PQconnectdb
(
connstr
);
conn
=
PQconnectdb
(
connstr
);
MemoryContextSwitchTo
(
oldcontext
);
MemoryContextSwitchTo
(
oldcontext
);
...
@@ -219,8 +220,8 @@ dblink_connect(PG_FUNCTION_ARGS)
...
@@ -219,8 +220,8 @@ dblink_connect(PG_FUNCTION_ARGS)
{
{
msg
=
pstrdup
(
PQerrorMessage
(
conn
));
msg
=
pstrdup
(
PQerrorMessage
(
conn
));
PQfinish
(
conn
);
PQfinish
(
conn
);
if
(
rcon
)
if
(
rcon
n
)
pfree
(
rcon
);
pfree
(
rcon
n
);
ereport
(
ERROR
,
ereport
(
ERROR
,
(
errcode
(
ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
),
(
errcode
(
ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
),
...
@@ -230,8 +231,8 @@ dblink_connect(PG_FUNCTION_ARGS)
...
@@ -230,8 +231,8 @@ dblink_connect(PG_FUNCTION_ARGS)
if
(
connname
)
if
(
connname
)
{
{
rcon
->
co
n
=
conn
;
rcon
n
->
con
n
=
conn
;
createNewConnection
(
connname
,
rcon
);
createNewConnection
(
connname
,
rcon
n
);
}
}
else
else
persistent_conn
=
conn
;
persistent_conn
=
conn
;
...
@@ -247,15 +248,15 @@ Datum
...
@@ -247,15 +248,15 @@ Datum
dblink_disconnect
(
PG_FUNCTION_ARGS
)
dblink_disconnect
(
PG_FUNCTION_ARGS
)
{
{
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
PGconn
*
conn
=
NULL
;
PGconn
*
conn
=
NULL
;
if
(
PG_NARGS
()
==
1
)
if
(
PG_NARGS
()
==
1
)
{
{
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
else
else
conn
=
persistent_conn
;
conn
=
persistent_conn
;
...
@@ -264,10 +265,10 @@ dblink_disconnect(PG_FUNCTION_ARGS)
...
@@ -264,10 +265,10 @@ dblink_disconnect(PG_FUNCTION_ARGS)
DBLINK_CONN_NOT_AVAIL
;
DBLINK_CONN_NOT_AVAIL
;
PQfinish
(
conn
);
PQfinish
(
conn
);
if
(
rcon
)
if
(
rcon
n
)
{
{
deleteConnection
(
conname
);
deleteConnection
(
conname
);
pfree
(
rcon
);
pfree
(
rcon
n
);
}
}
else
else
persistent_conn
=
NULL
;
persistent_conn
=
NULL
;
...
@@ -289,7 +290,7 @@ dblink_open(PG_FUNCTION_ARGS)
...
@@ -289,7 +290,7 @@ dblink_open(PG_FUNCTION_ARGS)
char
*
sql
=
NULL
;
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
StringInfo
str
=
makeStringInfo
();
StringInfo
str
=
makeStringInfo
();
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible behavior */
bool
fail
=
true
;
/* default to backward compatible behavior */
if
(
PG_NARGS
()
==
2
)
if
(
PG_NARGS
()
==
2
)
...
@@ -314,9 +315,9 @@ dblink_open(PG_FUNCTION_ARGS)
...
@@ -314,9 +315,9 @@ dblink_open(PG_FUNCTION_ARGS)
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
}
}
else
if
(
PG_NARGS
()
==
4
)
else
if
(
PG_NARGS
()
==
4
)
...
@@ -326,9 +327,9 @@ dblink_open(PG_FUNCTION_ARGS)
...
@@ -326,9 +327,9 @@ dblink_open(PG_FUNCTION_ARGS)
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
fail
=
PG_GETARG_BOOL
(
3
);
fail
=
PG_GETARG_BOOL
(
3
);
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
if
(
!
conn
)
if
(
!
conn
)
...
@@ -370,7 +371,7 @@ dblink_close(PG_FUNCTION_ARGS)
...
@@ -370,7 +371,7 @@ dblink_close(PG_FUNCTION_ARGS)
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
StringInfo
str
=
makeStringInfo
();
StringInfo
str
=
makeStringInfo
();
char
*
msg
;
char
*
msg
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible behavior */
bool
fail
=
true
;
/* default to backward compatible behavior */
if
(
PG_NARGS
()
==
1
)
if
(
PG_NARGS
()
==
1
)
...
@@ -392,9 +393,9 @@ dblink_close(PG_FUNCTION_ARGS)
...
@@ -392,9 +393,9 @@ dblink_close(PG_FUNCTION_ARGS)
{
{
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
}
}
if
(
PG_NARGS
()
==
3
)
if
(
PG_NARGS
()
==
3
)
...
@@ -403,9 +404,9 @@ dblink_close(PG_FUNCTION_ARGS)
...
@@ -403,9 +404,9 @@ dblink_close(PG_FUNCTION_ARGS)
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
fail
=
PG_GETARG_BOOL
(
2
);
fail
=
PG_GETARG_BOOL
(
2
);
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
if
(
!
conn
)
if
(
!
conn
)
...
@@ -454,7 +455,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
...
@@ -454,7 +455,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
PGresult
*
res
=
NULL
;
PGresult
*
res
=
NULL
;
MemoryContext
oldcontext
;
MemoryContext
oldcontext
;
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
/* stuff done only on the first call of the function */
/* stuff done only on the first call of the function */
if
(
SRF_IS_FIRSTCALL
())
if
(
SRF_IS_FIRSTCALL
())
...
@@ -473,9 +474,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
...
@@ -473,9 +474,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
howmany
=
PG_GETARG_INT32
(
2
);
howmany
=
PG_GETARG_INT32
(
2
);
fail
=
PG_GETARG_BOOL
(
3
);
fail
=
PG_GETARG_BOOL
(
3
);
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
else
if
(
PG_NARGS
()
==
3
)
else
if
(
PG_NARGS
()
==
3
)
{
{
...
@@ -493,9 +494,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
...
@@ -493,9 +494,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
howmany
=
PG_GETARG_INT32
(
2
);
howmany
=
PG_GETARG_INT32
(
2
);
rcon
=
getConnectionByName
(
conname
);
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
)
if
(
rcon
n
)
conn
=
rcon
->
co
n
;
conn
=
rcon
n
->
con
n
;
}
}
}
}
else
if
(
PG_NARGS
()
==
2
)
else
if
(
PG_NARGS
()
==
2
)
...
@@ -656,7 +657,7 @@ dblink_record(PG_FUNCTION_ARGS)
...
@@ -656,7 +657,7 @@ dblink_record(PG_FUNCTION_ARGS)
char
*
connstr
=
NULL
;
char
*
connstr
=
NULL
;
char
*
sql
=
NULL
;
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible */
bool
fail
=
true
;
/* default to backward compatible */
/* create a function context for cross-call persistence */
/* create a function context for cross-call persistence */
...
@@ -855,7 +856,7 @@ dblink_exec(PG_FUNCTION_ARGS)
...
@@ -855,7 +856,7 @@ dblink_exec(PG_FUNCTION_ARGS)
char
*
connstr
=
NULL
;
char
*
connstr
=
NULL
;
char
*
sql
=
NULL
;
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
freeconn
=
false
;
bool
freeconn
=
false
;
bool
fail
=
true
;
/* default to backward compatible behavior */
bool
fail
=
true
;
/* default to backward compatible behavior */
...
@@ -2027,7 +2028,7 @@ getConnectionByName(const char *name)
...
@@ -2027,7 +2028,7 @@ getConnectionByName(const char *name)
key
,
HASH_FIND
,
NULL
);
key
,
HASH_FIND
,
NULL
);
if
(
hentry
)
if
(
hentry
)
return
(
hentry
->
rcon
);
return
(
hentry
->
rcon
n
);
return
(
NULL
);
return
(
NULL
);
}
}
...
@@ -2063,7 +2064,7 @@ createNewConnection(const char *name, remoteConn *rconn)
...
@@ -2063,7 +2064,7 @@ createNewConnection(const char *name, remoteConn *rconn)
(
errcode
(
ERRCODE_DUPLICATE_OBJECT
),
(
errcode
(
ERRCODE_DUPLICATE_OBJECT
),
errmsg
(
"duplicate connection name"
)));
errmsg
(
"duplicate connection name"
)));
hentry
->
rcon
=
rconn
;
hentry
->
rcon
n
=
rconn
;
strncpy
(
hentry
->
name
,
name
,
NAMEDATALEN
-
1
);
strncpy
(
hentry
->
name
,
name
,
NAMEDATALEN
-
1
);
}
}
...
...
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