From dd853ba943725718fd9c3922a14ec7ff5954803c Mon Sep 17 00:00:00 2001 From: chenzhikai <895543892@qq.com> Date: Tue, 7 Mar 2023 09:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0odbc=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=88=B0=E5=8C=85=E4=B8=AD=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?dblink=E8=BF=9E=E6=8E=A5=E5=A4=B1=E8=B4=A5=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E8=AF=A6=E6=83=85=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/script/aarch64_opengauss_list | 1 + build/script/opengauss_release_list_mini | 1 + build/script/opengauss_release_list_ubuntu_single | 1 + build/script/x86_64_opengauss_list | 1 + contrib/dblink/dblink.cpp | 13 +++++++++---- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build/script/aarch64_opengauss_list b/build/script/aarch64_opengauss_list index d01ef91ac..814d34976 100644 --- a/build/script/aarch64_opengauss_list +++ b/build/script/aarch64_opengauss_list @@ -835,6 +835,7 @@ ./lib/libpagecompression.so* ./lib/libdssapi.so ./lib/libdms.so +./lib/libodbc.so* ./include/postgresql/server/postgres_ext.h ./include/postgresql/server/pg_config_os.h diff --git a/build/script/opengauss_release_list_mini b/build/script/opengauss_release_list_mini index 435f57b52..58b21a021 100644 --- a/build/script/opengauss_release_list_mini +++ b/build/script/opengauss_release_list_mini @@ -884,6 +884,7 @@ ./lib/postgresql/latin2_and_win1250.so ./lib/postgresql/euc2004_sjis2004.so ./lib/libhll.so +./lib/libodbc.so* ./include/postgresql/server/postgres_ext.h ./include/postgresql/server/pg_config_os.h diff --git a/build/script/opengauss_release_list_ubuntu_single b/build/script/opengauss_release_list_ubuntu_single index 62c2733a6..fe76edc68 100644 --- a/build/script/opengauss_release_list_ubuntu_single +++ b/build/script/opengauss_release_list_ubuntu_single @@ -887,6 +887,7 @@ ./lib/postgresql/latin2_and_win1250.so ./lib/postgresql/euc2004_sjis2004.so ./lib/libhll.so +./lib/libodbc.so* ./include/postgresql/server/postgres_ext.h ./include/postgresql/server/pg_config_os.h diff --git a/build/script/x86_64_opengauss_list b/build/script/x86_64_opengauss_list index 2c7a57df3..014186a34 100644 --- a/build/script/x86_64_opengauss_list +++ b/build/script/x86_64_opengauss_list @@ -832,6 +832,7 @@ ./lib/libpagecompression.so* ./lib/libdssapi.so ./lib/libdms.so +./lib/libodbc.so* ./include/postgresql/server/postgres_ext.h ./include/postgresql/server/pg_config_os.h diff --git a/contrib/dblink/dblink.cpp b/contrib/dblink/dblink.cpp index e894eeaea..9c7d148d8 100644 --- a/contrib/dblink/dblink.cpp +++ b/contrib/dblink/dblink.cpp @@ -106,6 +106,7 @@ static bool UseODBCLinker(char* connstr); #define REMOTE_CONN_HASH (get_session_context()->remoteConnHash) /* initial number of connection hashes */ #define NUMCONN 16 +#define NAX_ERR_MSG_LEN 1000 #define MAX_BUF_LEN 100000 #define MAX_DRIVERNAME_LEN 50 #define DBLINK_NOTIFY_COLS 3 @@ -559,6 +560,9 @@ ODBCLinker::ODBCLinker(char* connstr_or_name) } LinkInfo linfo; + linfo.drivername = NULL; + linfo.password = NULL; + linfo.username = NULL; int len = strlen(connstr_or_name); GetDrivername(connstr_or_name, &linfo); /* atuo commit is the default value */ @@ -568,11 +572,13 @@ ODBCLinker::ODBCLinker(char* connstr_or_name) securec_check(rc, "\0", "\0"); if ((error != SQL_SUCCESS) && (error != SQL_SUCCESS_WITH_INFO)) { + SQLCHAR sqlcode[NAX_ERR_MSG_LEN]; + SQLGetDiagField(SQL_HANDLE_DBC, this->connHandle, 1, SQL_DIAG_MESSAGE_TEXT, &sqlcode, NAX_ERR_MSG_LEN, NULL); SQLFreeHandle(SQL_HANDLE_DBC, this->connHandle); SQLFreeHandle(SQL_HANDLE_ENV, this->envHandle); ereport(ERROR, (errcode(ERRCODE_CONNECTION_FAILURE), - errmsg("Error SQLConnect"))); + errmsg("Error SQLConnect\n%s", sqlcode))); } } @@ -629,9 +635,8 @@ char* ODBCLinker::errorMsg() if (this->stmt == NULL) { return NULL; } - int msgLen = 100; - char* msg = (char*)palloc(sizeof(char) * msgLen); - SQLGetDiagRec(SQL_HANDLE_STMT, this->stmt, 1, NULL, NULL, (SQLCHAR*)msg, 100 ,NULL); + char* msg = (char*)palloc(sizeof(char) * NAX_ERR_MSG_LEN); + SQLGetDiagRec(SQL_HANDLE_STMT, this->stmt, 1, NULL, NULL, (SQLCHAR*)msg, NAX_ERR_MSG_LEN, NULL); return msg; }