📄 connection.c
字号:
OCISessionEnd(con->cxt, con->err, con->ses, (ub4) OCI_DEFAULT)
)
}
/* update internal status */
if (res == TRUE)
{
con->cstate = OCI_CONN_ATTACHED;
if (OCILib.ver_runtime < OCI_9 && con->pool != NULL)
con->pool->nb_busy--;
}
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_ConnectionClose
* ------------------------------------------------------------------------ */
boolean OCI_ConnectionClose(OCI_Connection *con)
{
OCI_CHECK(con == NULL, FALSE);
/* clear server output resources */
OCI_ServerDisableOutput(con);
/* lofoff and detatch form server */
OCI_ConnectionLogOff(con);
OCI_ConnectionDetach(con);
OCI_ConnectionDeallocate(con);
/* free internal lists */
OCI_ListFree(con->stmts);
OCI_ListFree(con->trsns);
OCI_ListFree(con->tinfs);
if (con->pool == NULL)
{
/* free strings */
OCI_FREE(con->db);
OCI_FREE(con->user);
OCI_FREE(con->pwd);
}
OCI_FREE(con->fmt_date);
OCI_FREE(con->fmt_num);
OCI_FREE(con->version);
con->stmts = NULL;
con->trsns = NULL;
con->tinfs = NULL;
return TRUE;
}
/* ************************************************************************ *
* PUBLIC FUNCTIONS
* ************************************************************************ */
/* ------------------------------------------------------------------------ *
* OCI_ConnectionCreate
* ------------------------------------------------------------------------ */
OCI_Connection * OCI_API OCI_ConnectionCreate(const mtext *db,
const mtext *user,
const mtext *pwd,
unsigned int mode)
{
OCI_Connection * con;
/* let's be sure OCI_Initialize() has been called */
OCI_CHECK_INITIALIZED(NULL);
con = OCI_ConnectionAllocate(NULL, db, user, pwd, mode);
if (con != NULL)
{
if (OCI_ConnectionAttach(con) == FALSE ||
OCI_ConnectionLogon(con) == FALSE)
{
OCI_ConnectionFree(con);
con = NULL;
}
}
OCI_RESULT(con != NULL);
return con;
}
/* ------------------------------------------------------------------------ *
* OCI_ConnectionFree
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_ConnectionFree(OCI_Connection *con)
{
boolean res = TRUE;
OCI_Error *err = NULL;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
/* clear connection reference from current error object */
err = OCI_ErrorGet(FALSE);
if (err != NULL && err->con == con)
err->con = NULL;
if (con->pool != NULL)
{
res = OCI_ConnectionLogOff(con);
if (OCILib.ver_runtime >= OCI_9)
OCI_ConnectionDetach(con);
}
else
{
res = OCI_ConnectionClose(con);
OCI_ListRemove(OCILib.cons, con);
OCI_FREE(con);
}
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_Commit
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_Commit(OCI_Connection *con)
{
boolean res = TRUE;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_CALL2
(
res, con,
OCITransCommit(con->cxt, con->err, (ub4) OCI_DEFAULT)
)
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_Rollback
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_Rollback(OCI_Connection *con)
{
boolean res = TRUE;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_CALL2
(
res, con,
OCITransRollback(con->cxt, con->err, (ub4) OCI_DEFAULT)
)
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_SetAutoCommit
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_SetAutoCommit(OCI_Connection *con, boolean enable)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_RESULT(TRUE);
con->autocom = enable;
return TRUE;
}
/* ------------------------------------------------------------------------ *
* OCI_GetAutoCommit
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_GetAutoCommit(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_RESULT(TRUE);
return con->autocom;
}
/* ------------------------------------------------------------------------ *
* OCI_IsConnected
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_IsConnected(OCI_Connection *con)
{
boolean res = TRUE;
ub4 status = 0;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_CALL2
(
res, con,
OCIAttrGet((dvoid **) con->svr, (ub4) OCI_HTYPE_SERVER,
(dvoid *) &status, (ub4 *) NULL,
(ub4) OCI_ATTR_SERVER_STATUS, con->err)
)
OCI_RESULT(res);
return (status == OCI_SERVER_NORMAL);
}
/* ------------------------------------------------------------------------ *
* OCI_GetUserData
* ------------------------------------------------------------------------ */
void * OCI_API OCI_GetUserData(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_RESULT(TRUE);
return con->usrdata;
}
/* ------------------------------------------------------------------------ *
* OCI_SetSetData
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_SetUserData(OCI_Connection *con, void * data)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_RESULT(TRUE);
con->usrdata = data;
return TRUE;
}
/* ------------------------------------------------------------------------ *
* OCI_GetDatabase
* ------------------------------------------------------------------------ */
const mtext * OCI_API OCI_GetDatabase(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
OCI_RESULT(TRUE);
return (const mtext *) con->db;
}
/* ------------------------------------------------------------------------ *
* OCI_GetUserName
* ------------------------------------------------------------------------ */
const mtext * OCI_API OCI_GetUserName(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
OCI_RESULT(TRUE);
return (const mtext *) con->user;
}
/* ------------------------------------------------------------------------ *
* OCI_GetPassword
* ------------------------------------------------------------------------ */
const mtext * OCI_API OCI_GetPassword(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
OCI_RESULT(TRUE);
return (const mtext *) con->pwd;
}
/* ------------------------------------------------------------------------ *
* OCI_SetPassword
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_SetPassword(OCI_Connection *con, const mtext *password)
{
boolean res = TRUE;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
OCI_CHECK_PTR(OCI_IPC_STRING, password, FALSE);
OCI_CALL2
(
res, con,
OCIPasswordChange(con->cxt, con->err,
(OraText *) con->user, (ub4) mtextsize(con->user),
(OraText *) con->pwd, (ub4) mtextsize(con->pwd),
(OraText *) password, (ub4) mtextsize(password),
(ub4) OCI_DEFAULT)
)
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_GetSessionMode
* ------------------------------------------------------------------------ */
unsigned int OCI_API OCI_GetSessionMode(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
OCI_RESULT(TRUE);
return con->mode;
}
/* ------------------------------------------------------------------------ *
* OCI_GetVersionServer
* ------------------------------------------------------------------------ */
const mtext * OCI_API OCI_GetVersionServer(OCI_Connection *con)
{
boolean res = FALSE;
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
if (con->version == NULL)
{
con->version = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
OCI_SIZE_BUFFER + 1, FALSE);
if (con->version != NULL)
{
int osize = OCI_SIZE_BUFFER * sizeof(mtext);
void *ostr = NULL;
mtext *p = NULL;
con->version[0] = 0;
res = TRUE;
ostr = OCI_GetInputMetaString(con->version, &osize);
OCI_CALL2
(
res, con,
OCIServerVersion((dvoid *) con->cxt, con->err,
(OraText *) ostr, (ub4) osize,
(ub1) OCI_HTYPE_SVCCTX)
)
OCI_GetOutputMetaString(ostr, con->version, &osize);
OCI_ReleaseMetaString(ostr);
if (res == TRUE)
{
con->version[osize / sizeof(mtext)] = 0;
/* parse server version string to find the version information */
for (p = con->version; (p != NULL) && (*p != 0); p++)
{
if (mtisdigit(*p) &&
(*(p+1) != 0) &&
(*(p+1) == MT('.') || (*(p+2) == MT('.') )))
{
if (OCI_NB_ARG_VERSION != mtsscanf(p, MT("%d.%d.%d"),
&con->ver_maj,
&con->ver_min,
&con->ver_rev))
{
/* extracting version info failed ! */
con->ver_maj = 0;
con->ver_min = 0;
con->ver_rev = 0;
}
break;
}
}
}
else
OCI_FREE(con->version);
}
}
OCI_RESULT(res);
return con->version;
}
/* ------------------------------------------------------------------------ *
* OCI_GetServerMajorVersion
* ------------------------------------------------------------------------ */
unsigned int OCI_API OCI_GetServerMajorVersion(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
if (con->ver_maj == 0)
OCI_GetVersionServer(con);
OCI_RESULT(con->ver_maj != OCI_UNKNOWN);
return con->ver_maj;
}
/* ------------------------------------------------------------------------ *
* OCI_GetServerMinorVersion
* ------------------------------------------------------------------------ */
unsigned int OCI_API OCI_GetServerMinorVersion(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
if (con->ver_min == 0)
OCI_GetVersionServer(con);
OCI_RESULT(con->ver_min != OCI_UNKNOWN);
return con->ver_min;
}
/* ------------------------------------------------------------------------ *
* OCI_GetServerRevisionVersion
* ------------------------------------------------------------------------ */
unsigned int OCI_API OCI_GetServerRevisionVersion(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
if (con->ver_rev == 0)
OCI_GetVersionServer(con);
OCI_RESULT(con->ver_rev != OCI_UNKNOWN);
return con->ver_rev;
}
/* ------------------------------------------------------------------------ *
* OCI_GetTransaction
* ------------------------------------------------------------------------ */
OCI_Transaction * OCI_API OCI_GetTransaction(OCI_Connection *con)
{
OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
OCI_RESULT(TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -