50 #if defined(NCBI_OS_MSWIN)
51 # include <winsock2.h>
52 # include "../ncbi_win_hook.hpp"
62 #define NCBI_USE_ERRCODE_X Dbapi_CTLib_Context
68 #define ftdsVER NCBI_AS_STRING(NCBI_FTDS_VERSION_NAME(ftds))
70 namespace NCBI_NS_FTDS_CTLIB
83 # define s_CTLCtxLock s_TDSCtxLock
109 static void StaticClearAll(
void);
113 return m_ExitProcessPatched;
122 bool m_ExitProcessPatched;
130 m_ExitProcessPatched(
false)
132 #if defined(NCBI_OS_MSWIN) && defined(NCBI_DLL_BUILD)
158 return instance.
Get();
166 vector<CTLibContext*>::iterator it = find(
m_Registry.begin(),
179 vector<CTLibContext*>::iterator it = find(
m_Registry.begin(),
218 : m_CTL_Context(&context)
219 , m_CTL_Conn(&ctl_conn)
221 , m_IsAllocated(
false)
290 #if defined(FTDS_IN_USE)
307 const_cast<char*
>(server_name.data()),
308 static_cast<CS_INT>(server_name.size())));
310 #if defined(CS_SERVERADDR)
320 const_cast<char*
>(server_name.data()),
321 static_cast<CS_INT>(server_name.size()),
336 const_cast<char*
>(server_name.data()),
337 static_cast<CS_INT>(server_name.size())));
344 const_cast<char*
>(server_name.data()),
345 server_name.size()));
422 #if !defined(FTDS_IN_USE)
439 : m_CTL_Conn(&ctl_conn)
441 , m_IsAllocated(
false)
565 m_LoginRetryCount(0),
569 m_ReusingContext(reuse_context)
578 "version other than 5.0 or 7.x.",
672 #if defined(FTDS_IN_USE) && NCBI_FTDS_VERSION >= 95
674 static FIntHandler s_DefaultIntHandler;
675 if (int_handler == &CTL_Connection::x_IntHandler) {
676 m_OrigIntHandler = s_DefaultIntHandler;
678 if (s_DefaultIntHandler ==
nullptr) {
679 s_DefaultIntHandler = int_handler;
681 m_OrigIntHandler = int_handler;
682 int_handler = &CTL_Connection::x_IntHandler;
749 int sec = (nof_secs == 0 ?
CS_NO_LIMIT :
static_cast<int>(nof_secs));
766 int sec = (nof_secs == 0 ?
CS_NO_LIMIT :
static_cast<int>(nof_secs));
801 if (app_name.empty()) {
807 if (app_name.empty()) {
809 app_name =
"DBAPI-" ftdsVER;
811 app_name =
"DBAPI-ctlib";
886 #if defined(FTDS_IN_USE) && NCBI_FTDS_VERSION >= 95
887 ctl_conn->m_OrigIntHandler = m_OrigIntHandler;
934 unsigned int num = 0;
988 (
CS_INT)
sizeof(p_pot_tmp),
996 #if defined(FTDS_IN_USE) && NCBI_FTDS_VERSION >= 95
1016 #if defined(NCBI_OS_MSWIN) && defined(NCBI_DLL_BUILD)
1076 p_pot != 0 && p_pot->NofItems() > 0)
1108 ex->SetSybaseSeverity(msg->
severity);
1119 ex->SetSybaseSeverity(msg->
severity);
1137 const string& server_name,
1138 const string& user_name,
1142 unsigned int rows_in_batch = 0
1145 ex->SetServerName(server_name);
1146 ex->SetUserName(user_name);
1147 ex->SetSybaseSeverity(severity);
1148 ex->SetParams(params);
1149 ex->SetRowsInBatch(rows_in_batch);
1161 const string& server_name,
1162 const string& user_name
1183 #if !defined(FTDS_IN_USE)
1185 unique_ptr<CDB_Exception> ex(
1189 "Got timeout on ct_cancel(CS_CANCEL_ALL)",
1238 (
CS_INT)
sizeof(ctl_conn),
1242 if (ctl_conn->ServerName().size() < 127 && ctl_conn->UserName().size() < 127) {
1243 server_name = ctl_conn->ServerName();
1244 user_name = ctl_conn->UserName();
1255 p_pot != 0 && p_pot->NofItems() > 0)
1268 err_str <<
"CTLIB error handler detects the following error" << endl
1274 err_str <<
"OS # " << msg->
osnumber
1275 <<
" OS msg " << msg->
osstring << endl;
1280 err_str <<
"SQL: " << msg->
sqlstate << endl;
1291 unsigned int rows_in_batch = 0;
1293 handlers = &ctl_conn->GetMsgHandlers();
1294 message.
context.Reset(&ctl_conn->GetDbgInfo());
1295 params = ctl_conn->GetLastParams();
1296 rows_in_batch = ctl_conn->GetRowsInCurrentBatch();
1297 }
else if (ctl_ctx !=
nullptr) {
1300 if (handlers !=
nullptr
1324 if (ctl_conn !=
NULL && ctl_conn->IsOpen()) {
1325 #if NCBI_FTDS_VERSION >= 95
1326 if (ctl_conn->GetCancelTimedOut()) {
1331 ctl_conn->SetCancelTimedOut(
false);
1343 }
else if ((msg->
msgnumber & 0xFF) == 25) {
1399 retriable, rows_in_batch);
1461 (
void*) &ctl_conn, (
CS_INT)
sizeof(ctl_conn),
1466 if (ctl_conn->ServerName().size() < 127 && ctl_conn->UserName().size() < 127) {
1467 server_name = ctl_conn->ServerName();
1468 user_name = ctl_conn->UserName();
1478 p_pot != 0 && p_pot->NofItems() > 0)
1490 err_str <<
"Message from the server ";
1493 err_str <<
"<" << msg->
svrname <<
"> ";
1497 <<
" severity: " << msg->
severity << endl;
1500 err_str <<
"Proc: " << msg->
proc <<
" line: " << msg->
line << endl;
1505 err_str <<
"SQL: " << msg->
sqlstate << endl;
1508 err_str << msg->
text << endl;
1517 unsigned int rows_in_batch = 0;
1519 handlers = &ctl_conn->GetMsgHandlers();
1527 message.
context.Reset(&ctl_conn->GetDbgInfo());
1528 params = ctl_conn->GetLastParams();
1529 rows_in_batch = ctl_conn->GetRowsInCurrentBatch();
1530 if (ctl_conn->IsCancelInProgress()
1575 unique_ptr<CDB_Exception> ex(
new CDB_RPCEx(
1589 unique_ptr<CDB_Exception> ex(
new CDB_SQLEx(
1602 unique_ptr<CDB_Exception> ex(
new CDB_DSEx(
1641 #if !defined(NCBI_CTLIB_TDS_VERSION)
1642 # define NCBI_CTLIB_TDS_VERSION 125
1645 #define NCBI_CTLIB_TDS_FALLBACK_VERSION 110
1670 # define FTDS_VERSION_ERR_LEVEL Info
1672 # define FTDS_VERSION_ERR_LEVEL Warning
1679 return TFtdsTdsVersion::GetDefault();
1680 #elif defined(CS_CURRENT_VERSION)
1681 return CS_CURRENT_VERSION;
1683 version = TCtlibTdsVersion::GetDefault();
1692 #if NCBI_FTDS_VERSION >= 95
1696 #if NCBI_FTDS_VERSION >= 100
1705 #ifdef CS_VERSION_120
1709 #ifdef CS_VERSION_125
1713 #ifdef CS_VERSION_150
1717 #ifdef CS_VERSION_155
1719 return CS_VERSION_155;
1721 #ifdef CS_VERSION_157
1723 return CS_VERSION_157;
1731 <<
"The version " <<
version <<
" of TDS protocol for "
1732 "the DBAPI CTLib driver is not supported. Falling back to "
1733 "the TDS protocol version " << fallback_version <<
".");
1758 const string& driver,
1762 unique_ptr<TImplementation> drv;
1773 bool reuse_context =
false;
1777 bool reuse_context =
false;
1785 string client_charset;
1786 unsigned int max_connect = 0;
1788 if ( params !=
NULL ) {
1796 for (; cit != cend; ++cit) {
1797 const TValue& v = (*cit)->GetValue();
1799 if ( v.id ==
"reuse_context" ) {
1800 reuse_context = (v.value !=
"false");
1801 }
else if ( v.id ==
"version" ) {
1804 }
else if ( v.id ==
"packet" ) {
1806 }
else if ( v.id ==
"prog_name" ) {
1807 prog_name = v.value;
1808 }
else if ( v.id ==
"host_name" ) {
1809 host_name = v.value;
1810 }
else if ( v.id ==
"client_charset" ) {
1811 client_charset = v.value;
1812 }
else if ( v.id ==
"max_connect" ) {
1826 drv->CTLIB_SetPacketSize(page_size);
1829 if (!prog_name.empty()) {
1830 drv->SetApplicationName(prog_name);
1833 if (!host_name.empty()) {
1834 drv->SetHostName(host_name);
1837 if (!client_charset.empty()) {
1838 drv->SetClientCharset(client_charset);
1844 drv->SetMaxConnect(1000);
1847 return drv.release();
1851 #if defined(FTDS_IN_USE)
1853 # define CDbapiCtlibCF_ftdsVER_ctlib \
1854 NCBI_FTDS_VERSION_NAME2(CDbapiCtlibCF_ftds,_ctlib)
1855 # define DBAPI_RegisterDriver_FTDSVER \
1856 NCBI_FTDS_VERSION_NAME(DBAPI_RegisterDriver_FTDS)
1861 CDbapiCtlibCF_ftdsVER_ctlib(
void)
1887 #if defined(FTDS_IN_USE)
1890 NCBI_EntryPoint_xdbapi_ftdsVER(
1899 DBAPI_RegisterDriver_FTDSVER(
void)
1901 RegisterEntryPoint<I_DriverContext>(NCBI_EntryPoint_xdbapi_ftdsVER);
static void SetMaxConnect(unsigned int max_connect)
static CDbapiConnMgr & Instance(void)
Get access to the class instance.
virtual TInterface * CreateInstance(const string &driver=kEmptyStr, CVersionInfo version=NCBI_INTERFACE_VERSION(I_DriverContext), const TPluginManagerParamTree *params=0) const
Create instance of TDriver.
CDbapiCtlibCFBase(const string &driver_name)
CDbapiCtlibCF_Sybase(void)
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
void Release()
Manually force the resource to be released.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
void Add(const TPotItem item, int check_4_unique=0)
Helper class for object allocation/deallocation.
T & Get(void)
Create the variable if not created yet, return the reference.
CS_RETCODE Check(CS_RETCODE rc)
CTLibContextRegistry(void)
void Remove(CTLibContext *ctx)
vector< CTLibContext * > m_Registry
static void StaticClearAll(void)
bool m_ExitProcessPatched
~CTLibContextRegistry(void)
bool ExitProcessIsPatched(void) const
void Add(CTLibContext *ctx)
static CTLibContextRegistry & Instance(void)
virtual bool IsAbleTo(ECapability cpb) const
Check if a driver is acle to provide necessary functionality.
virtual void CTLIB_SetLoginLoopDelay(CS_INT nof_sec)
virtual void CTLIB_SetPacketSize(CS_INT packet_size)
virtual unsigned int GetLoginTimeout(void) const
Get login timeout.
virtual bool SetLoginTimeout(unsigned int nof_secs=0)
Set login timeout.
CS_RETCODE Check(CS_RETCODE rc) const
virtual void CTLIB_SetHostName(const string &host_name)
virtual bool SetTimeout(unsigned int nof_secs=0)
Set connection timeout.
unsigned int GetMaxConnect(void)
CTLibContextRegistry * m_Registry
virtual void CTLIB_SetLoginRetryCount(CS_INT n)
static CS_RETCODE CS_PUBLIC CTLIB_cterr_handler(CS_CONTEXT *context, CS_CONNECTION *con, CS_CLIENTMSG *msg)
bool x_SafeToFinalize(void) const
virtual void CTLIB_SetApplicationName(const string &a_name)
static CS_RETCODE CS_PUBLIC CTLIB_srverr_handler(CS_CONTEXT *context, CS_CONNECTION *con, CS_SERVERMSG *msg)
CTLibContext(bool reuse_context=true, CS_INT version=GetCtlibTdsVersion())
virtual void InitApplicationName(void)
Explicitly auto-initialize the application name, if necessary.
virtual bool SetMaxBlobSize(size_t nof_bytes)
Set maximal size for BLOB data.
void x_AddToRegistry(void)
virtual void SetClientCharset(const string &charset)
virtual ~CTLibContext(void)
void x_RemoveFromRegistry(void)
virtual string GetDriverName(void) const
virtual impl::CConnection * MakeIConnection(const CDBConnParams ¶ms)
CRWLock & x_GetCtxLock(void) const
virtual CS_CONTEXT * CTLIB_GetContext(void) const
bool SetMaxConnect(unsigned int num)
Set maximal number of open connections.
void x_SetRegistry(CTLibContextRegistry *registry)
void x_Close(bool delete_conn=true)
static CS_RETCODE CS_PUBLIC CTLIB_cserr_handler(CS_CONTEXT *context, CS_CLIENTMSG *msg)
virtual unsigned int GetTimeout(void) const
Get connection timeout.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
definition of a Culling tree
Command(CTL_Connection &ctl_conn)
const CTL_Connection & GetCTLConn(void) const
bool Open(CS_INT type, CS_INT option, const string &arg=kEmptyCStr)
bool SendData(CS_VOID *buff, CS_INT buff_len)
CS_COMMAND * GetNativeHandle(void) const
CS_RETCODE GetResults(CS_INT &res_type)
bool GetDataInfo(CS_IODESC &desc)
CS_CONNECTION * GetNativeHandle(void) const
bool Drop(void)
Drop allocated connection.
CS_RETCODE CheckWhileOpening(CS_RETCODE rc)
const CTL_Connection & GetCTLConn(void) const
const CTLibContext & GetCTLContext(void) const
Connection(CTLibContext &context, CTL_Connection &ctl_conn)
bool Open(const CDBConnParams ¶ms)
CTLibContext * m_CTL_Context
CTL_Connection * m_CTL_Conn
~Connection(void) noexcept
void Handle(const CDBHandlerStack &handler)
void SetRetriable(ERetriable retriable)
void Accept(unique_ptr< CDB_Exception > &e)
bool HandleMessage(int severity, int msgnum, const string &message) const
const string & GetExtraMsg(void) const
virtual void SetHostName(const string &host_name)
Set host name.
size_t GetMaxBlobSize(void) const
const CDBHandlerStack & GetCtxHandlerStack(void) const
virtual bool SetTimeout(unsigned int nof_secs=0)
Set connection timeout.
static void ResetEnvSybase(void)
virtual string GetApplicationName(void) const
Return application name.
virtual bool SetMaxBlobSize(size_t nof_bytes)
Set maximal size for BLOB data.
virtual void SetClientCharset(const string &charset)
virtual CRWLock & x_GetCtxLock(void) const
virtual unsigned int GetLoginTimeout(void) const
Get login timeout.
const string & GetClientCharset(void) const
virtual void SetApplicationName(const string &app_name)
Set application name.
virtual bool SetLoginTimeout(unsigned int nof_secs=0)
Set login timeout.
virtual unsigned int GetTimeout(void) const
Get connection timeout.
CS_RETCODE cs_ctx_alloc(CS_INT version, CS_CONTEXT **ctx)
CS_RETCODE cs_locale(CS_CONTEXT *ctx, CS_INT action, CS_LOCALE *locale, CS_INT type, CS_VOID *buffer, CS_INT buflen, CS_INT *outlen)
CS_RETCODE cs_config(CS_CONTEXT *ctx, CS_INT action, CS_INT property, CS_VOID *buffer, CS_INT buflen, CS_INT *outlen)
#define CS_SV_INTERNAL_FAIL
#define CS_SV_CONFIG_FAIL
CS_RETCODE cs_loc_alloc(CS_CONTEXT *ctx, CS_LOCALE **locptr)
CS_RETCODE cs_ctx_drop(CS_CONTEXT *ctx)
#define CS_CONSTAT_CONNECTED
CS_RETCODE cs_ctx_global(CS_INT version, CS_CONTEXT **ctx)
CS_RETCODE cs_loc_drop(CS_CONTEXT *ctx, CS_LOCALE *locale)
static CS_CONNECTION * conn
impl::CDBExceptionStorage & GetCTLExceptionStorage(void)
CS_RETCODE ct_command(CS_COMMAND *cmd, CS_INT type, const CS_VOID *buffer, CS_INT buflen, CS_INT option)
CS_RETCODE ct_connect(CS_CONNECTION *con, CS_CHAR *servername, CS_INT snamelen)
CS_RETCODE ct_results(CS_COMMAND *cmd, CS_INT *result_type)
CS_RETCODE ct_callback(CS_CONTEXT *ctx, CS_CONNECTION *con, CS_INT action, CS_INT type, CS_VOID *func)
CS_RETCODE ct_fetch(CS_COMMAND *cmd, CS_INT type, CS_INT offset, CS_INT option, CS_INT *rows_read)
CS_RETCODE ct_cmd_drop(CS_COMMAND *cmd)
CS_RETCODE ct_cmd_alloc(CS_CONNECTION *con, CS_COMMAND **cmd)
CS_RETCODE ct_con_alloc(CS_CONTEXT *ctx, CS_CONNECTION **con)
CS_RETCODE ct_con_drop(CS_CONNECTION *con)
CS_RETCODE ct_close(CS_CONNECTION *con, CS_INT option)
CS_RETCODE ct_send(CS_COMMAND *cmd)
CS_RETCODE ct_data_info(CS_COMMAND *cmd, CS_INT action, CS_INT colnum, CS_IODESC *iodesc)
CS_RETCODE ct_send_data(CS_COMMAND *cmd, CS_VOID *buffer, CS_INT buflen)
CS_RETCODE ct_cancel(CS_CONNECTION *conn, CS_COMMAND *cmd, CS_INT type)
CS_RETCODE ct_con_props(CS_CONNECTION *con, CS_INT action, CS_INT property, CS_VOID *buffer, CS_INT buflen, CS_INT *out_len)
CS_RETCODE ct_init(CS_CONTEXT *ctx, CS_INT version)
CS_RETCODE ct_exit(CS_CONTEXT *ctx, CS_INT unused)
CS_RETCODE ct_config(CS_CONTEXT *ctx, CS_INT action, CS_INT property, CS_VOID *buffer, CS_INT buflen, CS_INT *outlen)
NCBI_PARAM_DECL(int, ctlib, TDS_VERSION)
CS_INT GetCtlibTdsVersion(int version)
CDiagCompileInfo GetBlankCompileInfo(void)
NCBI_PARAM_DEF_EX(int, ctlib, TDS_VERSION, 125, eParam_NoThread, CTLIB_TDS_VERSION)
#define FTDS_VERSION_ERR_LEVEL
static void PassException(unique_ptr< CDB_Exception > &ex, const string &server_name, const string &user_name, CS_INT severity, const CDBParams *params, ERetriable retriable, unsigned int rows_in_batch=0)
static CS_RETCODE HandleConnStatus(CS_CONNECTION *conn, CS_CLIENTMSG *msg, const string &server_name, const string &user_name)
#define NCBI_CTLIB_TDS_VERSION
void NCBI_EntryPoint_xdbapi_ctlib(CPluginManager< I_DriverContext >::TDriverInfoList &info_list, CPluginManager< I_DriverContext >::EEntryPointRequest method)
#define NCBI_CTLIB_TDS_FALLBACK_VERSION
static CSafeStatic< CRWLock > s_CTLCtxLock(CSafeStaticLifeSpan::eLifeSpan_Long)
Static lock which will guard all thread-unsafe operations on most ctlib contexts and a handful of ctl...
typedef NCBI_PARAM_TYPE(ctlib, TDS_VERSION) TCtlibTdsVersion
ERetriable
Can the action be retried?
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
@ eRetriable_No
It makes no sense to retry the action.
@ eRetriable_Yes
It makes sense to try again.
void DBAPI_RegisterDriver_CTLIB(void)
CConstRef< SContext > context
#define DATABASE_DRIVER_ERROR(message, err_code)
ECapability
Report if the driver supports this functionality.
virtual Uint4 GetHost(void) const =0
virtual string GetServerName(void) const =0
virtual Uint2 GetPort(void) const =0
virtual string GetUserName(void) const =0
CDiagContext & GetDiagContext(void)
Get diag context instance.
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
#define NCBI_CURRENT_FUNCTION
Get current function name.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
const string & GetAppName(void) const
Get application name.
EDiagSev
Severity level for the posted diagnostics.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Critical
Critical error message.
void Error(CExceptionArgs_Base &args)
#define NCBI_CATCH_ALL_X(err_subcode, message)
void Warning(CExceptionArgs_Base &args)
@ eParam_NoThread
Do not use per-thread values.
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
size_type find_first_not_of(const CTempString match, size_type pos=0) const
Find the first occurrence of any character not in the matching string within the current string,...
TNodeList_CI SubNodeBegin(void) const
Return first const iterator on subnode list.
TNodeList::const_iterator TNodeList_CI
TNodeList_CI SubNodeEnd(void) const
Return last const iterator on subnode list.
@ eNonCompatible
major, minor does not match
#define NCBI_DBAPIDRIVER_CTLIB_EXPORT
static COnExitProcess & Instance(void)
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
if(yy_accept[yy_current_state])
constexpr bool empty(list< Ts... >) noexcept
void Check(const string &value)
string ConvertN2A(Uint4 host)
const struct ncbi::grid::netcache::search::fields::SIZE size
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
int(* int_handler)(void *)