1 #ifndef DBAPI_DRIVER_CTLIB___INTERFACES__HPP
2 #define DBAPI_DRIVER_CTLIB___INTERFACES__HPP
48 # if defined(NCBI_FTDS_VERSION_NAME) && defined(NCBI_IS_FTDS_DEFAULT)
49 # undef NCBI_FTDS_VERSION_NAME
50 # undef NCBI_FTDS_VERSION_NAME2
51 # define NCBI_FTDS_VERSION_NAME(X) X
52 # define NCBI_FTDS_VERSION_NAME2(X,Y) X ## Y
53 # elif defined(NCBI_DBAPI_RENAME_CTLIB)
54 # include <../impl/ncbi_ftds_ver.h>
56 # define NCBI_FTDS_VERSION 0
57 # define NCBI_FTDS_VERSION_NAME(X) X
58 # define NCBI_FTDS_VERSION_NAME2(X,Y) X ## Y
61 # define NCBI_NS_FTDS_CTLIB NCBI_FTDS_VERSION_NAME2(ftds,_ctlib)
64 # define CTLibContext CTDSContext
65 # define CTL_Connection CTDS_Connection
66 # define CTL_Cmd CTDS_Cmd
67 # define CTL_CmdBase CTDS_CmdBase
68 # define CTL_LangCmd CTDS_LangCmd
69 # define CTL_RPCCmd CTDS_RPCCmd
70 # define CTL_CursorCmd CTDS_CursorCmd
71 # define CTL_BCPInCmd CTDS_BCPInCmd
72 # define CTL_SendDataCmd CTDS_SendDataCmd
73 # define CTL_Result CTDS_Result
74 # define CTL_RowResult CTDS_RowResult
75 # define CTL_ParamResult CTDS_ParamResult
76 # define CTL_ComputeResult CTDS_ComputeResult
77 # define CTL_StatusResult CTDS_StatusResult
78 # define CTL_CursorResult CTDS_CursorResult
79 # define CTL_CursorResultExpl CTDS_CursorResultExpl
80 # define CTL_BlobResult CTDS_BlobResult
81 # define CTL_BlobDescriptor CTDS_BlobDescriptor
82 # define CTL_CursorBlobDescriptor CTDS_CursorBlobDescriptor
83 # define CTLibContextRegistry CTDSContextRegistry
86 # define CTL_ITDescriptor CTDS_ITDescriptor
87 # define CTL_CursorITDescriptor CTDS_CursorITDescriptor
89 # define CTLIB_SetApplicationName TDS_SetApplicationName
90 # define CTLIB_SetHostName TDS_SetHostName
91 # define CTLIB_SetPacketSize TDS_SetPacketSize
92 # define CTLIB_SetMaxNofConns TDS_SetMaxNofConns
94 # define NCBI_CS_STRING_TYPE CS_VARCHAR_TYPE
95 # if NCBI_FTDS_VERSION >= 91
96 # define USE_STRUCT_CS_VARCHAR 1
102 # define NCBI_CS_STRING_TYPE CS_CHAR_TYPE
109 namespace NCBI_NS_FTDS_CTLIB
163 bool IsOpen_native(
void);
183 return *m_CTL_Context;
188 return *m_CTL_Context;
255 friend class ncbi::CDB_Connection;
267 virtual bool SetLoginTimeout (
unsigned int nof_secs = 0);
268 virtual bool SetTimeout (
unsigned int nof_secs = 0);
269 virtual bool SetMaxBlobSize (
size_t nof_bytes);
271 virtual void InitApplicationName(
void);
273 virtual unsigned int GetLoginTimeout(
void)
const;
274 virtual unsigned int GetTimeout (
void)
const;
276 virtual string GetDriverName(
void)
const;
287 virtual void CTLIB_SetApplicationName(
const string& a_name);
290 virtual void CTLIB_SetHostName(
const string& host_name);
291 virtual void CTLIB_SetPacketSize(
CS_INT packet_size);
292 virtual void CTLIB_SetLoginRetryCount(
CS_INT n);
293 virtual void CTLIB_SetLoginLoopDelay(
CS_INT nof_sec);
299 bool SetMaxConnect(
unsigned int num);
300 unsigned int GetMaxConnect(
void);
302 virtual CS_CONTEXT* CTLIB_GetContext(
void)
const;
327 return m_LoginRetryCount;
331 return m_LoginLoopDelay;
334 virtual void SetClientCharset(
const string& charset);
339 CRWLock& x_GetCtxLock(
void)
const;
351 void x_AddToRegistry(
void);
352 void x_RemoveFromRegistry(
void);
355 void x_Close(
bool delete_conn =
true);
356 bool x_SafeToFinalize(
void)
const;
358 #if defined(FTDS_IN_USE) && NCBI_FTDS_VERSION >= 95
359 typedef int (*FIntHandler)(
void*);
360 FIntHandler m_OrigIntHandler;
378 friend class ncbi::CDB_Connection;
399 CS_INT GetBLKVersion(
void)
const;
421 virtual bool IsAlive(
void);
424 return m_Handle.IsOpen();
427 void DeferTimeout(
void);
429 #if defined(FTDS_IN_USE) && NCBI_FTDS_VERSION >= 95
430 void SetCancelTimedOut(
bool val)
432 m_CancelTimedOut =
val;
435 bool GetCancelTimedOut(
void)
const
437 return m_CancelTimedOut;
443 virtual CDB_LangCmd* LangCmd (
const string& lang_query);
444 virtual CDB_RPCCmd* RPC (
const string& rpc_name);
448 unsigned int batch_size = 1);
452 bool dump_results =
true);
457 virtual bool Refresh(
void);
469 virtual bool Abort(
void);
474 virtual bool Close(
void);
482 return !
IsValid() || GetNativeConnection().IsDead();
486 GetNativeConnection().SetDead(flag);
491 virtual void SetTimeout(
size_t nof_secs);
492 virtual void SetCancelTimeout(
size_t nof_secs);
494 virtual size_t GetTimeout(
void)
const;
495 virtual size_t GetCancelTimeout(
void)
const;
497 virtual unsigned int GetRowsInCurrentBatch(
void)
const;
499 size_t PrepareToCancel(
void);
500 void CancelFinished(
size_t was_timeout);
503 virtual TSockHandle GetLowLevelHandle(
void)
const;
504 virtual string GetVersionString(
void)
const;
507 const string& cursor_name,
510 void CompleteBlobDescriptors(vector<I_BlobDescriptor*>& descs,
511 const string& cursor_name);
514 void x_LoadTextPtrProcs(
void);
523 bool x_IsLegacyBlobColumnType(
const string&
table_name,
524 const string& column_name);
567 class CAsyncCancelGuard
571 ~CAsyncCancelGuard(
void);
575 friend class CAsyncCancelGuard;
579 # if NCBI_FTDS_VERSION >= 95
580 static int x_IntHandler(
void* param);
581 typedef int (*FIntHandler)(
void*);
582 FIntHandler m_OrigIntHandler;
591 bool m_CancelTimedOut;
593 static int x_TimeoutFunc(
void* param,
unsigned int total_timeout);
594 int (*m_OrigTimeoutFunc)(
void*,
unsigned int);
595 void *m_OrigTimeoutParam;
599 size_t m_OrigTimeout;
600 unsigned int m_BaseTimeout;
601 unsigned int m_TotalTimeout;
602 bool m_AsyncCancelAllowed;
603 bool m_AsyncCancelRequested;
620 const string&
query);
630 #ifdef USE_STRUCT_CS_VARCHAR
650 bool dump_results =
true);
654 return GetConnection().IsMultibyteClientEncoding();
659 return GetConnection().GetClientEncoding();
678 m_DbgInfo->extra_msg =
info;
682 return m_DbgInfo->extra_msg;
687 return GetConnection().IsDead();
691 GetConnection().SetDead(flag);
698 GetConnection(), GetLastParams());
703 CBaseCmd::SetHasFailed(flag);
704 if (flag && !GetConnection().IsAlive()) {
707 GetConnection(), GetLastParams());
738 void EnsureActiveStatus(
void);
767 const string&
query);
775 const string& param_name,
777 bool declare_only =
false
779 void GetRowCount(
int*
cnt);
785 inline void DeleteResult(
void);
786 inline void DeleteResultInternal(
void);
787 inline void MarkEndOfReply(
void);
789 inline bool HaveResult(
void)
const;
802 inline bool ProcessResultInternal(
CS_INT res_type);
806 unsigned int msg_num);
809 void DropSybaseCmd(
void);
827 const string&
query);
833 bool Cancel(
void)
override;
838 bool SendInternal(
void);
857 const string& lang_query);
863 virtual bool Send(
void);
865 virtual bool HasMoreResults(
void)
const;
866 virtual int RowCount(
void)
const;
869 bool x_AssignParams(
void);
888 const string& proc_name
895 virtual bool Send(
void);
897 virtual bool HasMoreResults(
void)
const;
898 virtual int RowCount(
void)
const;
901 bool x_AssignParams(
void);
920 const string& cursor_name,
922 unsigned int fetch_size
926 void CloseForever(
void);
930 virtual bool Update(
const string&
table_name,
const string& upd_query);
935 bool dump_results =
true);
936 virtual bool Delete(
const string&
table_name);
937 virtual int RowCount(
void)
const;
938 virtual bool CloseCursor(
void);
943 bool ProcessResults(
void);
946 bool x_AssignParams(
bool just_declare =
false);
965 const string& cursor_name,
967 unsigned int fetch_size);
972 virtual bool Update(
const string&
table_name,
const string& upd_query);
977 bool dump_results =
true);
978 virtual bool Delete(
const string&
table_name);
979 virtual int RowCount(
void)
const;
980 virtual bool CloseCursor(
void);
985 void ClearResultSet(
void);
988 return m_CombinedQuery;
992 bool x_AssignParams(
void);
996 unique_ptr<CTL_CursorResultExpl>
m_Res;
1022 virtual bool Bind(
unsigned int column_num,
CDB_Object* param_ptr);
1023 virtual bool Send(
void);
1024 virtual bool CommitBCPTrans(
void);
1025 virtual bool Cancel(
void);
1026 virtual bool EndBCP(
void);
1027 virtual int RowCount(
void)
const;
1034 bool x_AssignParams(
void);
1035 bool x_IsUnicodeClientAPI(
void)
const;
1041 void x_BlkSetHints(
void);
1060 unsigned int param_num = GetBindParamsImpl().NofParams();
1092 virtual bool Cancel(
void);
1095 virtual size_t SendChunk(
const void* chunk_ptr,
size_t nof_bytes);
1097 virtual bool HasMoreResults(
void)
const;
1098 virtual int RowCount(
void)
const;
1104 string m_UTF8Fragment;
1133 virtual bool Fetch(
void);
1305 { m_Descriptors.insert(&desc); }
1307 { m_Descriptors.erase(&desc); }
1311 const string& cursor_name) :
1319 virtual bool SkipItem(
void);
1320 virtual bool Fetch(
void);
1322 void x_InvalidateDescriptors(
void);
1341 virtual bool Fetch(
void);
1342 virtual int CurrentItemNo(
void)
const;
1343 virtual int GetColumnNum(
void)
const;
1346 virtual size_t ReadItem(
void*
buffer,
size_t buffer_size,
1350 return GetBlobDescriptor(m_CurItemNo);
1353 virtual bool SkipItem(
void);
1373 void ClearFields(
void);
1394 return GetCTLConn().CheckWhileOpening(rc);
1405 return m_ActiveCmd ? m_ActiveCmd->GetLastParams() :
NULL;
1411 return m_ActiveCmd ? m_ActiveCmd->GetRowsInCurrentBatch() : 0
U;
1420 conn.m_OrigTimeout =
conn.GetTimeout();
1421 conn.m_BaseTimeout = 0;
1422 # if NCBI_FTDS_VERSION >= 95
1423 conn.m_TotalTimeout = 0;
1425 conn.m_AsyncCancelAllowed =
true;
1426 conn.m_AsyncCancelRequested =
false;
1427 # if NCBI_FTDS_VERSION < 95
1428 if (
conn.m_OrigTimeout == 0) {
1435 CTL_Connection::CAsyncCancelGuard::~CAsyncCancelGuard(
void)
1438 m_Conn.SetTimeout(m_Conn.m_OrigTimeout);
1439 m_Conn.m_AsyncCancelAllowed =
false;
1443 #ifdef USE_STRUCT_CS_VARCHAR
1458 sizeof(
CS_VARCHAR) -
sizeof(m_Data->str) + m_Data->len);
1540 return (m_Res !=
NULL);
1600 if ( HaveResult() ) {
1610 m_Res->m_EOR =
true;
1644 #define CTL_BLOB_DESCRIPTOR_TYPE_MAGNUM 0xc00
1645 #define CTL_BLOB_DESCRIPTOR_TYPE_CURSOR 0xc01
1658 virtual int DescriptorType(
void)
const;
1676 const string& column_name,
1680 int DescriptorType(
void)
const;
1691 #define CTL_ITDESCRIPTOR_TYPE_MAGNUM CTL_BLOB_DESCRIPTOR_TYPE_MAGNUM
1692 #define CTL_ITDESCRIPTOR_TYPE_CURSOR CTL_BLOB_DESCRIPTOR_TYPE_CURSOR
AutoArray< SBcpBind > & GetBind(void)
AutoArray< SBcpBind > m_BindArray
CS_BLKDESC * x_GetSybaseCmd(void) const
map< CDB_BCPInCmd::EBCP_Hints, string > THintsMap
unique_ptr< CDB_Exception > m_Context
Set only when m_Desc lacks a valid textptr.
void SetValue(const CTempString &s)
CTempString GetValue(void) const
CDB_SendDataCmd * ConnSendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool dump_results=true)
virtual bool x_Cancel(ECancelType)
CTL_Connection::TDbgInfo TDbgInfo
bool x_SendData(I_BlobDescriptor &desc, CDB_Stream &img, bool log_it=true)
void SetDead(bool flag=true)
void SetTimedOut(bool val)
void DropCmd(impl::CCommand &cmd)
CRef< TDbgInfo > m_DbgInfo
void SetRetriable(ERetriable val)
CTL_Connection & GetConnection(void)
bool IsMultibyteClientEncoding(void) const
const string & GetExecCntxInfo(void) const
ERetriable GetRetriable(void) const
bool GetTimedOut(void) const
virtual void SetHasFailed(bool flag=true)
void SetExecCntxInfo(const string &info)
const TDbgInfo & GetDbgInfo(void) const
EEncoding GetClientEncoding(void) const
CTL_RowResult * MakeStatusResult(void)
void SetResult(CTL_RowResult *result)
CTL_RowResult * MakeRowResult(void)
void MarkEndOfReply(void)
bool ProcessResultInternal(CDB_Result &res)
void SetSybaseCmd(CS_COMMAND *cmd)
bool HaveResult(void) const
CTL_RowResult * MakeComputeResult(void)
CTL_RowResult * MakeCursorResult(void)
CS_COMMAND * x_GetSybaseCmd(void) const
void DeleteResultInternal(void)
CTL_RowResult & GetResult(void)
CTL_RowResult * MakeParamResult(void)
CTL_ComputeResult(CS_COMMAND *pCmd, CTL_Connection &conn)
bool m_ForCancelInProgress
const TDbgInfo & GetDbgInfo()
bool IsForCancelInProgress(void)
CTL_Connection & GetConnection()
const CDBParams * GetLastParams()
const CDBParams * GetLastParams(void) const
const CTLibContext & GetCTLibContext(void) const
CS_RETCODE CheckSFB(CS_RETCODE rc, const char *msg, unsigned int msg_num)
friend class CTL_CursorCmdExpl
friend class CTL_SendDataCmd
CS_RETCODE Check(CS_RETCODE rc)
ctlib::Connection m_Handle
bool IsCancelInProgress(void) const
bool x_SendData(I_BlobDescriptor &desc, CDB_Stream &img, bool log_it=true)
void SetDead(bool flag=true)
friend class CTL_CursorCmd
bool m_TextPtrProcsLoaded
virtual unsigned int GetRowsInCurrentBatch(void) const
ctlib::Connection & GetNativeConnection(void)
CTL_CmdBase * m_ActiveCmd
unsigned int m_ActivityLevel
CMutex m_CancelLogisticsMutex
bool x_ProcessResultInternal(CS_COMMAND *cmd, CS_INT res_type)
const TDbgInfo & GetDbgInfo(void) const
CTLibContext & GetCTLibContext(void)
virtual CDB_SendDataCmd * SendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool dump_results=true)
"Send-data" command
virtual bool Close(void)
Close an open connection.
const ctlib::Connection & GetNativeConnection(void) const
friend class CTL_BCPInCmd
CS_CONNECTION * x_GetSybaseConn(void) const
CTL_CursorResult * m_CursorResult
CTL_CursorResultExpl * GetResultSet(void) const
void ClearResultSet(void)
unique_ptr< CTL_LangCmd > m_LCmd
const string GetCombinedQuery(void) const
void SetResultSet(CTL_CursorResultExpl *res)
unique_ptr< CTL_CursorResultExpl > m_Res
virtual bool SkipItem(void)
Skip result item.
void ClearResultSet(void)
vector< I_BlobDescriptor * > m_BlobDescrs
virtual CDB_Object * GetItem(CDB_Object *item_buff=0, I_Result::EGetItem policy=I_Result::eAppendLOB)
Get a result item (you can use either GetItem or ReadItem).
CTL_LangCmd & GetCmd(void)
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)
Read a result item body (for BLOB columns, mostly).
CTL_LangCmd const & GetCmd(void) const
vector< CDB_Object * > m_Fields
virtual int GetColumnNum(void) const
Return number of columns in the recordset.
virtual I_BlobDescriptor * GetBlobDescriptor(void)
Get a descriptor for a BLOB column (for SendData).
virtual bool Fetch(void)
Fetch next row.
void SetResultSet(CDB_Result *res)
virtual EDB_ResType ResultType(void) const
Get type of the result.
void FetchAllResultSet(void)
CDB_Result * GetResultSet(void) const
virtual int CurrentItemNo(void) const
Return current item number we can retrieve (0,1,...) Return "-1" if no more items left (or available)...
const string & GetCursorName(void) const
CTL_CursorResult(CS_COMMAND *pCmd, CTL_Connection &conn, const string &cursor_name)
void RegisterDescriptor(CTL_CursorBlobDescriptor &desc)
void UnregisterDescriptor(CTL_CursorBlobDescriptor &desc)
set< CTL_CursorBlobDescriptor * > m_Descriptors
CTL_ParamResult(CS_COMMAND *pCmd, CTL_Connection &conn)
unique_ptr< CDBParams > m_InParams
unsigned char m_BindBuff[2048]
CTL_RowResult(CS_COMMAND *cmd, CTL_Connection &conn)
AutoArray< CS_VOID * > m_BindItem
AutoArray< CS_DATAFMT > m_ColFmt
AutoArray< ENullValue > m_NullValue
const CTL_Connection & GetConnection(void) const
void SetCurrentItemNum(int num)
void CheckIsDead(void) const
static EDB_Type ConvDataType_Ctlib2DBAPI(const CS_DATAFMT &fmt)
AutoArray< CS_SMALLINT > m_Indicator
virtual ~CTL_RowResult(void)
CDB_Object * GetItemInternal(I_Result::EGetItem policy, CS_COMMAND *cmd, CS_INT item_no, CS_DATAFMT &fmt, CDB_Object *item_buf)
CTL_Connection * m_Connect
CTL_Connection & GetConnection(void)
CS_RETCODE Check(CS_RETCODE rc)
AutoArray< CS_INT > m_Copied
CS_COMMAND * x_GetSybaseCmd(void) const
const CDBParams * GetLastParams(void) const
friend class CTL_Connection
const CTL_Connection::TDbgInfo & GetDbgInfo(void) const
void IncCurrentItemNum(void)
CS_RETCODE my_ct_get_data(CS_COMMAND *cmd, CS_INT item, CS_VOID *buffer, CS_INT buflen, CS_INT *outlen, bool &is_null)
int GetCurrentItemNum(void) const
CDB_BlobDescriptor::ETDescriptorType m_DescrType
CTL_StatusResult(CS_COMMAND *pCmd, CTL_Connection &conn)
CS_INT GetLoginRetryCount(void) const
CS_INT GetPacketSize(void) const
CTLibContextRegistry * m_Registry
CS_INT GetLoginLoopDelay(void) const
CS_INT GetTDSVersion(void) const
CS_LOCALE * GetLocale(void) const
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
const CTL_Connection & GetCTLConn(void) const
CS_COMMAND * GetNativeHandle(void) const
CTL_Connection & GetCTLConn(void)
CTL_Connection * m_CTL_Conn
CS_CONNECTION * GetNativeHandle(void) const
const CTLibContext & GetCTLContext(void) const
CTLibContext * m_CTL_Context
CTL_Connection * m_CTL_Conn
CTLibContext & GetCTLContext(void)
void SetDead(bool flag=true)
string GetCmdName(void) const
impl::CConnection & GetConnImpl(void) const
void DropCmd(impl::CCommand &cmd)
CTL_BlobDescriptor CTL_ITDescriptor
CTL_CursorBlobDescriptor CTL_CursorITDescriptor
CS_INT GetCtlibTdsVersion(int version=0)
static CS_CONNECTION * conn
static const char table_name[]
static const column_t columns[]
ERetriable
Can the action be retried?
#define NCBI_DATABASE_THROW_ANNOTATED(ex_class, message, err_code, severity, dbg_info, conn, params)
ECapability
Report if the driver supports this functionality.
EBCP_Hints
Type of hint that can be set.
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
@ eDiag_Error
Error message.
bool IsValid(const CSeq_point &pt, CScope *scope)
Checks that point >= 0 and point < length of Bioseq.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
const char * data(void) const
Return a pointer to the array represented.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
size_type size(void) const
Return the length of the represented array.
#define NCBI_DBAPIDRIVER_CTLIB_EXPORT
unsigned int
A callback function used to compare two keys in a database.
const string version
version string
void Check(const string &value)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
static void x_Close(SHttpConnector *uuu)
Static variables safety - create on demand, destroy on application termination.
CRef< T > MakeResult(CRef< T > result)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
static CS_CONTEXT * context