Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
f3576c33
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f3576c33
编写于
10月 08, 2005
作者:
B
Bruce Momjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cosmetic changes to dblink.
上级
7d937cd4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
45 deletion
+46
-45
contrib/dblink/dblink.c
contrib/dblink/dblink.c
+46
-45
未找到文件。
contrib/dblink/dblink.c
浏览文件 @
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
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录