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 @@
typedef
struct
remoteConn
{
PGconn
*
con
;
/* Hold the remote connection */
bool
remoteTrFlag
;
/* Indicates whether or not a transaction
* on remote database is in progress */
PGconn
*
conn
;
/* Hold the remote connection */
int
autoXactCursors
;
/* Indicates the number of open cursors,
* non-zero means we opened the xact
* ourselves */
}
remoteConn
;
/*
...
...
@@ -70,7 +71,7 @@ typedef struct remoteConn
*/
static
remoteConn
*
getConnectionByName
(
const
char
*
name
);
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
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
);
...
...
@@ -99,7 +100,7 @@ much like ecpg e.g. a mapping between a name and a PGconn object.
typedef
struct
remoteConnHashEnt
{
char
name
[
NAMEDATALEN
];
remoteConn
*
rcon
;
remoteConn
*
rcon
n
;
}
remoteConnHashEnt
;
/* initial number of connection hashes */
...
...
@@ -162,10 +163,10 @@ typedef struct remoteConnHashEnt
#define DBLINK_GET_CONN \
do { \
char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
rcon = getConnectionByName(conname_or_str); \
if(rcon) \
rcon
n
= getConnectionByName(conname_or_str); \
if(rcon
n
) \
{ \
conn = rcon
->co
n; \
conn = rcon
n->con
n; \
} \
else \
{ \
...
...
@@ -197,7 +198,7 @@ dblink_connect(PG_FUNCTION_ARGS)
char
*
msg
;
MemoryContext
oldcontext
;
PGconn
*
conn
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
if
(
PG_NARGS
()
==
2
)
{
...
...
@@ -210,7 +211,7 @@ dblink_connect(PG_FUNCTION_ARGS)
oldcontext
=
MemoryContextSwitchTo
(
TopMemoryContext
);
if
(
connname
)
rcon
=
(
remoteConn
*
)
palloc
(
sizeof
(
remoteConn
));
rcon
n
=
(
remoteConn
*
)
palloc
(
sizeof
(
remoteConn
));
conn
=
PQconnectdb
(
connstr
);
MemoryContextSwitchTo
(
oldcontext
);
...
...
@@ -219,8 +220,8 @@ dblink_connect(PG_FUNCTION_ARGS)
{
msg
=
pstrdup
(
PQerrorMessage
(
conn
));
PQfinish
(
conn
);
if
(
rcon
)
pfree
(
rcon
);
if
(
rcon
n
)
pfree
(
rcon
n
);
ereport
(
ERROR
,
(
errcode
(
ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
),
...
...
@@ -230,8 +231,8 @@ dblink_connect(PG_FUNCTION_ARGS)
if
(
connname
)
{
rcon
->
co
n
=
conn
;
createNewConnection
(
connname
,
rcon
);
rcon
n
->
con
n
=
conn
;
createNewConnection
(
connname
,
rcon
n
);
}
else
persistent_conn
=
conn
;
...
...
@@ -247,15 +248,15 @@ Datum
dblink_disconnect
(
PG_FUNCTION_ARGS
)
{
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
PGconn
*
conn
=
NULL
;
if
(
PG_NARGS
()
==
1
)
{
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
else
conn
=
persistent_conn
;
...
...
@@ -264,10 +265,10 @@ dblink_disconnect(PG_FUNCTION_ARGS)
DBLINK_CONN_NOT_AVAIL
;
PQfinish
(
conn
);
if
(
rcon
)
if
(
rcon
n
)
{
deleteConnection
(
conname
);
pfree
(
rcon
);
pfree
(
rcon
n
);
}
else
persistent_conn
=
NULL
;
...
...
@@ -289,7 +290,7 @@ dblink_open(PG_FUNCTION_ARGS)
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
StringInfo
str
=
makeStringInfo
();
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible behavior */
if
(
PG_NARGS
()
==
2
)
...
...
@@ -314,9 +315,9 @@ dblink_open(PG_FUNCTION_ARGS)
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
}
else
if
(
PG_NARGS
()
==
4
)
...
...
@@ -326,9 +327,9 @@ dblink_open(PG_FUNCTION_ARGS)
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
sql
=
GET_STR
(
PG_GETARG_TEXT_P
(
2
));
fail
=
PG_GETARG_BOOL
(
3
);
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
if
(
!
conn
)
...
...
@@ -370,7 +371,7 @@ dblink_close(PG_FUNCTION_ARGS)
char
*
conname
=
NULL
;
StringInfo
str
=
makeStringInfo
();
char
*
msg
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible behavior */
if
(
PG_NARGS
()
==
1
)
...
...
@@ -392,9 +393,9 @@ dblink_close(PG_FUNCTION_ARGS)
{
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
}
if
(
PG_NARGS
()
==
3
)
...
...
@@ -403,9 +404,9 @@ dblink_close(PG_FUNCTION_ARGS)
conname
=
GET_STR
(
PG_GETARG_TEXT_P
(
0
));
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
fail
=
PG_GETARG_BOOL
(
2
);
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
if
(
!
conn
)
...
...
@@ -454,7 +455,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
PGresult
*
res
=
NULL
;
MemoryContext
oldcontext
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
/* stuff done only on the first call of the function */
if
(
SRF_IS_FIRSTCALL
())
...
...
@@ -473,9 +474,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
howmany
=
PG_GETARG_INT32
(
2
);
fail
=
PG_GETARG_BOOL
(
3
);
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
else
if
(
PG_NARGS
()
==
3
)
{
...
...
@@ -493,9 +494,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
curname
=
GET_STR
(
PG_GETARG_TEXT_P
(
1
));
howmany
=
PG_GETARG_INT32
(
2
);
rcon
=
getConnectionByName
(
conname
);
if
(
rcon
)
conn
=
rcon
->
co
n
;
rcon
n
=
getConnectionByName
(
conname
);
if
(
rcon
n
)
conn
=
rcon
n
->
con
n
;
}
}
else
if
(
PG_NARGS
()
==
2
)
...
...
@@ -656,7 +657,7 @@ dblink_record(PG_FUNCTION_ARGS)
char
*
connstr
=
NULL
;
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
fail
=
true
;
/* default to backward compatible */
/* create a function context for cross-call persistence */
...
...
@@ -855,7 +856,7 @@ dblink_exec(PG_FUNCTION_ARGS)
char
*
connstr
=
NULL
;
char
*
sql
=
NULL
;
char
*
conname
=
NULL
;
remoteConn
*
rcon
=
NULL
;
remoteConn
*
rcon
n
=
NULL
;
bool
freeconn
=
false
;
bool
fail
=
true
;
/* default to backward compatible behavior */
...
...
@@ -2027,7 +2028,7 @@ getConnectionByName(const char *name)
key
,
HASH_FIND
,
NULL
);
if
(
hentry
)
return
(
hentry
->
rcon
);
return
(
hentry
->
rcon
n
);
return
(
NULL
);
}
...
...
@@ -2063,7 +2064,7 @@ createNewConnection(const char *name, remoteConn *rconn)
(
errcode
(
ERRCODE_DUPLICATE_OBJECT
),
errmsg
(
"duplicate connection name"
)));
hentry
->
rcon
=
rconn
;
hentry
->
rcon
n
=
rconn
;
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