1 Star 0 Fork 53

野狐先生/openGauss-connector-odbc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pgxalib.cpp 17.96 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
/*------
* Module: pgxalib.cpp
*
* Description:
* This module implements XA like routines
* invoked from MSDTC process.
*
* xa_open(), xa_close(), xa_commit(),
* xa_rollback() and xa_recover()
* are really invoked AFAIC.
*-------
*/
#include <oleTx2xa.h>
#include <sqlext.h>
#include <odbcinst.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <process.h>
#include <time.h>
#include <string>
#include <map>
#include <vector>
EXTERN_C static void mylog(const char *fmt,...);
using namespace std;
class XAConnection
{
private:
string connstr;
string dsnstr;
HDBC xaconn;
vector<string> qvec;
int pos;
bool immediateConnection;
string sqlState;
string errMsg;
void parse_xa_info();
public:
XAConnection(LPCTSTR str) : connstr(str), xaconn(NULL), pos(-1), immediateConnection(false) {parse_xa_info();}
~XAConnection();
void Reset(void);
HDBC ActivateConnection(void);
void SetPos(int spos) {pos = spos;}
HDBC GetConnection(void) const {return xaconn;}
vector<string> &GetResultVec(void) {return qvec;}
int GetPos(void) {return pos;}
const string &GetConnstr(void) {return connstr;}
const string &GetDsnstr(void) {return dsnstr;}
bool GetImmediateConnection(void) {return immediateConnection;}
bool AuthenticationError(void) {return sqlState == "08001" && errMsg.find("could not connect") == std::string::npos;}
};
static class INIT_CRIT
{
private:
public:
bool cs_init;
CRITICAL_SECTION map_cs;
CRITICAL_SECTION mylog_cs;
map<int, XAConnection> xatab;
FILE *LOGFP;
HENV env;
INIT_CRIT() : LOGFP(NULL), env(NULL)
{
InitializeCriticalSection(&map_cs);
InitializeCriticalSection(&mylog_cs);
cs_init = true;
}
~INIT_CRIT()
{
leave();
}
void leave()
{
if (cs_init)
{
mylog("leaving pgxadll\n");
xatab.clear();
FreeEnv();
if (LOGFP)
fclose(LOGFP);
LOGFP = NULL;
DeleteCriticalSection(&mylog_cs);
DeleteCriticalSection(&map_cs);
cs_init = false;
}
}
void finalize()
{
leave();
}
void FreeEnv()
{
if (env)
{
mylog("Freeing env\n");
SQLFreeHandle(SQL_HANDLE_ENV, env);
env = NULL;
}
}
} init_crit;
#define MLOCK_ACQUIRE EnterCriticalSection(&init_crit.map_cs)
#define MLOCK_RELEASE LeaveCriticalSection(&init_crit.map_cs)
static int dtclog = 0;
XAConnection::~XAConnection()
{
}
void XAConnection::Reset()
{
qvec.clear();
if (xaconn)
{
mylog("about to Disconnect\n");
SQLDisconnect(xaconn);
mylog("Freeing HANDLE_DBC\n");
SQLFreeHandle(SQL_HANDLE_DBC, xaconn);
}
}
HDBC XAConnection::ActivateConnection(void)
{
RETCODE ret;
MLOCK_ACQUIRE;
if (!init_crit.env)
{
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &init_crit.env);
if (!SQL_SUCCEEDED(ret))
{
MLOCK_RELEASE;
return NULL;
}
}
MLOCK_RELEASE;
if (xaconn)
return xaconn;
ret = SQLSetEnvAttr(init_crit.env, SQL_ATTR_ODBC_VERSION, (PTR) SQL_OV_ODBC3, 0);
ret = SQLAllocHandle(SQL_HANDLE_DBC, init_crit.env, &xaconn);
if (!SQL_SUCCEEDED(ret))
return NULL;
ret = SQLDriverConnect(xaconn, NULL,
(SQLCHAR *) dsnstr.c_str(), SQL_NTS, NULL, SQL_NULL_DATA, NULL, SQL_DRIVER_COMPLETE);
if (SQL_SUCCEEDED(ret))
return xaconn;
SQLCHAR sqlstate[8], errmsg[256];
SQLGetDiagRec(SQL_HANDLE_DBC, xaconn,
1, sqlstate, NULL, errmsg,
sizeof(errmsg), NULL);
mylog("first SQLDriverConnect return=%d sqlstate=%s error=%s\n", ret, sqlstate, errmsg);
sqlState = (char *) sqlstate;
errMsg = (char *) errmsg;
if (!AuthenticationError())
{
SQLFreeHandle(SQL_HANDLE_DBC, xaconn);
return NULL;
}
sqlState.empty();
errMsg.empty();
ret = SQLDriverConnect(xaconn, NULL,
(SQLCHAR *) (dsnstr + ";Username=postgres;Password=postgres;sslmode=allow").c_str(), SQL_NTS, NULL, SQL_NULL_DATA, NULL, SQL_DRIVER_COMPLETE);
if (SQL_SUCCEEDED(ret))
{
mylog("second SQLDriverConnect success\n");
return xaconn;
}
SQLGetDiagRec(SQL_HANDLE_DBC, xaconn,
1, sqlstate, NULL, errmsg,
sizeof(errmsg), NULL);
mylog("second SQLDriverConnect return=%d sqlstate=%s error=%s\n", ret, sqlstate, errmsg);
sqlState = (char *) sqlstate;
errMsg = (char *) errmsg;
return NULL;
}
#define _BUILD_DLL_
#ifdef _BUILD_DLL_
EXTERN_C {
#define DIRSEPARATOR "\\"
#define PG_BINARY_A "ab"
#define MYLOGDIR "c:"
#define MYLOGFILE "mylog_"
static void
generate_filename(const char *dirname, const char *prefix, char *filename)
{
int pid = 0;
pid = _getpid();
if (dirname == 0 || filename == 0)
return;
strcpy(filename, dirname);
strcat(filename, DIRSEPARATOR);
if (prefix != 0)
strcat(filename, prefix);
sprintf(filename, "%s%u%s", filename, pid, ".log");
return;
}
static void FreeEnv()
{
init_crit.FreeEnv();
}
#define DTCLOGDIR "c:\\pgdtclog"
#include <direct.h>
static const char * const DBMSNAME = "PostgreSQL";
static const char * const KEY_NAME = "MsdtcLog";
static const char * const ODBCINST_INI = "ODBCINST.INI";
INT_PTR FAR WINAPI GetMsdtclog()
{
char temp[16];
SQLGetPrivateProfileString(DBMSNAME, KEY_NAME, "", temp, sizeof(temp), ODBCINST_INI);
dtclog = atoi(temp);
return dtclog;
}
INT_PTR FAR WINAPI SetMsdtclog(int dtclog)
{
char temp[16];
sprintf(temp, "%d", dtclog);
SQLWritePrivateProfileString(DBMSNAME, KEY_NAME, temp, ODBCINST_INI);
return dtclog;
}
static BOOL
output_mylog()
{
return (0 != dtclog);
}
static void
mylog(const char *fmt,...)
{
va_list args;
char filebuf[80];
static BOOL init = TRUE;
FILE *logfp = init_crit.LOGFP;
if (!output_mylog())
return;
EnterCriticalSection(&init_crit.mylog_cs);
va_start(args, fmt);
if (init)
{
if (!logfp)
{
generate_filename(MYLOGDIR, MYLOGFILE, filebuf);
logfp = fopen(filebuf, PG_BINARY_A);
}
if (!logfp)
{
generate_filename(DTCLOGDIR, MYLOGFILE, filebuf);
logfp = fopen(filebuf, PG_BINARY_A);
#ifdef WIN32
if (NULL == logfp)
{
if (0 == _mkdir(DTCLOGDIR))
logfp = fopen(filebuf, PG_BINARY_A);
}
#endif /* WIN32 */
}
if (logfp)
{
setbuf(logfp, NULL);
init_crit.LOGFP = logfp;
}
}
init = FALSE;
if (logfp)
{
time_t ntime;
char ctim[128];
time(&ntime);
strcpy(ctim, ctime(&ntime));
ctim[strlen(ctim) - 1] = '\0';
fprintf(logfp, "[%d.%d(%s)]", GetCurrentProcessId(), GetCurrentThreadId(), ctim);
vfprintf(logfp, fmt, args);
}
va_end(args);
LeaveCriticalSection(&init_crit.mylog_cs);
}
static int initialize_globals(void)
{
static int init = 1;
if (!init)
init = 0;
return 0;
}
static void XatabClear(void);
static void finalize_globals(void)
{
/* my(q)log is unavailable from here */
mylog("DETACHING From MSDTC PROCESS\n");
init_crit.finalize();
}
HINSTANCE s_hModule; /* Saved module handle. */
/* This is where the Driver Manager attaches to this Driver */
BOOL WINAPI
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
WORD wVersionRequested;
WSADATA wsaData;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
s_hModule = (HINSTANCE) hInst; /* Save for dialog boxes */
/* Load the WinSock Library */
wVersionRequested = MAKEWORD(1, 1);
if (WSAStartup(wVersionRequested, &wsaData))
return FALSE;
/* Verify that this is the minimum version of WinSock */
if (LOBYTE(wsaData.wVersion) != 1 ||
HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return FALSE;
}
initialize_globals();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_PROCESS_DETACH:
finalize_globals();
WSACleanup();
return TRUE;
case DLL_THREAD_DETACH:
break;
default:
break;
}
return TRUE;
}
} /* end of EXTERN_C */
#endif /* _BUILD_DLL_ */
static void XatabClear(void)
{
init_crit.xatab.clear();
}
static const char *XidToText(const XID &xid, char *rtext)
{
int glen = xid.gtrid_length, blen = xid.bqual_length;
int i, j;
for (i = 0, j = 0; i < glen; i++, j += 2)
sprintf(rtext + j, "%02x", (unsigned char) xid.data[i]);
strcat(rtext, "-"); j++;
for (; i < glen + blen; i++, j += 2)
sprintf(rtext + j, "%02x", (unsigned char) xid.data[i]);
return rtext;
}
static int
pg_hex2bin(const UCHAR *src, UCHAR *dst, int length)
{
UCHAR chr;
const UCHAR *src_wk;
UCHAR *dst_wk;
int i, val;
BOOL HByte = TRUE;
for (i = 0, src_wk = src, dst_wk = dst; i < length; i++, src_wk++)
{
chr = *src_wk;
if (!chr)
break;
if (chr >= 'a' && chr <= 'f')
val = chr - 'a' + 10;
else if (chr >= 'A' && chr <= 'F')
val = chr - 'A' + 10;
else
val = chr - '0';
if (HByte)
*dst_wk = (val << 4);
else
{
*dst_wk += val;
dst_wk++;
}
HByte = !HByte;
}
return length;
}
static int TextToXid(XID &xid, const char *rtext)
{
int slen, glen, blen;
char *sptr;
slen = (int) strlen(rtext);
sptr = (char *)strchr(rtext, '-');
if (sptr)
{
glen = (int) (sptr - rtext);
blen = slen - glen - 1;
}
else
{
glen = slen;
blen = 0;
}
xid.gtrid_length = glen / 2;
xid.bqual_length = blen / 2;
pg_hex2bin((const UCHAR *) rtext, (UCHAR *) &xid.data[0], glen);
pg_hex2bin((const UCHAR *) sptr + 1, (UCHAR *) &xid.data[glen / 2], blen);
return (glen + blen) / 2;
}
static bool bImmediateConnectDefault = false;
#define CHAR_OPENING_BRACE '{'
#define CHAR_CLOSING_BRACE '}'
#define CHAR_SEMI_COLON ';'
#define CHAR_EQUAL '='
#define STR_OPENING_BRACE "{"
#define STR_CLOSING_BRACE "}"
#define STR_SEMI_COLON ";"
#define STR_EQUAL "="
#define KEYWORD_DTC_CHECK "dtchk"
#define KEYWORD_DEBUG "debug"
#define KEYWORD_ABDEBUG "B2"
void XAConnection::parse_xa_info()
{
const char *cstr, *pstr, *pnstr;
char keyword[64], value[64];
bool keyhasbr, valhasbr;
int debugv = -1;
cstr = connstr.c_str();
immediateConnection = bImmediateConnectDefault;
GetMsdtclog();
for (pstr = cstr; *pstr;)
{
keyhasbr = valhasbr = false;
if (CHAR_OPENING_BRACE == *pstr)
{
keyhasbr = true;
if (pnstr = strchr(pstr, (int) CHAR_CLOSING_BRACE), NULL != pnstr)
strncpy_s(keyword, sizeof(keyword), pstr + 1, pnstr - pstr - 1);
else
break;
pstr = pnstr + 1;
if (CHAR_EQUAL != *pstr)
break;
}
else
{
if (pnstr = strchr(pstr, (int) CHAR_EQUAL), NULL != pnstr)
strncpy_s(keyword, sizeof(keyword), pstr, pnstr - pstr);
else
break;
pstr = pnstr;
}
pstr++;
if (CHAR_OPENING_BRACE == *pstr)
{
valhasbr = true;
if (pnstr = strchr(pstr, (int) CHAR_CLOSING_BRACE), NULL != pnstr)
strncpy_s(value, sizeof(value), pstr + 1, pnstr - pstr - 1);
else
break;
pstr = pnstr + 1;
}
else
{
if (pnstr = strchr(pstr, (int) CHAR_SEMI_COLON), NULL != pnstr)
{
strncpy_s(value, sizeof(value), pstr, pnstr - pstr);
pstr = pnstr;
}
else
{
strcpy(value, pstr);
pstr = strchr(pstr, '\0');
}
}
if (0 == _stricmp(keyword, KEYWORD_DTC_CHECK))
immediateConnection = (0 != atoi(value));
else if (0 == _stricmp(keyword, KEYWORD_DEBUG) ||
0 == _stricmp(keyword, KEYWORD_ABDEBUG))
debugv = atoi(value);
else
{
if (keyhasbr)
dsnstr += STR_OPENING_BRACE;
dsnstr += keyword;
if (keyhasbr)
dsnstr += STR_CLOSING_BRACE;
dsnstr += STR_EQUAL;
if (valhasbr)
dsnstr += STR_OPENING_BRACE;
dsnstr += value;
if (valhasbr)
dsnstr += STR_CLOSING_BRACE;
dsnstr += STR_SEMI_COLON;
}
if (NULL == pstr ||
CHAR_SEMI_COLON != *pstr)
break;
pstr++;
}
if (0 != dtclog)
{
char dbgopt[16];
if (debugv <= 0)
debugv = 1;
_snprintf(dbgopt, sizeof(dbgopt), KEYWORD_ABDEBUG "=%d;", debugv);
dsnstr += dbgopt;
}
}
EXTERN_C static int __cdecl xa_open(char *xa_info, int rmid, long flags)
{
int xartn = XA_OK;
bool bActivateConnection = bImmediateConnectDefault;
mylog("xa_open %s rmid=%d flags=%ld\n", xa_info, rmid, flags);
MLOCK_ACQUIRE;
init_crit.xatab.insert(pair<int, XAConnection>(rmid, XAConnection(xa_info)));
MLOCK_RELEASE;
map<int, XAConnection>::iterator p;
p = init_crit.xatab.find(rmid);
if (p == init_crit.xatab.end())
xartn = XAER_RMERR;
else if (p->second.GetImmediateConnection())
{
mylog("xa_open calls ActivateConnection %s\n", p->second.GetDsnstr().c_str());
if (p->second.ActivateConnection())
xartn = XA_OK;
else
xartn = XAER_RMERR;
}
mylog("xa_open %s rmid=%d returning %d\n", xa_info, rmid, xartn);
return xartn;
}
EXTERN_C static int __cdecl xa_close(char *xa_info, int rmid, long flags)
{
mylog("xa_close rmid=%d flags=%ld\n", rmid, flags);
map<int, XAConnection>::iterator p;
MLOCK_ACQUIRE;
p = init_crit.xatab.find(rmid);
if (p != init_crit.xatab.end())
p->second.Reset();
init_crit.xatab.erase(rmid);
if (init_crit.xatab.size() == 0)
FreeEnv();
GetMsdtclog();
MLOCK_RELEASE;
return XA_OK;
}
//
// Dummy implementation (not called from MSDTC).
//
EXTERN_C static int __cdecl xa_start(XID *xid, int rmid, long flags)
{
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_start %s rmid=%d flags=%ld\n", pgxid, rmid, flags);
init_crit.xatab.find(rmid)->second.ActivateConnection();
return XA_OK;
}
//
// Dummy implementation (not called from MSDTC).
//
EXTERN_C static int __cdecl xa_end(XID *xid, int rmid, long flags)
{
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_end %s rmid=%d flags=%ld\n", pgxid, rmid, flags);
return XA_OK;
}
EXTERN_C static int __cdecl xa_rollback(XID *xid, int rmid, long flags)
{
int rmcode = XAER_RMERR;
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_rollback %s rmid=%d flags=%ld\n", pgxid, rmid, flags);
map<int, XAConnection>::iterator p;
p = init_crit.xatab.find(rmid);
if (p != init_crit.xatab.end())
{
HDBC conn = p->second.ActivateConnection();
if (conn)
{
SQLCHAR cmdmsg[512], sqlstate[8];
HSTMT stmt;
RETCODE ret;
ret = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret)
{
mylog("Statement allocation error\n");
return rmcode;
}
_snprintf((char *) cmdmsg, sizeof(cmdmsg), "ROLLBACK PREPARED '%s'", pgxid);
ret = SQLExecDirect(stmt, (SQLCHAR *) cmdmsg, SQL_NTS);
switch (ret)
{
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
rmcode = XA_OK;
break;
case SQL_ERROR:
SQLGetDiagRec(SQL_HANDLE_STMT, stmt,
1, sqlstate, NULL, cmdmsg,
sizeof(cmdmsg), NULL);
mylog("xa_commit error %s '%s'\n", sqlstate, cmdmsg);
if (_stricmp((char *) sqlstate, "42704") == 0)
rmcode = XA_HEURHAZ;
break;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
}
return rmcode;
}
//
// Dummy implementation (not called from MSDTC).
// Anyway it's almost impossible to implement this routine properly.
//
EXTERN_C static int __cdecl xa_prepare(XID *xid, int rmid, long flags)
{
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_prepare %s rmid=%d\n", pgxid, rmid);
#ifdef _SLEEP_FOR_TEST_
Sleep(2000);
#endif /* _SLEEP_FOR_TEST_ */
map<int, XAConnection>::iterator p;
p = init_crit.xatab.find(rmid);
if (p != init_crit.xatab.end())
{
HDBC conn = p->second.GetConnection();
if (conn)
{
}
}
return XAER_RMERR;
}
EXTERN_C static int __cdecl xa_commit(XID *xid, int rmid, long flags)
{
int rmcode = XAER_RMERR;
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_commit %s rmid=%d flags=%ld\n", pgxid, rmid, flags);
#ifdef _SLEEP_FOR_TEST_
Sleep(2000);
#endif /* _SLEEP_FOR_TEST_ */
map<int, XAConnection>::iterator p;
p = init_crit.xatab.find(rmid);
if (p != init_crit.xatab.end())
{
HDBC conn = p->second.ActivateConnection();
if (conn)
{
SQLCHAR cmdmsg[512], sqlstate[8];
HSTMT stmt;
RETCODE ret;
SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
_snprintf((char *) cmdmsg, sizeof(cmdmsg), "COMMIT PREPARED '%s'", pgxid);
ret = SQLExecDirect(stmt, (SQLCHAR *) cmdmsg, SQL_NTS);
switch (ret)
{
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
rmcode = XA_OK;
break;
case SQL_ERROR:
SQLGetDiagRec(SQL_HANDLE_STMT, stmt,
1, sqlstate, NULL, cmdmsg,
sizeof(cmdmsg), NULL);
if (_stricmp((char *) sqlstate, "42704") == 0)
rmcode = XA_HEURHAZ;
break;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
}
return rmcode;
}
EXTERN_C static int __cdecl xa_recover(XID *xids, long count, int rmid, long flags)
{
int rmcode = XAER_RMERR, rcount;
mylog("xa_recover rmid=%d count=%d flags=%ld\n", rmid, count, flags);
map<int, XAConnection>::iterator p;
p = init_crit.xatab.find(rmid);
if (p == init_crit.xatab.end())
return rmcode;
HDBC conn = p->second.ActivateConnection();
if (!conn)
{
if (p->second.AuthenticationError())
rmcode = 0;
mylog("%s returns %d\n", __FUNCTION__, rmcode);
return rmcode;
}
vector<string> &vec = p->second.GetResultVec();
int pos = p->second.GetPos();
if ((flags & TMSTARTRSCAN) != 0)
{
HSTMT stmt;
RETCODE ret;
char buf[512];
vec.clear();
SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
ret = SQLExecDirect(stmt, (SQLCHAR *) "select gid from pg_prepared_xacts", SQL_NTS);
if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret)
{
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
pos = -1;
goto onExit;
}
SQLBindCol(stmt, 1, SQL_C_CHAR, buf, sizeof(buf), NULL);
ret = SQLFetch(stmt);
while (SQL_NO_DATA_FOUND != ret)
{
vec.push_back(buf);
ret = SQLFetch(stmt);
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
pos = 0;
}
rcount = (int) vec.size();
rmcode = rcount - pos;
if (rmcode > count)
rmcode = count;
for (int i = 0; i < rmcode; i++, pos++)
TextToXid(xids[i], vec[pos].c_str());
if ((flags & TMENDRSCAN) != 0)
{
vec.clear();
pos = -1;
}
mylog("return count=%d\n", rmcode);
onExit:
p->second.SetPos(pos);
return rmcode;
}
//
// I'm not sure if this is invoked from MSDTC
// Anyway there's nothing to do with it.
//
EXTERN_C static int __cdecl xa_forget(XID *xid, int rmid, long flags)
{
char pgxid[258];
XidToText(*xid, pgxid);
mylog("xa_forget %s rmid=%d\n", pgxid, rmid);
return XA_OK;
}
//
// I'm not sure if this can be invoked from MSDTC.
//
EXTERN_C static int __cdecl xa_complete(int *handle, int *retval, int rmid, long flags)
{
mylog("xa_complete rmid=%d\n", rmid);
return XA_OK;
}
EXTERN_C static xa_switch_t xapsw = { "psotgres_xa", TMNOMIGRATE,
0, xa_open, xa_close, xa_start, xa_end, xa_rollback,
xa_prepare, xa_commit, xa_recover, xa_forget,
xa_complete};
EXTERN_C HRESULT __cdecl GetXaSwitch (XA_SWITCH_FLAGS XaSwitchFlags,
xa_switch_t ** ppXaSwitch)
{
mylog("GetXaSwitch called\n");
GetMsdtclog();
*ppXaSwitch = &xapsw;
return S_OK;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/qq1907824738/openGauss-connector-odbc.git
git@gitee.com:qq1907824738/openGauss-connector-odbc.git
qq1907824738
openGauss-connector-odbc
openGauss-connector-odbc
master

搜索帮助