40 # include <winsock2.h>
41 #elif !defined(NCBI_OS_SOLARIS)
42 # include <sys/fcntl.h>
43 # include <sys/types.h>
44 # include <sys/socket.h>
47 #define NCBI_USE_ERRCODE_X Dbapi_DataServer
60 for (
unsigned int i = 0,
n = params.
GetNum();
i <
n; ++
i) {
62 const string& name = params.
GetName(
i);
66 <<
"Column #" << (
i + 1) <<
" = " <<
value
70 <<
"Parameter #" << (
i + 1) <<
" (" << name <<
") = " <<
value
76 # define TRACE_PARAMS(params) s_TraceParams(params, DIAG_COMPILE_INFO)
78 # define TRACE_PARAMS(params) ((void)0)
91 return static_cast<unsigned int>(
value);
95 : m_IsPositional(
true)
102 : m_IsPositional(
true)
109 : m_IsPositional(
false)
111 , m_Name(MakeName(name, m_Format))
116 : m_IsPositional(
false)
118 , m_Name(MakeName(name, m_Format))
161 for (; c !=
NULL && c != name.
end(); ++c) {
163 if (ch ==
' ' || ch ==
'\t' || ch ==
'\n' || ch ==
'\r') {
164 if (begin_str ==
NULL) {
169 bool space_chars_only =
true;
170 for (
const char* tc = c; tc !=
NULL && *tc !=
'\0'; ++tc) {
172 if (tch ==
' ' || tch ==
'\t' || tch ==
'\n' || tch ==
'\r') {
175 space_chars_only =
false;
180 if (space_chars_only) {
187 if (begin_str ==
NULL) {
220 if (begin_str !=
NULL) {
221 new_name.
assign(begin_str, c - begin_str);
235 for (; c !=
NULL && c != name.
end(); ++c) {
237 if (ch ==
' ' || ch ==
'\t' || ch ==
'\n' || ch ==
'\r') {
238 if (begin_str ==
NULL) {
243 bool space_chars_only =
true;
244 for (
const char* tc = c; tc !=
NULL && *tc !=
'\0'; ++tc) {
246 if (tch ==
' ' || tch ==
'\t' || tch ==
'\n' || tch ==
'\r') {
249 space_chars_only =
false;
254 if (space_chars_only) {
261 if (begin_str ==
NULL) {
263 if (ch ==
':' || ch ==
'@' || ch ==
'$' || ch ==
'%') {
270 if (begin_str !=
NULL) {
271 plain_name.
assign(begin_str, c - begin_str);
283 : m_ConnImpl(c), m_HasTransaction(
false)
307 #ifndef NCBI_OS_SOLARIS
317 int orig_flags = fcntl(s, F_GETFL, 0);
318 fcntl(s, F_SETFL, orig_flags | O_NONBLOCK);
320 int n = recv(s, &c, 1, MSG_PEEK);
322 if ((orig_flags & O_NONBLOCK) != O_NONBLOCK) {
323 fcntl(s, F_SETFL, orig_flags);
331 # ifdef NCBI_OS_MSWIN
332 return WSAGetLastError() == WSAEWOULDBLOCK;
336 # if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
352 #define CHECK_CONNECTION( conn ) \
353 CHECK_DRIVER_WARNING( !conn, "Connection has been closed", 200002 )
358 _TRACE(
"Sending SQL: " << lang_query);
378 unsigned int batch_size)
391 _TRACE(
"Sending " << data_size <<
" byte(s) of data");
399 _TRACE(
"Sending " << lob.
Size() <<
" byte(s) of data");
410 _TRACE(
"Now using database " << name);
533 unique_ptr<CDB_LangCmd> lcmd(
LangCmd(
"IF @@TRANCOUNT > 0 ROLLBACK"));
605 #define CHECK_RESULT( res ) \
606 CHECK_DRIVER_WARNING( !res, "This result is not available anymore", 200003 )
728 #define CHECK_COMMAND( cmd ) \
729 CHECK_DRIVER_WARNING( !cmd, "This command cannot be used anymore", 200005 )
1179 const string& column_name,
1180 const string& search_conditions,
1184 , m_ColumnName(column_name)
1185 , m_SearchConditions(search_conditions)
1186 , m_ColumnType(column_type)
1187 , m_HasLegacyType(has_legacy_type)
1268 , m_Conn(
subject.m_Connection)
1276 unique_ptr<CDB_LangCmd> auto_stmt
1279 auto_stmt->DumpResults();
1294 "it is not finished yet.");
1316 unique_ptr<CDB_LangCmd> auto_stmt(
m_Conn.
LangCmd(
"BEGIN TRANSACTION"));
1318 auto_stmt->DumpResults();
1325 unique_ptr<CDB_LangCmd> auto_stmt(
m_Conn.
LangCmd(
"COMMIT"));
1327 auto_stmt->DumpResults();
1334 unique_ptr<CDB_LangCmd> auto_stmt
1337 auto_stmt->DumpResults();
1352 unique_ptr<CDB_LangCmd> auto_stmt(
m_Conn.
LangCmd(
"SELECT @@trancount as tc"));
1354 if (auto_stmt->Send()) {
1355 while(auto_stmt->HasMoreResults()) {
1356 unique_ptr<CDB_Result> rs(auto_stmt->Result());
1358 if (rs.get() ==
NULL) {
1368 rs->GetItem(&tran_count);
1372 while(rs->Fetch()) {
Helper class to allow safe initialization from higher-layer objects.
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
virtual CDBParams & GetDefineParams(void)
Get meta-information about defined parameters.
const string & GetQuery(void) const
virtual CDBParams & GetBindParams(void)
Binding.
bool WasCanceled(void) const
unsigned int m_RowsSentAtBatchStart
virtual bool Update(const string &table_name, const string &upd_query)
Update the last fetched row.
virtual bool CommitBCPTrans(void)
Complete batch – to store all rows transferred by far in this batch into the table.
void SetRecompile(bool recompile=true)
Set the "recompile before execute" flag for the stored proc.
virtual void AddOrderHint(CTempString columns)
Add "ORDER" hint.
virtual CDB_Result * Result(void)
Get result set.
virtual void AddHint(CDB_BCPInCmd::EBCP_Hints hint, unsigned int value)
Add hint with value.
virtual bool HasFailed(void) const
virtual void SetHints(CTempString hints)
Set hints by one call.
void DumpResults(void)
Dump the results of the command if result processor is installed for this connection,...
virtual bool UpdateBlob(unsigned int item_num, CDB_Stream &data, bool log_it=true)
virtual CDB_Result * OpenCursor(void)
Open the cursor.
virtual bool EndBCP(void)
Complete the BCP and store all rows transferred in last batch into the table.
virtual CDB_SendDataCmd * SendDataCmd(unsigned int item_num, size_t size, bool log_it=true, bool dump_results=true)
void AttachTo(CDB_LangCmd *interface)
virtual bool Delete(const string &table_name)
Delete the last fetched row.
virtual bool CloseCursor(void)
Close the cursor.
unsigned int m_BatchesSent
virtual bool Cancel(void)
Cancel the command execution.
virtual bool HasMoreResults(void) const
virtual bool Send(void)
Send command to the server.
unsigned int GetRowsInCurrentBatch(void) const
bool More(const string &query_text)
Add more text to the language command.
virtual int RowCount(void) const =0
Get the number of rows affected by the command Special case: negative on error or if there is no way ...
virtual bool Abort(void)=0
abort the connection Attention: it is not recommended to use this method unless you absolutely have t...
virtual void SetTimeout(size_t nof_secs)=0
virtual TSockHandle GetLowLevelHandle(void) const
Get OS handle of the socket represented by the connection.
void AttachTo(CDB_Connection *interface)
virtual CDB_SendDataCmd * SendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool dump_results=true)=0
"Send-data" command
virtual string GetVersionString(void) const
const string & UserName(void) const
I_DriverContext * Context(void) const
Get pointer to the driver context.
const string & GetDatabaseName(void) const
virtual CDB_RPCCmd * RPC(const string &rpc_name)=0
Remote procedure call.
CDB_ResultProcessor * SetResultProcessor(CDB_ResultProcessor *rp)
bool IsReusable(void) const
Check if this connection is a reusable one.
CDBConnParams::EServerType GetServerType(void)
unsigned int GetReuseCount(void) const
const string & Password(void) const
virtual string GetDriverName(void) const
virtual void SetCancelTimeout(size_t nof_secs)=0
virtual bool IsAlive(void)=0
Check out if connection is alive (this function doesn't ping the server, it just checks the status of...
virtual CDB_BCPInCmd * BCPIn(const string &table_name)=0
"Bulk copy in" command
const string & ServerName(void) const
Get the server name, user login name, and password.
virtual I_DriverContext::TConnectionMode ConnectMode(void) const =0
Get the bitmask for the connection mode (BCP, secure login, ...)
virtual bool Refresh(void)=0
Reset the connection to the "ready" state (cancel all active commands)
const string & PoolName(void) const
Find out which connection pool this connection belongs to.
virtual void SetDatabaseName(const string &name)
virtual bool SendData(I_BlobDescriptor &desc, CDB_Stream &lob, bool log_it=true)=0
Shortcut to send text and image to the server without using the "Send-data" command (SendDataCmd)
virtual size_t GetCancelTimeout(void) const
void PushMsgHandler(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
Put the message handler into message handler stack.
virtual CDB_CursorCmd * Cursor(const string &cursor_name, const string &query, unsigned int batch_size=1)=0
Cursor.
void PopMsgHandler(CDB_UserHandler *h)
Remove the message handler (and all above it) from the stack.
virtual size_t GetTimeout(void) const
virtual CDB_LangCmd * LangCmd(const string &lang_query)=0
These methods: LangCmd(), RPC(), BCPIn(), Cursor() and SendDataCmd() create and return a "command" ob...
virtual CDB_Object * GetItem(CDB_Object *item_buf=0, I_Result::EGetItem policy=I_Result::eAppendLOB)=0
Get a result item (you can use either GetItem or ReadItem).
virtual I_BlobDescriptor * GetBlobDescriptor(void)=0
Get a descriptor for a BLOB column (for SendData).
virtual const CDBParams & GetDefineParams(void) const
virtual int CurrentItemNo(void) const =0
Return current item number we can retrieve (0,1,...) Return "-1" if no more items left (or available)...
virtual bool SkipItem(void)=0
Skip result item.
virtual int GetColumnNum(void) const =0
Return number of columns in the recordset.
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)=0
Read a result item body (for BLOB columns, mostly).
void AttachTo(CDB_Result *interface)
virtual EDB_ResType ResultType(void) const =0
Get type of the result.
virtual bool Fetch(void)=0
Fetch next row.
void AttachTo(CDB_SendDataCmd *interface)
virtual size_t SendChunk(const void *pChunk, size_t nofBytes)=0
Send chunk of data to the server.
virtual bool Cancel(void)=0
void DumpResults(void)
Dump the results of the command if result processor is installed for this connection,...
virtual bool HasMoreResults(void) const
virtual CDB_Result * Result(void)
Get result set.
static const char table_name[]
static const column_t columns[]
ETriState
Enumeration to represent a tristate value.
#define CHECK_DRIVER_WARNING(failed, message, err_code)
#define DATABASE_DRIVER_ERROR(message, err_code)
#define CHECK_DRIVER_ERROR(failed, message, err_code)
virtual EDB_Type GetDataType(const CDBParamVariant ¶m) const =0
Get data type for column in the resultset.
virtual const string & GetName(const CDBParamVariant ¶m, CDBParamVariant::ENameFormat format=CDBParamVariant::eSQLServerName) const =0
Get name of column.
virtual size_t GetMaxSize(const CDBParamVariant ¶m) const =0
Get maximum size in bytes for column.
static CTempString MakeName(const CTempString &name, ENameFormat &format)
virtual unsigned int GetNum(void) const =0
Get total number of columns in resultset.
virtual CDBParams & Bind(const CDBParamVariant ¶m, CDB_Object *value, bool out_param=false)
This method stores pointer to data.
static string MakePlainName(const CTempString &name)
ENameFormat GetFormat(void) const
virtual const CDB_Object * GetValue(const CDBParamVariant ¶m) const =0
Get value of column.
const string & GetName(void) const
virtual EDB_ResType ResultType() const
Get type of the result.
impl::CResult * GetIResultPtr(void) const
virtual I_ConnectionExtra & GetExtraFeatures(void)
Get interface for extra features that could be implemented in the driver.
virtual ~CDB_SendDataCmd()
size_t GetCancelTimeout(void) const
Get timeout for command cancellation and connection closing.
virtual bool SendRow()
Send row to the server.
virtual int GetColumnNum(void) const
Return number of columns in the recordset.
virtual bool CompleteBatch()
Complete batch – to store all rows transferred by far in this batch into the table.
CAutoTrans(const CSubject &subject)
virtual void SetRecompile(bool recompile=true)
Set the "recompile before execute" flag for the stored proc Implementation-specific.
virtual CDB_SendDataCmd * SendDataCmd(unsigned int item_num, size_t size, bool log_it=true, bool discard_results=true)
Make "send-data" command.
virtual size_t ItemMaxSize(unsigned int item_num) const
Get size (in bytes) of a result item.
virtual int RowCount() const
Get the number of fetched rows Special case: negative on error or if there is no way that this comman...
virtual CDB_Result * Result()
Get result set.
virtual CDB_BCPInCmd * BCPIn(const string &table_name)
Make "bulk copy in" command.
virtual ~CDB_ResultProcessor()
virtual CDB_SendDataCmd * SendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool discard_results=true)
Make "send-data" command.
impl::CConnection * m_ConnImpl
virtual bool WasCanceled() const
Implementation-specific.
virtual void SetCancelTimeout(size_t nof_secs)
Set timeout for command cancellation and connection closing.
virtual const string & UserName() const
Get the user user.
virtual ~CDB_Result()
Destructor.
virtual bool WasSent() const
Implementation-specific.
virtual string GetDriverName(void) const
virtual bool WasCanceled() const
Implementation-specific.
virtual CDB_Result * Result()
Get result set.
impl::CResult * m_ResImpl
impl::CResult & GetIResult(void) const
virtual bool Cancel()
Cancel the command execution.
impl::CSendDataCmd * m_CmdImpl
virtual bool HasFailed() const
Check if command has failed.
void SetConn(CDB_Connection *c)
virtual int RowCount() const
Get the number of rows affected by the command.
virtual CDB_Result * Result()
Get result set.
impl::CBaseCmd * m_CmdImpl
virtual bool Refresh()
Reset the connection to the "ready" state (cancel all active commands)
virtual bool UpdateBlob(unsigned int item_num, CDB_Stream &data, bool log_it=true)
virtual CDBParams & GetDefineParams(void)
Get meta-information about defined parameters.
virtual bool More(const string &query_text)
Add more text to the language command.
virtual CDB_Result * Open()
Open the cursor.
virtual bool WasSent() const
Implementation-specific.
virtual Uint4 Host() const
Get the host.
void AddOrderHint(CTempString columns)
Add "ORDER" hint.
virtual bool Send()
Send command to the server.
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
void AddHint(EBCP_Hints hint, unsigned int value=0)
Add hint with value.
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
virtual ~CDB_Connection()
Destructor.
virtual I_DriverContext::TConnectionMode ConnectMode() const
Get the bitmask for the connection mode (BCP, secure login, ...)
virtual bool Send()
Send command to the server.
virtual bool Delete(const string &table_name)
Delete the last fetched row.
virtual bool HasMoreResults() const
bool Bind(unsigned int column_num, CDB_Object *value)
virtual ~CDB_BlobDescriptor(void)
virtual bool SendData(I_BlobDescriptor &desc, CDB_Stream &lob, bool log_it=true)
Shortcut to send text and image to the server without using the "Send-data" command (SendDataCmd)
virtual bool CompleteBCP()
Complete the BCP and store all rows transferred in last batch into the table.
CDB_ResultProcessor * m_Next
CDB_ResultProcessor * m_Prev
virtual void DumpResults()
Dump the results of the command If result processor is installed for this connection,...
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
impl::CBaseCmd * m_CmdImpl
CDB_BlobDescriptor(const string &table_name, const string &column_name, const string &search_conditions, ETDescriptorType column_type=eUnknown, ETriState has_legacy_type=eTriState_Unknown)
virtual string GetVersionString(void) const
Driver version, supplied here rather than by the context for ODBC's sake.
unsigned int GetReuseCount() const
Indicate how many times (if at all) this connection has been previously used.
virtual EDB_Type ItemDataType(unsigned int item_num) const
Get datatype of a result item.
virtual bool Close()
Close the cursor.
virtual I_DriverContext * Context() const
Get pointer to the driver context.
virtual int CurrentItemNo() const
Return current item number we can retrieve (0,1,...)
impl::CBaseCmd * m_CmdImpl
virtual bool IsAlive()
Check out if connection is alive.
virtual bool IsReusable() const
Check if this connection is a reusable one.
virtual CDBParams & GetDefineParams(void)
Get meta-information about defined parameters.
virtual void DumpResults()
Dump the results of the command If result processor is installed for this connection,...
virtual bool SkipItem()
Skip result item.
virtual bool Abort()
Abort the connection.
virtual void DumpResults()
Dump the results of the command If result processor is installed for this connection,...
void SetDatabaseName(const string &name)
Set database name.
virtual size_t SendChunk(const void *data, size_t size)
Send chunk of data to the server.
virtual CDB_LangCmd * LangCmd(const string &lang_query)
Make language command.
virtual CDB_CursorCmd * Cursor(const string &cursor_name, const string &query, unsigned int batch_size)
Make cursor command.
virtual bool HasFailed() const
Check if command has failed.
virtual bool Close(void)
Close an open connection.
size_t GetTimeout(void) const
Get connection timeout.
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)
Read a result item body (for BLOB columns, mostly).
virtual const string & PoolName() const
Find out which connection pool this connection belongs to.
virtual void PushMsgHandler(CDB_UserHandler *h, EOwnership ownership=eNoOwnership)
Put the message handler into message handler stack.
virtual const string & ServerName() const
Get the server name.
EBCP_Hints
Type of hint that can be set.
virtual const string & DatabaseName(void) const
Get the database name.
virtual Uint2 Port() const
Get the port.
virtual CDB_Object * GetItem(CDB_Object *item_buf=0, EGetItem policy=eAppendLOB)
Get a result item (you can use either GetItem or ReadItem).
virtual bool Cancel()
Cancel the BCP command.
virtual const char * ItemName(unsigned int item_num) const
Get name of a result item.
virtual unsigned int NofItems() const
Get # of items (columns) in the result.
virtual void PopMsgHandler(CDB_UserHandler *h)
Remove the message handler (and all above it) from the stack.
virtual CDBParams & GetBindParams(void)
Get meta-information about parameters.
virtual I_BlobDescriptor * GetBlobDescriptor()
Get a descriptor for a BLOB column (for SendData).
impl::CBaseCmd * m_CmdImpl
virtual void ProcessResult(CDB_Result &res)
The default implementation just dumps all rows.
virtual CDB_RPCCmd * RPC(const string &rpc_name)
Make remote procedure call command.
virtual bool Cancel(void)
virtual void SetTimeout(size_t nof_secs)
Set connection timeout.
void BeginTransaction(void)
virtual bool HasMoreResults() const
Return TRUE if it makes sense (at all) to call Result()
virtual int DescriptorType(void) const
virtual bool Cancel()
Cancel the command execution.
void SetHints(CTempString hints)
Set hints by one call. Resets everything that was set by Add*Hint().
virtual bool HasMoreResults() const
virtual const string & GetProcName(void) const
Get a name of the procedure.
virtual bool Update(const string &table_name, const string &upd_query)
Update the last fetched row.
virtual const string & Password() const
Get the password.
virtual const CDBParams & GetDefineParams(void) const
Get meta-information about rows in resultset.
virtual CDBParams & GetDefineParams(void)
Get meta-information about defined parameters.
virtual int RowCount() const
Get the number of rows affected by the command Special case: negative on error or if there is no way ...
virtual CDB_ResultProcessor * SetResultProcessor(CDB_ResultProcessor *rp)
Set new result-processor.
virtual bool Fetch()
Fetch next row.
string GetLogString(void) const
virtual size_t Size() const
#define NCBI_CURRENT_FUNCTION
Get current function name.
const CNcbiDiag & GetRef(void) const
Some compilers (e.g.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
@ eDiag_Trace
Trace message.
#define NCBI_CATCH_ALL_X(err_subcode, message)
void Warning(CExceptionArgs_Base &args)
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
const_iterator end() const
Return an iterator to the string's ending position (one past the end of the represented sequence)
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
const char * const_iterator
const char * data(void) const
Return a pointer to the array represented.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
#define TRACE_PARAMS(params)
unsigned int ConvertI2UI(int value)
#define CHECK_COMMAND(cmd)
#define CHECK_CONNECTION(conn)
#define CHECK_RESULT(res)
static void s_TraceParams(const CDBParams ¶ms, const CDiagCompileInfo &info)