NCBI C++ ToolKit
connection.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: connection.cpp 102711 2024-06-28 14:39:22Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Vladimir Soussov
27  *
28  * File Description: ODBC connection
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbiapp.hpp>
35 #include <dbapi/driver/types.hpp>
36 #include <dbapi/error_codes.hpp>
37 #include <stdio.h>
38 #include <string.h>
39 
40 #ifdef HAVE_ODBCSS_H
41 // #include <odbcss.h>
42 #include <msodbcsql.h>
43 #endif
44 
45 #include "odbc_utils.hpp"
46 
47 // #define DEFAULT_ODBC_DRIVER_NAME "SQL Server"
48 #define DEFAULT_ODBC_DRIVER_NAME "ODBC Driver 18 for SQL Server"
49 
50 #define NCBI_USE_ERRCODE_X Dbapi_Odbc_Conn
51 
52 #undef NCBI_DATABASE_THROW
53 #define NCBI_DATABASE_THROW(ex_class, message, err_code, severity) \
54  NCBI_ODBC_THROW(ex_class, message, err_code, severity)
55 // No use of NCBI_DATABASE_RETHROW or DATABASE_DRIVER_*_EX here.
56 
57 // Accommodate all the code of the form
58 // string err_message = "..." + GetDbgInfo();
59 // DATABASE_DRIVER_ERROR(err_message, ...);
60 // which will still pick up the desired context due to
61 // NCBI_DATABASE_THROW's above redefinition.
62 #define GetDbgInfo() 0
63 
65 
66 bool IsBCPCapable(void)
67 {
68  return true;
69 }
70 
72  CDB_BlobDescriptor& descr_in,
73  SQLLEN size,
74  bool is_text,
75  bool logit,
76  SQLPOINTER id,
77  SQLLEN* ph);
78 
80  SQLPOINTER* id);
81 
82 ////////////////////////////////////////////////////////////////////////////////
84  const CDBConnParams& params) :
86  cntx,
87  params,
88  IsBCPCapable()
89  ),
90  m_Link(NULL),
91  m_ActiveStmt(NULL),
92  m_Reporter(0, SQL_HANDLE_DBC, NULL, this, &cntx.GetReporter()),
93  m_query_timeout(cntx.GetTimeout()),
94  m_cancel_timeout(cntx.GetCancelTimeout())
95 {
97 
98  SQLRETURN rc;
99 
100  {{
101  CWriteLockGuard guard(cntx.x_GetCtxLock());
103  cntx.GetODBCContext(),
104  const_cast<SQLHDBC*>(&m_Link));
105 
106  if (rc != SQL_SUCCESS) {
107  cntx.GetReporter().ReportErrors();
108  }
109  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
110  DATABASE_DRIVER_ERROR( "Cannot allocate a connection handle.",
111  100011 );
112  }
113  }}
114 
115  // This might look strange, but in current design all errors related to
116  // opening of a connection to a database are reported by a DriverContext.
117  // Have fun.
118  // cntx.SetupErrorReporter(params);
119  CODBC_Reporter opening_reporter(&params.GetOpeningMsgHandlers(),
120  SQL_HANDLE_DBC, m_Link, this,
121  &cntx.GetReporter());
122 
123  x_SetupErrorReporter(params);
124 
125  x_SetConnAttributesBefore(cntx, params);
126 
127  x_Connect(cntx, params, opening_reporter);
128 }
129 
130 
131 void
133 {
134  _ASSERT(m_Link);
135 
140 }
141 
143  CODBCContext& cntx,
144  const CDBConnParams& params,
145  const CODBC_Reporter& opening_reporter) const
146 {
147  SQLRETURN rc;
148  string server_name;
149 
150  if (params.GetHost()) {
151  server_name = impl::ConvertN2A(params.GetHost());
152  } else {
153  server_name = params.GetServerName();
154  }
155 
157 
158  if(!cntx.GetUseDSN()) {
159  string connect_str;
160  string conn_str_suffix = ";SERVER=" + server_name;
161 
162  if (params.GetHost() && params.GetPort()) {
163  conn_str_suffix +=
164  ";ADDRESS=" + server_name +
165  "," + NStr::IntToString(params.GetPort()) +
166  ";NETWORK=DBMSSOCN"
167  ;
168  }
169  conn_str_suffix +=
170  ";UID=" + params.GetUserName() +
171  ";PWD=" + params.GetPassword() +
172  ";TrustServerCertificate=yes"
173  ;
174 
176 
177  // Connection strings for SQL Native Client 2005.
178  // string connect_str("DRIVER={SQL Native Client};MultipleActiveResultSets=true;SERVER=");
179  // string connect_str("DRIVER={SQL Native Client};SERVER=");
180 
181  if (app) {
182  const string driver_name = x_GetDriverName(app->GetConfig());
183 
184  connect_str = "DRIVER={" + driver_name + "}";
185  } else {
186  connect_str = "DRIVER={" DEFAULT_ODBC_DRIVER_NAME "}";
187  }
188 
189  connect_str += conn_str_suffix;
190 
191  TSqlString connect_str_ss = x_MakeTSqlString(connect_str, enc);
192 
194  0,
195  const_cast<TSqlChar*>(connect_str_ss.data()),
196  connect_str_ss.size(),
197  0,
198  0,
199  0,
201  }
202  else {
203  TSqlString server_name_ss = x_MakeTSqlString(server_name, enc);
204  TSqlString username_ss = x_MakeTSqlString(params.GetUserName(), enc);
205  TSqlString password_ss = x_MakeTSqlString(params.GetPassword(), enc);
206  rc = SQLConnect(m_Link,
207  const_cast<TSqlChar*>(server_name_ss.data()),
208  server_name_ss.size(),
209  const_cast<TSqlChar*>(username_ss.data()),
210  username_ss.size(),
211  const_cast<TSqlChar*>(password_ss.data()),
212  password_ss.size());
213  }
214 
215  if (!cntx.CheckSIE(rc, m_Link, opening_reporter)) {
216  string err;
217 
218  err += "Cannot connect to the server '" + server_name;
219  err += "' as user '" + params.GetUserName() + "'";
220  DATABASE_DRIVER_ERROR( err, 100011 );
221  }
222 }
223 
224 
225 void
227  const CODBCContext& cntx,
228  const CDBConnParams& params)
229 {
230  SQLULEN timeout, login_timeout;
231  NStr::StringToNumeric(params.GetParam("timeout"), &timeout);
232  NStr::StringToNumeric(params.GetParam("login_timeout"), &login_timeout);
234  0);
236  (SQLPOINTER)login_timeout, 0);
237 
238  if(cntx.GetPacketSize()) {
242  0);
243  }
244 
245 #ifdef SQL_COPT_SS_BCP
246  // Always enable BCP ...
248  SQL_COPT_SS_BCP,
249  (SQLPOINTER) SQL_BCP_ON,
251 #endif
252 }
253 
254 
255 string
257 {
258  enum EState {eStInitial, eStSingleQuote};
259  vector<string> driver_names;
260  const string odbc_driver_name =
261  registry.GetString("ODBC", "DRIVER_NAME",
262  "'" DEFAULT_ODBC_DRIVER_NAME "'");
263 
264  NStr::Split(odbc_driver_name, " ", driver_names,
266  EState state = eStInitial;
267  string driver_name;
268 
269  ITERATE(vector<string>, it, driver_names) {
270  bool complete_deriver_name = false;
271  const string cur_str(*it);
272 
273  // Check for quotes ...
274  if (state == eStInitial) {
275  if (cur_str[0] == '\'') {
276  if (cur_str[cur_str.size() - 1] == '\'') {
277  // Skip quote ...
278  driver_name = it->substr(1, cur_str.size() - 2);
279  complete_deriver_name = true;
280  } else {
281  // Skip quote ...
282  driver_name = it->substr(1);
283  state = eStSingleQuote;
284  }
285  } else {
286  driver_name = cur_str;
287  complete_deriver_name = true;
288  }
289  } else if (state == eStSingleQuote) {
290  if (cur_str[cur_str.size() - 1] == '\'') {
291  // Final quote ...
292  driver_name += " " + cur_str.substr(0, cur_str.size() - 1);
293  state = eStInitial;
294  complete_deriver_name = true;
295  } else {
296  driver_name += " " + cur_str;
297  }
298  }
299 
300  if (complete_deriver_name) {
301  return driver_name;
302  }
303  }
304 
305  return driver_name;
306 }
307 
308 
310 {
311  string str_version = "TDS_Version=";
312 
313  switch ( version )
314  {
315  case 42:
316  str_version += "4.2;Port=2158";
317  break;
318  case 46:
319  str_version += "4.6";
320  break;
321  case 50:
322  str_version += "5.0;Port=2158";
323  break;
324  case 70:
325  str_version += "7.0";
326  break;
327  //case 80:
328  // str_version += "8.0";
329  // break;
330  default:
331  // DATABASE_DRIVER_ERROR( "Invalid TDS version with the FreeTDS driver.", 100000 );
332  //str_version += "8.0";
333  //break;
334  return string();
335  }
336 
337  return str_version;
338 }
339 
340 
342 {
343  if (m_Link) {
344  SQLINTEGER status;
346 
347  return ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (status == SQL_CD_FALSE));
348  }
349 
350  return (m_Link != NULL);
351 }
352 
353 
354 CODBC_LangCmd* CODBC_Connection::xLangCmd(const string& lang_query)
355 {
356  CODBC_LangCmd* lcmd = new CODBC_LangCmd(*this, lang_query);
357  return lcmd;
358 }
359 
360 CDB_LangCmd* CODBC_Connection::LangCmd(const string& lang_query)
361 {
362  return Create_LangCmd(*(xLangCmd(lang_query)));
363 }
364 
365 
366 CDB_RPCCmd* CODBC_Connection::RPC(const string& rpc_name)
367 {
368  CODBC_RPCCmd* rcmd = new CODBC_RPCCmd(*this, rpc_name);
369  return Create_RPCCmd(*rcmd);
370 }
371 
372 
374 {
375  if ( !IsBCPable() ) {
376  string err_message = "No bcp on this connection." + GetDbgInfo();
377  DATABASE_DRIVER_ERROR( err_message, 410003 );
378  }
379 
380  CODBC_BCPInCmd* bcmd = new CODBC_BCPInCmd(*this, m_Link, table_name);
381  return Create_BCPInCmd(*bcmd);
382 }
383 
384 
385 CDB_CursorCmd* CODBC_Connection::Cursor(const string& cursor_name,
386  const string& query,
387  unsigned int batch_size)
388 {
389 #if 1
390  CODBC_CursorCmdExpl* ccmd = new CODBC_CursorCmdExpl(*this,
391  cursor_name,
392  query);
393 #else
394  CODBC_CursorCmd* ccmd = new CODBC_CursorCmd(*this,
395  cursor_name,
396  query);
397 #endif
398 
399  return Create_CursorCmd(*ccmd);
400 }
401 
402 
404  size_t data_size,
405  bool log_it,
406  bool dump_results)
407 {
408  CODBC_SendDataCmd* sd_cmd =
409  new CODBC_SendDataCmd(*this,
410  (CDB_BlobDescriptor&)descr_in,
411  data_size,
412  log_it,
413  dump_results);
414  return Create_SendDataCmd(*sd_cmd);
415 }
416 
417 
419  bool log_it)
420 {
421  CStatementBase stmt(*this, kEmptyStr);
422 
423  SQLPOINTER p = (SQLPOINTER)2;
424  SQLLEN s = lob.Size();
425  SQLLEN ph;
426 
429 
431  desc_type = CDB_BlobDescriptor::eBinary;
432  } else {
433  desc_type = CDB_BlobDescriptor::eText;
434  }
435 
437  stmt,
438  (CDB_BlobDescriptor&)desc,
439  s,
440  (desc_type == CDB_BlobDescriptor::eText),
441  log_it,
442  p,
443  &ph
444  )) ||
445  (!ODBC_xSendDataGetId(stmt, &p ))) {
446  string err_message = "Cannot prepare a command." + GetDbgInfo();
447  DATABASE_DRIVER_ERROR( err_message, 410035 );
448  }
449 
450  return x_SendData(desc_type, stmt, lob);
451 
452 }
453 
454 
456 {
457  // close all commands first
459 
460  return IsAlive();
461 }
462 
463 
465 {
467  if ( IsBCPable() ) {
469  }
470  if ( HasSecureLogin() ) {
472  }
473  return mode;
474 }
475 
476 
478 {
479  try {
480  Close();
481 
483  ReportErrors();
484  }
485  }
487  if (m_ActiveStmt) {
488  m_ActiveStmt->m_IsActive = false;
489  }
490 }
491 
492 
494 {
496  MarkClosed();
497  return false;
498 }
499 
501 {
502  if (Refresh()) {
503  switch(SQLDisconnect(m_Link)) {
505  case SQL_ERROR:
506  ReportErrors();
507  case SQL_SUCCESS:
508  break;
509  default:
510  {
511  string err_message = "SQLDisconnect failed (memory corruption suspected)." + GetDbgInfo();
512  DATABASE_DRIVER_ERROR( err_message, 410009 );
513  }
514  }
515 
516  MarkClosed();
517 
518  return true;
519  }
520 
521  return false;
522 }
523 
524 void CODBC_Connection::SetTimeout(size_t nof_secs)
525 {
526  m_query_timeout = nof_secs;
527 }
528 
530 {
531  m_cancel_timeout = nof_secs;
532 }
533 
535 {
536  string name = GetCDriverContext().GetDriverName();
537 #ifdef SQL_DRIVER_NAME
538  TSqlChar buffer[256];
539  SQLSMALLINT length = sizeof(buffer);
541  &length))
542  && length > 0 && buffer[0] != _T_NCBI_ODBC('\0')) {
543  TSqlString name2(buffer, length);
544  name2.erase(name2.find(_T_NCBI_ODBC('\0')));
545  name += '(' + CUtf8::AsUTF8(name2) + ')';
546  }
547 #endif
548  return name;
549 }
550 
552 {
553  string version = "0.0";
554 #ifdef SQL_DRIVER_VER
555  TSqlChar buffer[256];
556  SQLSMALLINT length = sizeof(buffer);
558  &length))
559  && length > 0 && buffer[0] != _T_NCBI_ODBC('\0')) {
561  }
562 #endif
563  return version;
564 }
565 
566 static
567 bool
569 {
570  switch(rc) {
572  stmt.ReportErrors();
573  case SQL_SUCCESS: break;
574  case SQL_ERROR:
575  default:
576  stmt.ReportErrors();
577  return false;
578  }
579 
580  return true;
581 }
582 
584  CDB_BlobDescriptor& descr_in,
585  SQLLEN size,
586  bool is_text,
587  bool logit,
588  SQLPOINTER id,
589  SQLLEN* ph)
590 {
591  string q = "update ";
592  q += descr_in.TableName();
593  q += " set ";
594  q += descr_in.ColumnName();
595  q += "= ? where ";
596  q += descr_in.SearchConditions();
597  //q+= " ;\nset rowcount 0";
598 
599 #if defined(SQL_TEXTPTR_LOGGING)
600  if(!logit) {
601  switch(SQLSetStmtAttr(stmt.GetHandle(), SQL_TEXTPTR_LOGGING, /*SQL_SOPT_SS_TEXTPTR_LOGGING,*/
602  (SQLPOINTER)SQL_TL_OFF, SQL_IS_INTEGER)) {
604  case SQL_ERROR:
605  stmt.ReportErrors();
606  default:
607  break;
608  }
609  }
610 #endif
611 
612 
613  CDB_BlobDescriptor::ETDescriptorType descr_type = descr_in.GetColumnType();
614  if (descr_type == CDB_BlobDescriptor::eUnknown) {
615  if (is_text) {
616  descr_type = CDB_BlobDescriptor::eText;
617  } else {
618  descr_type = CDB_BlobDescriptor::eBinary;
619  }
620  }
621 
622  *ph = SQL_LEN_DATA_AT_EXEC(size);
623 
624  int c_type = 0;
625  int sql_type = 0;
626 
627  if (descr_type == CDB_BlobDescriptor::eText) {
628  // New code ...
629  if (stmt.IsMultibyteClientEncoding()) {
630  c_type = SQL_C_WCHAR;
631  sql_type = SQL_WLONGVARCHAR;
632  *ph = SQL_DATA_AT_EXEC;
633  } else {
634  c_type = SQL_C_CHAR;
635  sql_type = SQL_LONGVARCHAR;
636  }
637  // End of new code ...
638  // Old code ...
639 // #if defined(UNICODE)
640 // c_type = SQL_C_WCHAR;
641 // sql_type = SQL_WLONGVARCHAR;
642 // #else
643 // c_type = SQL_C_CHAR;
644 // sql_type = SQL_LONGVARCHAR;
645 // #endif
646  } else {
647  c_type = SQL_C_BINARY;
648  sql_type = SQL_LONGVARBINARY;
649  }
650 
651  // Do not use SQLDescribeParam. It is not implemented with the odbc driver
652  // from FreeTDS.
653 
655  stmt.GetHandle(),
656  1,
658  c_type,
659  sql_type,
660  size,
661  0,
662  id,
663  0,
664  ph),
665  stmt)) {
666  return false;
667  }
668 
669  TSqlString ss = x_MakeTSqlString(q, stmt.GetClientEncoding());
670  if (!ODBC_xCheckSIE(SQLPrepare(stmt.GetHandle(),
671  const_cast<TSqlChar*>(ss.data()),
672  ss.size()),
673  stmt)) {
674  return false;
675  }
676 
677  switch(SQLExecute(stmt.GetHandle())) {
678  case SQL_NEED_DATA:
679  return true;
681  case SQL_ERROR:
682  stmt.ReportErrors();
683  default:
684  return false;
685  }
686 }
687 
689  SQLPOINTER* id)
690 {
691  switch(SQLParamData(stmt.GetHandle(), id)) {
692  case SQL_NEED_DATA:
693  return true;
695  case SQL_ERROR:
696  stmt.ReportErrors();
697  default:
698  return false;
699  }
700 }
701 
702 bool
705  CDB_Stream& stream)
706 {
707  char buff[1800];
708 
709  int rc;
710 
711  size_t len = 0;
712  size_t invalid_len = 0;
713 
714  while(( len = stream.Read(buff + invalid_len, sizeof(buff) - invalid_len - 1)) != 0 ) {
715  len += invalid_len;
716  // New code ...
717 // size_t valid_len = len;
718 //
719 // if (stmt.GetClientEncoding() == eEncoding_UTF8 &&
720 // descr_type == CDB_BlobDescriptor::eText) {
721 //
722 // valid_len = CStringUTF8::GetValidBytesCount(buff, len);
723 // invalid_len = len - valid_len;
724 // }
725 //
726 // {
727 // TSqlString ss = x_MakeTSqlString(CTempString(buff, valid_len),
728 // stmt.GetClientEncoding());
729 // odbc::TChar* tchar_str = const_cast<odbc::TChar*>(ss.data());
730 //
731 // rc = SQLPutData(stmt.GetHandle(),
732 // static_cast<SQLPOINTER>(tchar_str),
733 // static_cast<SQLINTEGER>(ss.byte_count())
734 // );
735 // }
736 //
737 // if (stmt.GetClientEncoding() == eEncoding_UTF8 &&
738 // descr_type == CDB_BlobDescriptor::eText) {
739 //
740 // if (valid_len < len) {
741 // memmove(buff, buff + valid_len, invalid_len);
742 // }
743 // }
744  // End of new code ...
745 
746 
747  // Old code ...
748  if (stmt.GetClientEncoding() == eEncoding_UTF8 &&
749  descr_type == CDB_BlobDescriptor::eText) {
750 
751  size_t valid_len = impl::GetValidUTF8Len(CTempString(buff, len));
752  invalid_len = len - valid_len;
753 
754  // Encoding is always eEncoding_UTF8 in here.
755  TSqlString ss = x_MakeTSqlString(CTempString(buff, valid_len),
757  odbc::TChar* tchar_str = const_cast<odbc::TChar*>(ss.c_str());
758 
759  rc = SQLPutData(stmt.GetHandle(),
760  static_cast<SQLPOINTER>(tchar_str),
761  static_cast<SQLINTEGER>(ss.byte_count())
762  );
763 
764  if (valid_len < len) {
765  memmove(buff, buff + valid_len, invalid_len);
766  }
767  } else {
768  // Experimental code ...
769 // size_t valid_len = len;
770 //
771 // TSqlString ss = x_MakeTSqlString(CTempString(buff, valid_len),
772 // stmt.GetClientEncoding());
773 // odbc::TChar* tchar_str = const_cast<odbc::TChar*>(ss.data());
774 //
775 // rc = SQLPutData(stmt.GetHandle(),
776 // static_cast<SQLPOINTER>(tchar_str),
777 // static_cast<SQLINTEGER>(ss.byte_count())
778 // );
779  rc = SQLPutData(stmt.GetHandle(),
780  static_cast<SQLPOINTER>(buff),
781  static_cast<SQLINTEGER>(len) // Number of bytes ...
782  );
783  }
784  // End of old code ...
785 
786  switch( rc ) {
788  stmt.ReportErrors();
789  case SQL_NEED_DATA:
790  continue;
791  case SQL_NO_DATA:
792  return true;
793  case SQL_SUCCESS:
794  break;
795  case SQL_ERROR:
796  stmt.ReportErrors();
797  default:
798  return false;
799  }
800  }
801 
802  if (invalid_len > 0) {
803  DATABASE_DRIVER_ERROR( "Invalid encoding of a text string." + GetDbgInfo(), 410055 );
804  }
805 
806  switch(SQLParamData(stmt.GetHandle(), (SQLPOINTER*)&len)) {
807  case SQL_SUCCESS_WITH_INFO: stmt.ReportErrors();
808  case SQL_SUCCESS: break;
809  case SQL_NO_DATA: return true;
810  case SQL_NEED_DATA:
811  {
812  string err_message = "Not all the data were sent." + GetDbgInfo();
813  DATABASE_DRIVER_ERROR( err_message, 410044 );
814  }
815  case SQL_ERROR: stmt.ReportErrors();
816  default:
817  {
818  string err_message = "SQLParamData failed." + GetDbgInfo();
819  DATABASE_DRIVER_ERROR( err_message, 410045 );
820  }
821  }
822 
823  for(;;) {
824  switch(SQLMoreResults( stmt.GetHandle() )) {
825  case SQL_SUCCESS_WITH_INFO: stmt.ReportErrors();
826  case SQL_SUCCESS: continue;
827  case SQL_NO_DATA: break;
828  case SQL_ERROR:
829  {
830  stmt.ReportErrors();
831  string err_message = "SQLMoreResults failed." + GetDbgInfo();
832  DATABASE_DRIVER_ERROR( err_message, 410014 );
833  }
834  default:
835  {
836  string err_message = "SQLMoreResults failed (memory corruption suspected)." + GetDbgInfo();
837  DATABASE_DRIVER_ERROR( err_message, 410015 );
838  }
839  }
840  break;
841  }
842 
843  return true;
844 }
845 
846 
847 /////////////////////////////////////////////////////////////////////////////
849  impl::CBaseCmd(conn, query),
850  m_RowCount(-1),
851  m_Reporter(&conn.GetMsgHandlers(), SQL_HANDLE_STMT, NULL, &conn,
852  &conn.m_Reporter),
853  m_IsActive(true)
854 {
855  x_Init();
856 }
857 
859  const string& cursor_name,
860  const string& query) :
861  impl::CBaseCmd(conn, cursor_name, query),
862  m_RowCount(-1),
863  m_Reporter(&conn.GetMsgHandlers(), SQL_HANDLE_STMT, NULL, &conn,
864  &conn.m_Reporter),
865  m_IsActive(true)
866 {
867  x_Init();
868 }
869 
870 void
872 {
873  if (GetConnection().m_ActiveStmt) {
875  }
876  GetConnection().m_ActiveStmt = this;
877 
878  SQLRETURN rc
880 
881  if(rc == SQL_ERROR) {
883  }
885 
886  SQLUINTEGER query_timeout
887  = static_cast<SQLUINTEGER>(GetConnection().GetTimeout());
888  switch(SQLSetStmtAttr(GetHandle(),
890  (SQLPOINTER)static_cast<uintptr_t>(query_timeout),
891  0))
892  {
894  case SQL_ERROR:
895  case SQL_INVALID_HANDLE:
896  ReportErrors();
897  break;
898  default: // SQL_SUCCESS
899  break;
900  };
901 }
902 
904 {
905  try {
907  if(rc != SQL_SUCCESS) {
908  ReportErrors();
909  }
910  }
912  if (m_IsActive) {
914  }
915 }
916 
917 bool
919 {
920  switch (rc)
921  {
922  case SQL_SUCCESS:
923  return true;
925  case SQL_ERROR:
926  ReportErrors();
927  break;
928  case SQL_INVALID_HANDLE:
929  {
930  string err_message = "Invalid handle." + GetDbgInfo();
931  DATABASE_DRIVER_ERROR( err_message, 0 );
932  }
933  break;
934  }
935 
936  return false;
937 }
938 
939 int
940 CStatementBase::CheckSIE(int rc, const char* msg, unsigned int msg_num) const
941 {
942  switch( rc ) {
944  ReportErrors();
945 
946  case SQL_SUCCESS:
947  break;
948 
949  case SQL_ERROR:
950  ReportErrors();
951  {
952  string err_message = msg + GetDbgInfo();
953  DATABASE_DRIVER_ERROR( err_message, msg_num );
954  }
955  default:
956  {
957  string err_message;
958 
959  err_message.append(msg);
960  err_message.append(" (memory corruption suspected).");
961 
962  DATABASE_DRIVER_ERROR( err_message, 420001 );
963  }
964  }
965 
966  return rc;
967 }
968 
969 int
970 CStatementBase::CheckSIENd(int rc, const char* msg, unsigned int msg_num) const
971 {
972  switch( rc ) {
974  ReportErrors();
975 
976  case SQL_SUCCESS:
977  break;
978 
979  case SQL_ERROR:
980  ReportErrors();
981  {
982  string err_message = msg + GetDbgInfo();
983  DATABASE_DRIVER_ERROR( err_message, msg_num );
984  }
985  default:
986  {
987  string err_message;
988 
989  err_message.append(msg);
990  err_message.append(" (memory corruption suspected).");
991 
992  DATABASE_DRIVER_ERROR( err_message, 420001 );
993  }
994  }
995 
996  return rc;
997 }
998 
999 
1000 string
1002 {
1003  string type_str;
1004 
1005  switch (param.GetType()) {
1006  case eDB_Bit:
1007  type_str = "bit";
1008  break;
1009  case eDB_Int:
1010  type_str = "int";
1011  break;
1012  case eDB_SmallInt:
1013  type_str = "smallint";
1014  break;
1015  case eDB_TinyInt:
1016  type_str = "tinyint";
1017  break;
1018  case eDB_BigInt:
1019  type_str = "numeric";
1020  break;
1021  case eDB_Char:
1022  case eDB_VarChar:
1023  // New code ...
1024  if (IsMultibyteClientEncoding()) {
1025  type_str = "nvarchar(4000)";
1026  } else {
1027  type_str = "varchar(8000)";
1028  }
1029  // End of new code ...
1030  // Old code ...
1031 // if (IsMultibyteClientEncoding()) {
1032 // type_str = "nvarchar(255)";
1033 // } else {
1034 // type_str = "varchar(255)";
1035 // }
1036  break;
1037  case eDB_LongChar:
1038  if (IsMultibyteClientEncoding()) {
1039  type_str = "nvarchar(4000)";
1040  } else {
1041  type_str = "varchar(8000)";
1042  }
1043  break;
1044  case eDB_Binary:
1045  case eDB_VarBinary:
1046  // New code ...
1047  type_str = "varbinary(8000)";
1048  // Old code ...
1049 // type_str = "varbinary(255)";
1050  break;
1051  case eDB_LongBinary:
1052  type_str = "varbinary(8000)";
1053  break;
1054  case eDB_Float:
1055  type_str = "real";
1056  break;
1057  case eDB_Double:
1058  type_str = "float";
1059  break;
1060  case eDB_SmallDateTime:
1061  type_str = "smalldatetime";
1062  break;
1063  case eDB_DateTime:
1064  type_str = "datetime";
1065  break;
1066  case eDB_BigDateTime:
1067  type_str = ((CDB_BigDateTime&)param)
1068  .GetSQLTypeName(CDB_BigDateTime::eSyntax_Microsoft
1069  /* GetConnection().GetDateTimeSyntax() */);
1070  break;
1071  case eDB_Text:
1072  if (IsMultibyteClientEncoding()) {
1073  type_str = "ntext";
1074  } else {
1075  type_str = "text";
1076  }
1077  case eDB_Image:
1078  type_str = "image";
1079  break;
1080  case eDB_VarCharMax:
1081  if (IsMultibyteClientEncoding()) {
1082  type_str = "nvarchar(max)";
1083  } else {
1084  type_str = "varchar(max)";
1085  }
1086  break;
1087  case eDB_VarBinaryMax:
1088  type_str = "varbinary(max)";
1089  break;
1090  default:
1091  break;
1092  }
1093 
1094  return type_str;
1095 }
1096 
1097 bool
1099  CMemPot& bind_guard,
1100  SQLLEN* indicator_base,
1101  unsigned int pos) const
1102 {
1103  SQLRETURN rc = 0;
1104 
1105  EDB_Type data_type = param.GetType();
1106 
1107  switch (data_type) {
1108  case eDB_Text:
1109  case eDB_Image:
1110  case eDB_Bit:
1111  case eDB_Numeric:
1112  case eDB_UnsupportedType:
1113  return false;
1114  default:
1115  break;
1116  }
1117 
1118  SQLSMALLINT scale;
1119  switch (data_type) {
1120  case eDB_DateTime: scale = 3; break;
1121  case eDB_BigDateTime: scale = 7; break;
1122  default: scale = 0; break;
1123  }
1124 
1125  indicator_base[pos] = x_GetIndicator(param);
1126 
1127  rc = SQLBindParameter(GetHandle(),
1128  pos + 1,
1130  x_GetCType(param),
1131  x_GetSQLType(param),
1132  x_GetMaxDataSize(param),
1133  scale,
1134  x_GetData(param, bind_guard),
1135  x_GetCurDataSize(param),
1136  indicator_base + pos);
1137 
1138  CheckSIE(rc, "SQLBindParameter failed", 420066);
1139 
1140  return true;
1141 }
1142 
1143 
1146 {
1147  SQLSMALLINT type = 0;
1148 
1149  switch (param.GetType()) {
1150  case eDB_Int:
1151  type = SQL_C_SLONG;
1152  break;
1153  case eDB_SmallInt:
1154  type = SQL_C_SSHORT;
1155  break;
1156  case eDB_TinyInt:
1157  type = SQL_C_UTINYINT;
1158  break;
1159  case eDB_BigInt:
1160  type = SQL_C_SBIGINT;
1161  break;
1162  case eDB_Char:
1163  case eDB_VarChar:
1164  case eDB_LongChar:
1165  case eDB_VarCharMax:
1166  // New code ...
1167  if (IsMultibyteClientEncoding()) {
1168  type = SQL_C_WCHAR;
1169  } else {
1170  type = SQL_C_CHAR;
1171  }
1172  // End of new code ...
1173  // Old code ...
1174 // #ifdef UNICODE
1175 // type = SQL_C_WCHAR;
1176 // #else
1177 // type = SQL_C_CHAR;
1178 // #endif
1179  break;
1180  case eDB_Binary:
1181  case eDB_VarBinary:
1182  case eDB_LongBinary:
1183  case eDB_VarBinaryMax:
1184  type = SQL_C_BINARY;
1185  break;
1186  case eDB_Float:
1187  type = SQL_C_FLOAT;
1188  break;
1189  case eDB_Double:
1190  type = SQL_C_DOUBLE;
1191  break;
1192  case eDB_SmallDateTime:
1193  case eDB_DateTime:
1194  case eDB_BigDateTime:
1196  break;
1197  default:
1198  break;
1199  }
1200 
1201  return type;
1202 }
1203 
1204 
1207 {
1209 
1210  switch (param.GetType()) {
1211  case eDB_Int:
1212  type = SQL_INTEGER;
1213  break;
1214  case eDB_SmallInt:
1215  type = SQL_SMALLINT;
1216  break;
1217  case eDB_TinyInt:
1218  type = SQL_TINYINT;
1219  break;
1220  case eDB_BigInt:
1221  type = SQL_NUMERIC;
1222  break;
1223  case eDB_Char:
1224  case eDB_VarChar:
1225  // New code ...
1226  if (IsMultibyteClientEncoding()) {
1227  type = SQL_WVARCHAR;
1228  } else {
1229  type = SQL_VARCHAR;
1230  }
1231  // End of new code ...
1232  // Old code ...
1233 // #ifdef UNICODE
1234 // type = SQL_WVARCHAR;
1235 // #else
1236 // type = SQL_VARCHAR;
1237 // #endif
1238  break;
1239  case eDB_LongChar:
1240  case eDB_VarCharMax:
1241  // New code ...
1242  if (IsMultibyteClientEncoding()) {
1244  } else {
1246  }
1247  // End of new code ...
1248  // Old code ...
1249 // #ifdef UNICODE
1250 // type = SQL_WLONGVARCHAR;
1251 // #else
1252 // type = SQL_LONGVARCHAR;
1253 // #endif
1254  break;
1255  case eDB_Binary:
1256  case eDB_VarBinary:
1257  case eDB_LongBinary:
1258  type = SQL_VARBINARY;
1259  break;
1260  case eDB_VarBinaryMax:
1262  break;
1263  case eDB_Float:
1264  type = SQL_REAL;
1265  break;
1266  case eDB_Double:
1267  type = SQL_FLOAT;
1268  break;
1269  case eDB_SmallDateTime:
1270  case eDB_DateTime:
1271  case eDB_BigDateTime:
1273  break;
1274  default:
1275  break;
1276  }
1277 
1278  return type;
1279 }
1280 
1281 
1282 SQLULEN
1284 {
1285  SQLULEN size = 0;
1286 
1287  switch (param.GetType()) {
1288  case eDB_Int:
1289  size = 4;
1290  break;
1291  case eDB_SmallInt:
1292  size = 2;
1293  break;
1294  case eDB_TinyInt:
1295  size = 1;
1296  break;
1297  case eDB_BigInt:
1298  size = 18;
1299  break;
1300  case eDB_Char:
1301  case eDB_VarChar:
1302  // New code ...
1303  if (IsMultibyteClientEncoding()) {
1304  size = 8000 / sizeof(odbc::TChar);
1305  } else {
1306  size = 8000;
1307  }
1308  // End of new code ...
1309 
1310  // Old code ...
1311 // size = 255;
1312  break;
1313  case eDB_LongChar:
1314  // New code ...
1315  if (IsMultibyteClientEncoding()) {
1316  size = 8000 / sizeof(odbc::TChar);
1317  } else {
1318  size = 8000;
1319  }
1320  // End of new code ...
1321 
1322  // Old code ...
1323 // size = 8000 / sizeof(odbc::TChar);
1324  break;
1325  case eDB_Binary:
1326  case eDB_VarBinary:
1327  size = 8000;
1328  break;
1329  case eDB_LongBinary:
1330  size = 8000;
1331  break;
1332  case eDB_Float:
1333  size = 4;
1334  break;
1335  case eDB_Double:
1336  size = 8;
1337  break;
1338  case eDB_SmallDateTime:
1339  size = 16;
1340  break;
1341  case eDB_DateTime:
1342  size = 23;
1343  break;
1344  case eDB_BigDateTime:
1345  size = 27;
1346  break;
1347  case eDB_VarCharMax:
1348 #if 0
1349  if (IsMultibyteClientEncoding()) {
1350  size = kMax_UInt / sizeof(odbc::TChar);
1351  } else {
1352  size = kMax_UInt;
1353  }
1354 #else
1355  size = static_cast<const CDB_VarCharMax&>(param).Size();
1356  if (size == 0) {
1357  size = 1;
1358  }
1359 #endif
1360  break;
1361  case eDB_VarBinaryMax:
1362 #if 0
1363  size = kMax_UInt;
1364 #else
1365  size = static_cast<const CDB_VarBinaryMax&>(param).Size();
1366  if (size == 0) {
1367  size = 1;
1368  }
1369 #endif
1370  break;
1371  default:
1372  break;
1373  }
1374 
1375  return size;
1376 }
1377 
1378 
1379 SQLLEN
1381 {
1382  SQLLEN size = 0;
1383 
1384  switch (param.GetType()) {
1385  case eDB_Int:
1386  case eDB_SmallInt:
1387  case eDB_TinyInt:
1388  case eDB_BigInt:
1389  case eDB_Binary:
1390  case eDB_VarBinary:
1391  case eDB_Float:
1392  case eDB_Double:
1393  size = x_GetMaxDataSize(param);
1394  break;
1395  case eDB_Char:
1396  case eDB_VarChar:
1397  case eDB_LongChar:
1398  size = dynamic_cast<const CDB_String&>(param).Size() * sizeof(odbc::TChar);
1399  break;
1400  case eDB_LongBinary:
1401  size = dynamic_cast<const CDB_LongBinary&>(param).Size();
1402  break;
1403  case eDB_SmallDateTime:
1404  case eDB_DateTime:
1405  case eDB_BigDateTime:
1406  size = sizeof(SQL_TIMESTAMP_STRUCT);
1407  break;
1408  case eDB_VarCharMax:
1409  size = dynamic_cast<const CDB_VarCharMax&>(param).Size()
1410  * sizeof(odbc::TChar);
1411  break;
1412  case eDB_VarBinaryMax:
1413  size = dynamic_cast<const CDB_VarBinaryMax&>(param).Size();
1414  break;
1415  default:
1416  break;
1417  }
1418 
1419  return size;
1420 }
1421 
1422 
1423 SQLLEN
1425 {
1426  if (param.IsNULL()) {
1427  return SQL_NULL_DATA;
1428  }
1429 
1430  switch (param.GetType()) {
1431  case eDB_Char:
1432  case eDB_VarChar:
1433  case eDB_LongChar:
1434  return dynamic_cast<const CDB_String&>(param).Size()
1435  * sizeof(TSqlChar);
1436  case eDB_Binary:
1437  return dynamic_cast<const CDB_Binary&>(param).Size();
1438  case eDB_VarBinary:
1439  return dynamic_cast<const CDB_VarBinary&>(param).Size();
1440  case eDB_LongBinary:
1441  return dynamic_cast<const CDB_LongBinary&>(param).DataSize();
1442  case eDB_SmallDateTime:
1443  case eDB_DateTime:
1444  case eDB_BigDateTime:
1445  return sizeof(SQL_TIMESTAMP_STRUCT);
1446  break;
1447  case eDB_VarCharMax:
1448  return dynamic_cast<const CDB_VarCharMax&>(param).Size()
1449  * sizeof(TSqlChar);
1450  case eDB_VarBinaryMax:
1451  return dynamic_cast<const CDB_VarBinaryMax&>(param).Size();
1452  default:
1453  break;
1454  }
1455 
1456  return x_GetMaxDataSize(param);
1457 }
1458 
1459 
1460 SQLPOINTER
1462  CMemPot& bind_guard) const
1463 {
1464  SQLPOINTER data = NULL;
1465 
1466  switch (param.GetType()) {
1467  case eDB_Int:
1468  data = dynamic_cast<const CDB_Int&>(param).BindVal();
1469  break;
1470  case eDB_SmallInt:
1471  data = dynamic_cast<const CDB_SmallInt&>(param).BindVal();
1472  break;
1473  case eDB_TinyInt:
1474  data = dynamic_cast<const CDB_TinyInt&>(param).BindVal();
1475  break;
1476  case eDB_BigInt:
1477  data = dynamic_cast<const CDB_BigInt&>(param).BindVal();
1478  break;
1479  case eDB_Char:
1480  case eDB_VarChar:
1481  case eDB_LongChar:
1482 #ifdef UNICODE
1483  data = const_cast<wchar_t *>(dynamic_cast<const CDB_String&>(param)
1484  .AsWString(GetClientEncoding()).data());
1485 #else
1486  data = const_cast<char *>(dynamic_cast<const CDB_String&>(param)
1487  .Data());
1488 #endif
1489  break;
1490  case eDB_Binary:
1491  data = const_cast<void *>(dynamic_cast<const CDB_Binary&>(param).Value());
1492  break;
1493  case eDB_VarBinary:
1494  data = const_cast<void *>(dynamic_cast<const CDB_VarBinary&>(param).Value());
1495  break;
1496  case eDB_LongBinary:
1497  data = const_cast<void *>(dynamic_cast<const CDB_LongBinary&>(param).Value());
1498  break;
1499  case eDB_Float:
1500  data = dynamic_cast<const CDB_Float&>(param).BindVal();
1501  break;
1502  case eDB_Double:
1503  data = dynamic_cast<const CDB_Double&>(param).BindVal();
1504  break;
1505  case eDB_SmallDateTime:
1506  if(!param.IsNULL()) {
1507  SQL_TIMESTAMP_STRUCT* ts = NULL;
1508 
1509  ts = (SQL_TIMESTAMP_STRUCT*)bind_guard.Alloc(sizeof(SQL_TIMESTAMP_STRUCT));
1510  const CTime& t = dynamic_cast<const CDB_SmallDateTime&>(param).Value();
1511  ts->year = t.Year();
1512  ts->month = t.Month();
1513  ts->day = t.Day();
1514  ts->hour = t.Hour();
1515  ts->minute = t.Minute();
1516 
1517  ts->second = 0;
1518  ts->fraction = 0;
1519 
1520  data = ts;
1521  }
1522  break;
1523  case eDB_DateTime:
1524  if(!param.IsNULL()) {
1525  SQL_TIMESTAMP_STRUCT* ts = NULL;
1526 
1527  ts = (SQL_TIMESTAMP_STRUCT*)bind_guard.Alloc(sizeof(SQL_TIMESTAMP_STRUCT));
1528  const CTime& t = dynamic_cast<const CDB_DateTime&>(param).Value();
1529  ts->year = t.Year();
1530  ts->month = t.Month();
1531  ts->day = t.Day();
1532  ts->hour = t.Hour();
1533  ts->minute = t.Minute();
1534 
1535  ts->second = t.Second();
1536  ts->fraction = t.NanoSecond()/1000000;
1537  ts->fraction *= 1000000; /* MSSQL has a bug - it cannot handle fraction of msecs */
1538 
1539  data = ts;
1540  }
1541  break;
1542  case eDB_BigDateTime:
1543  if( !param.IsNULL() ) {
1544  SQL_TIMESTAMP_STRUCT* ts = NULL;
1545 
1546  ts = (SQL_TIMESTAMP_STRUCT*)bind_guard.Alloc
1547  (sizeof(SQL_TIMESTAMP_STRUCT));
1548  const CTime& t = ((const CDB_BigDateTime&)param).GetCTime();
1549  ts->year = t.Year();
1550  ts->month = t.Month();
1551  ts->day = t.Day();
1552  ts->hour = t.Hour();
1553  ts->minute = t.Minute();
1554 
1555  ts->second = t.Second();
1556  ts->fraction = t.NanoSecond() / 100 * 100;
1557 
1558  data = ts;
1559  }
1560  break;
1561  case eDB_VarCharMax:
1562 #ifdef UNICODE
1563  if( !param.IsNULL() ) {
1564  CDB_Stream& par = static_cast<CDB_Stream&>
1565  (const_cast<CDB_Object&>(param));
1566  size_t n = par.Size();
1567  AutoArray<char> raw_data(n);
1568  par.MoveTo(0);
1569  _VERIFY(par.Read(raw_data.get(), n) == n);
1570  CStringUTF8 utf_data
1571  = CUtf8::AsUTF8(CTempString(raw_data.get(), n),
1572  GetClientEncoding());
1573  raw_data.reset();
1574  wstring wdata = CUtf8::AsBasicString<TSqlChar>(utf_data);
1575  utf_data.clear();
1576  n = wdata.size() * sizeof(TSqlChar);
1577  data = bind_guard.Alloc(n);
1578  memcpy(data, wdata.data(), n);
1579  }
1580  break;
1581 // else fall through
1582 #endif
1583  case eDB_VarBinaryMax:
1584  if( !param.IsNULL() ) {
1585  CDB_Stream& par = static_cast<CDB_Stream&>
1586  (const_cast<CDB_Object&>(param));
1587  size_t n = par.Size();
1588  data = bind_guard.Alloc(n);
1589  par.MoveTo(0);
1590  _VERIFY(par.Read(data, n) == n);
1591  }
1592  break;
1593  default:
1594  break;
1595  }
1596 
1597  return data;
1598 }
1599 
1600 
1601 int
1603 {
1604  return static_cast<int>(m_RowCount);
1605 }
1606 
1607 bool
1609 {
1610  SQLUINTEGER cancel_timeout
1611  = static_cast<SQLUINTEGER>(GetConnection().GetCancelTimeout());
1614  (SQLPOINTER)static_cast<uintptr_t>(cancel_timeout),
1615  0);
1616  try {
1618  SQLUINTEGER query_timeout
1619  = static_cast<SQLUINTEGER>(GetConnection().GetTimeout());
1622  (SQLPOINTER)static_cast<uintptr_t>(query_timeout),
1623  0);
1624  return result;
1625  }
1626  catch (CDB_Exception&) {
1627  SQLUINTEGER query_timeout
1628  = static_cast<SQLUINTEGER>(GetConnection().GetTimeout());
1631  (SQLPOINTER)static_cast<uintptr_t>(query_timeout),
1632  0);
1633  throw;
1634  }
1635 }
1636 
1637 
1638 /////////////////////////////////////////////////////////////////////////////
1639 //
1640 // CODBC_SendDataCmd::
1641 //
1642 
1644  CDB_BlobDescriptor& descr,
1645  size_t nof_bytes,
1646  bool logit,
1647  bool dump_results) :
1649  impl::CSendDataCmd(conn, nof_bytes),
1650  m_DescrType(descr.GetColumnType() == CDB_BlobDescriptor::eText ?
1652  m_Res(NULL),
1653  m_HasMoreResults(false),
1654  m_DumpResults(dump_results)
1655 {
1656  SQLPOINTER p = (SQLPOINTER)1;
1657  if((!ODBC_xSendDataPrepare(*this, descr, (SQLINTEGER)nof_bytes,
1658  false, logit, p, &m_ParamPH)) ||
1659  (!ODBC_xSendDataGetId(*this, &p))) {
1660 
1661  string err_message = "Cannot prepare a command." + GetDbgInfo();
1662  DATABASE_DRIVER_ERROR( err_message, 410035 );
1663  }
1664 }
1665 
1666 size_t CODBC_SendDataCmd::SendChunk(const void* chunk_ptr, size_t nof_bytes)
1667 {
1668  if(nof_bytes > GetBytes2Go()) nof_bytes= GetBytes2Go();
1669  if(nof_bytes < 1) return 0;
1670 
1671  int rc;
1672 
1673 
1674  // New code ...
1675 // size_t valid_len = nof_bytes;
1676 //
1677 // if (GetClientEncoding() == eEncoding_UTF8 &&
1678 // m_DescrType == CDB_BlobDescriptor::eText) {
1679 //
1680 // valid_len = CStringUTF8::GetValidBytesCount(static_cast<const char*>(chunk_ptr),
1681 // nof_bytes);
1682 //
1683 // if (valid_len == 0) {
1684 // DATABASE_DRIVER_ERROR( "Invalid encoding of a text string." + GetDbgInfo(), 410055 );
1685 // }
1686 //
1687 // nof_bytes = valid_len;
1688 // }
1689 //
1690 // {
1691 // TSqlString ss = x_MakeTSqlString(CTempString(chunk_ptr, valid_len),
1692 // GetClientEncoding());
1693 // odbc::TChar* tchar_str = const_cast<odbc::TChar*>(ss.data());
1694 //
1695 // rc = SQLPutData(GetHandle(),
1696 // static_cast<SQLPOINTER>(tchar_str),
1697 // static_cast<SQLINTEGER>(ss.byte_count())
1698 // );
1699 // }
1700  // End of new code ...
1701 
1702  // Old code ...
1703  if (GetClientEncoding() == eEncoding_UTF8 &&
1705  size_t valid_len = 0;
1706 
1707  valid_len = impl::GetValidUTF8Len(
1708  CTempString(static_cast<const char*>(chunk_ptr),nof_bytes));
1709 
1710  if (valid_len < nof_bytes) {
1711  DATABASE_DRIVER_ERROR( "Invalid encoding of a text string." + GetDbgInfo(), 410055 );
1712  }
1713 
1714  // Encoding is always eEncoding_UTF8 in here.
1716  (CTempString(static_cast<const char*>(chunk_ptr), valid_len),
1717  eEncoding_UTF8);
1718  odbc::TChar* tchar_str = const_cast<odbc::TChar*>(ss.data());
1719  nof_bytes = valid_len;
1720 
1721  rc = SQLPutData(GetHandle(),
1722  static_cast<SQLPOINTER>(tchar_str),
1723  static_cast<SQLINTEGER>(ss.byte_count())
1724  );
1725  } else {
1726  rc = SQLPutData(GetHandle(),
1727  const_cast<SQLPOINTER>(chunk_ptr),
1728  static_cast<SQLINTEGER>(nof_bytes)
1729  );
1730  }
1731  // End of old code ...
1732 
1733 
1734  switch( rc ) {
1735  case SQL_SUCCESS_WITH_INFO:
1736  ReportErrors();
1737  case SQL_NEED_DATA:
1738  case SQL_NO_DATA:
1739  case SQL_SUCCESS:
1740  SetBytes2Go(GetBytes2Go() - nof_bytes);
1741  if(GetBytes2Go() == 0) break;
1742  return nof_bytes;
1743  case SQL_ERROR:
1744  ReportErrors();
1745  default:
1746  return 0;
1747  }
1748 
1749  SQLPOINTER s= (SQLPOINTER)1;
1750  switch(SQLParamData(GetHandle(), (SQLPOINTER*)&s)) {
1752  case SQL_SUCCESS: break;
1753  case SQL_NO_DATA: break;
1754  case SQL_NEED_DATA:
1755  {
1756  string err_message = "Not all the data were sent." + GetDbgInfo();
1757  DATABASE_DRIVER_ERROR( err_message, 410044 );
1758  }
1759  case SQL_ERROR: ReportErrors();
1760  default:
1761  {
1762  string err_message = "SQLParamData failed." + GetDbgInfo();
1763  DATABASE_DRIVER_ERROR( err_message, 410045 );
1764  }
1765  }
1766 
1767  for(;;) {
1768  switch(SQLMoreResults(GetHandle())) {
1770  case SQL_SUCCESS: continue;
1771  case SQL_NO_DATA: break;
1772  case SQL_ERROR:
1773  {
1774  ReportErrors();
1775  string err_message = "SQLMoreResults failed." + GetDbgInfo();
1776  DATABASE_DRIVER_ERROR( err_message, 410014 );
1777  }
1778  default:
1779  {
1780  string err_message = "SQLMoreResults failed (memory corruption suspected)." + GetDbgInfo();
1781  DATABASE_DRIVER_ERROR( err_message, 410015 );
1782  }
1783  }
1784  break;
1785  }
1786 
1787  return nof_bytes;
1788 }
1789 
1791 {
1792  if (GetBytes2Go() > 0) {
1793  xCancel();
1794  SetBytes2Go(0);
1795  return true;
1796  }
1797 
1798  return false;
1799 }
1800 
1802 {
1803  try {
1805 
1807 
1808  Cancel();
1809  }
1811 }
1812 
1814 {
1815  if ( !Close() ) {
1816  return;
1817  }
1818  ResetParams();
1819 }
1820 
1822 {
1823  if (m_Res) {
1824  delete m_Res;
1825  m_Res = 0;
1827  }
1828 
1829  if ( !CStatementBase::WasSent() ) {
1830  string err_message = "A command has to be sent first." + GetDbgInfo();
1831  DATABASE_DRIVER_ERROR( err_message, 420010 );
1832  }
1833 
1834  if(!m_HasMoreResults) {
1836  return 0;
1837  }
1838 
1839  while(m_HasMoreResults) {
1840  SQLSMALLINT nof_cols= 0;
1841  CheckSIE(SQLNumResultCols(GetHandle(), &nof_cols),
1842  "SQLNumResultCols failed", 420011);
1843 
1844  if(nof_cols < 1) { // no data in this result set
1845  SQLLEN rc;
1846 
1847  CheckSIE(SQLRowCount(GetHandle(), &rc),
1848  "SQLRowCount failed", 420013);
1849 
1850  m_RowCount = rc;
1852  continue;
1853  }
1854 
1855  m_Res = new CODBC_RowResult(*this, nof_cols, &m_RowCount);
1856  return Create_Result(*m_Res);
1857  }
1858 
1860  return 0;
1861 }
1862 
1864 {
1865  return m_HasMoreResults;
1866 }
1867 
1869 {
1870  // int rc = CheckSIE(SQLMoreResults(GetHandle()), "SQLBindParameter failed", 420066);
1871  //
1872  // return (rc == SQL_SUCCESS_WITH_INFO || rc == SQL_SUCCESS);
1873 
1874  switch(SQLMoreResults(GetHandle())) {
1876  case SQL_SUCCESS: return true;
1877  case SQL_NO_DATA: return false;
1878  case SQL_ERROR:
1879  {
1880  ReportErrors();
1881 
1882  string err_message = "SQLMoreResults failed." + GetDbgInfo();
1883  DATABASE_DRIVER_ERROR( err_message, 420014 );
1884  }
1885  default:
1886  {
1887  string err_message = "SQLMoreResults failed (memory corruption suspected)." + GetDbgInfo();
1888  DATABASE_DRIVER_ERROR( err_message, 420015 );
1889  }
1890  }
1891 }
1892 
1894 
1895 
1896 
CDBConnParams::
Definition: interfaces.hpp:258
CDB_Exception –.
Definition: exception.hpp:118
Convenience extension of basic_string, supporting implicit conversion to const TChar* in most situati...
Definition: types.hpp:99
void * Alloc(size_t nof_bytes)
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
SQLHENV GetODBCContext(void) const
Definition: interfaces.hpp:196
bool GetUseDSN(void) const
Definition: interfaces.hpp:209
const CODBC_Reporter & GetReporter(void) const
Definition: interfaces.hpp:200
SQLUINTEGER GetPacketSize(void) const
Definition: interfaces.hpp:191
bool CheckSIE(int rc, SQLHDBC con, const CODBC_Reporter &opening_reporter)
Definition: context.cpp:456
virtual CDB_CursorCmd * Cursor(const string &cursor_name, const string &query, unsigned int batch_size=1)
Cursor.
Definition: connection.cpp:385
friend class CODBC_RPCCmd
Definition: interfaces.hpp:257
virtual I_DriverContext::TConnectionMode ConnectMode(void) const
Get the bitmask for the connection mode (BCP, secure login, ...)
Definition: connection.cpp:464
CODBC_LangCmd * xLangCmd(const string &lang_query)
Definition: connection.cpp:354
size_t m_cancel_timeout
Definition: interfaces.hpp:355
size_t GetCancelTimeout() const
Definition: interfaces.hpp:310
friend class CODBC_LangCmd
Definition: interfaces.hpp:256
virtual bool IsAlive(void)
Check out if connection is alive (this function doesn't ping the server, it just checks the status of...
Definition: connection.cpp:341
void x_Connect(CODBCContext &cntx, const CDBConnParams &params, const CODBC_Reporter &opening_reporter) const
Definition: connection.cpp:142
virtual string GetVersionString(void) const
Definition: connection.cpp:551
friend class CODBC_CursorCmdExpl
Definition: interfaces.hpp:261
virtual string GetDriverName(void) const
Definition: connection.cpp:534
const SQLHDBC m_Link
Definition: interfaces.hpp:351
size_t m_query_timeout
Definition: interfaces.hpp:354
static string x_GetDriverName(const IRegistry &registry)
Definition: connection.cpp:256
virtual CDB_SendDataCmd * SendDataCmd(I_BlobDescriptor &desc, size_t data_size, bool log_it=true, bool dump_results=true)
"Send-data" command
Definition: connection.cpp:403
friend class CODBC_BCPInCmd
Definition: interfaces.hpp:258
bool x_SendData(CDB_BlobDescriptor::ETDescriptorType descr_type, CStatementBase &stmt, CDB_Stream &stream)
Definition: connection.cpp:703
virtual CDB_RPCCmd * RPC(const string &rpc_name)
Remote procedure call.
Definition: connection.cpp:366
virtual void SetTimeout(size_t nof_secs)
Definition: connection.cpp:524
friend class CODBC_SendDataCmd
Definition: interfaces.hpp:259
const TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:322
virtual bool Abort(void)
abort the connection Attention: it is not recommended to use this method unless you absolutely have t...
Definition: connection.cpp:493
virtual bool Refresh(void)
Reset the connection to the "ready" state (cancel all active commands)
Definition: connection.cpp:455
CODBC_Reporter m_Reporter
Definition: interfaces.hpp:353
static string x_MakeFreeTDSVersion(int version)
Definition: connection.cpp:309
virtual void SetCancelTimeout(size_t nof_secs)
Definition: connection.cpp:529
void x_SetConnAttributesBefore(const CODBCContext &cntx, const CDBConnParams &params)
Definition: connection.cpp:226
CStatementBase * m_ActiveStmt
Definition: interfaces.hpp:352
void x_SetupErrorReporter(const CDBConnParams &params)
Definition: connection.cpp:132
size_t GetTimeout() const
Definition: interfaces.hpp:305
virtual ~CODBC_Connection(void)
Definition: connection.cpp:477
void ReportErrors(void)
Definition: interfaces.hpp:327
CODBC_Connection(CODBCContext &cntx, const CDBConnParams &params)
Definition: connection.cpp:83
virtual CDB_LangCmd * LangCmd(const string &lang_query)
These methods: LangCmd(), RPC(), BCPIn(), Cursor() and SendDataCmd() create and return a "command" ob...
Definition: connection.cpp:360
friend class CODBC_CursorCmd
Definition: interfaces.hpp:260
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)
Definition: connection.cpp:418
virtual bool Close(void)
Close an open connection.
Definition: connection.cpp:500
virtual CDB_BCPInCmd * BCPIn(const string &table_name)
"Bulk copy in" command
Definition: connection.cpp:373
void SetHandlerStack(impl::CDBHandlerStack &hs)
Definition: interfaces.hpp:118
void SetServerName(const string &server_name)
Definition: interfaces.hpp:133
void ReportErrors(void) const
Definition: context.cpp:198
void SetHandle(SQLHANDLE h)
Definition: interfaces.hpp:121
void SetUserName(const string &username)
Definition: interfaces.hpp:136
virtual bool HasMoreResults(void) const
bool xCheck4MoreResults(void)
virtual ~CODBC_SendDataCmd(void)
virtual CDB_Result * Result(void)
Get result set.
CODBC_RowResult * m_Res
Definition: interfaces.hpp:715
CODBC_SendDataCmd(CODBC_Connection &conn, CDB_BlobDescriptor &descr, size_t nof_bytes, bool logit, bool dump_results)
void xCancel(void)
const CDB_BlobDescriptor::ETDescriptorType m_DescrType
Definition: interfaces.hpp:714
virtual bool Cancel(void)
virtual size_t SendChunk(const void *chunk_ptr, size_t nof_bytes)
Send chunk of data to the server.
const CODBC_Connection::TDbgInfo & GetDbgInfo(void) const
Definition: interfaces.hpp:388
bool CheckRC(int rc) const
Definition: connection.cpp:918
bool x_BindParam_ODBC(const CDB_Object &param, CMemPot &bind_guard, SQLLEN *indicator_base, unsigned int pos) const
virtual int RowCount(void) const
Get the number of rows affected by the command Special case: negative on error or if there is no way ...
CODBC_Reporter m_Reporter
Definition: interfaces.hpp:463
bool IsMultibyteClientEncoding(void) const
Definition: interfaces.hpp:431
SQLULEN x_GetMaxDataSize(const CDB_Object &param) const
bool Close(void) const
string Type2String(const CDB_Object &param) const
SQLHSTMT GetHandle(void) const
Definition: interfaces.hpp:369
void x_Init(void)
Definition: connection.cpp:871
SQLSMALLINT x_GetCType(const CDB_Object &param) const
SQLLEN x_GetIndicator(const CDB_Object &param) const
SQLLEN x_GetCurDataSize(const CDB_Object &param) const
CStatementBase(CODBC_Connection &conn, const string &query)
Definition: connection.cpp:848
SQLHSTMT m_Cmd
Definition: interfaces.hpp:462
int CheckSIE(int rc, const char *msg, unsigned int msg_num) const
Definition: connection.cpp:940
bool ResetParams(void) const
Definition: interfaces.hpp:426
~CStatementBase(void)
Definition: connection.cpp:903
EEncoding GetClientEncoding(void) const
Definition: interfaces.hpp:435
SQLSMALLINT x_GetSQLType(const CDB_Object &param) const
CODBC_Connection & GetConnection(void)
Definition: interfaces.hpp:373
int CheckSIENd(int rc, const char *msg, unsigned int msg_num) const
Definition: connection.cpp:970
SQLPOINTER x_GetData(const CDB_Object &param, CMemPot &bind_guard) const
void ReportErrors(void) const
Definition: interfaces.hpp:393
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTime –.
Definition: ncbitime.hpp:296
IRegistry –.
Definition: ncbireg.hpp:73
I_BlobDescriptor::
Definition: interfaces.hpp:369
void SetWasSent(bool flag=true)
bool WasSent(void) const
static CDB_Result * Create_Result(CResult &result)
bool IsBCPable(void) const
const CDBHandlerStack & GetMsgHandlers(void) const
CDB_CursorCmd * Create_CursorCmd(CBaseCmd &cursor_cmd)
CDB_RPCCmd * Create_RPCCmd(CBaseCmd &rpc_cmd)
void DropCmd(impl::CCommand &cmd)
void SetServerType(CDBConnParams::EServerType type)
bool HasSecureLogin(void) const
CDB_SendDataCmd * Create_SendDataCmd(CSendDataCmd &senddata_cmd)
CDriverContext & GetCDriverContext(void)
CDB_BCPInCmd * Create_BCPInCmd(CBaseCmd &bcpin_cmd)
CDB_LangCmd * Create_LangCmd(CBaseCmd &lang_cmd)
These methods to allow the children of CConnection to create various command-objects.
EEncoding GetClientEncoding(void) const
virtual CRWLock & x_GetCtxLock(void) const
void DetachSendDataIntf(void)
void SetBytes2Go(size_t value)
size_t GetBytes2Go(void) const
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
SQLCHAR TSqlChar
Definition: interfaces.hpp:76
char TChar
Definition: interfaces.hpp:78
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
#define SQLULEN
Definition: odbc.h:49
#define SQLLEN
Definition: odbc.h:52
#define SQLSetConnectAttr(h, n, p, t)
Definition: odbc.c:50
static const char table_name[]
Definition: bcp.c:249
static int type
Definition: getdata.c:31
static HSTMT stmt
Definition: rebindpar.c:12
char data[12]
Definition: iconv.c:80
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:581
void reset(element_type *p=0)
Reset will delete the old pointer, set content to the new value, and assume the ownership upon the ne...
Definition: ncbimisc.hpp:598
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
#define DATABASE_DRIVER_ERROR(message, err_code)
Definition: exception.hpp:740
virtual const impl::CDBHandlerStack & GetOpeningMsgHandlers(void) const =0
virtual string GetPassword(void) const =0
virtual string GetDriverName(void) const
Definition: interfaces.cpp:342
virtual Uint4 GetHost(void) const =0
virtual string GetServerName(void) const =0
virtual Uint2 GetPort(void) const =0
virtual string GetUserName(void) const =0
virtual string GetParam(const string &key) const =0
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
const string & SearchConditions() const
Definition: public.hpp:995
ETDescriptorType GetColumnType(void) const
Definition: public.hpp:998
const string & ColumnName() const
Definition: public.hpp:993
const string & TableName() const
Definition: public.hpp:991
EDB_Type
Definition: types.hpp:52
static EBlobType GetBlobType(EDB_Type db_type)
Definition: types.hpp:1216
@ eBlobType_Binary
Definition: types.hpp:81
size_type byte_count(void) const
Definition: types.hpp:111
virtual EDB_Type GetType() const =0
virtual bool MoveTo(size_t byte_number)
Definition: types.cpp:2008
virtual size_t Read(void *buff, size_t nof_bytes)
Definition: types.cpp:1987
virtual size_t Size() const
Definition: types.cpp:2014
bool IsNULL() const
Definition: types.hpp:303
@ eDB_Bit
Definition: types.hpp:68
@ eDB_Char
Definition: types.hpp:58
@ eDB_UnsupportedType
Definition: types.hpp:75
@ eDB_SmallDateTime
Definition: types.hpp:65
@ eDB_VarChar
Definition: types.hpp:57
@ eDB_TinyInt
Definition: types.hpp:55
@ eDB_LongChar
Definition: types.hpp:70
@ eDB_Double
Definition: types.hpp:62
@ eDB_Image
Definition: types.hpp:67
@ eDB_Float
Definition: types.hpp:61
@ eDB_Int
Definition: types.hpp:53
@ eDB_VarCharMax
Definition: types.hpp:72
@ eDB_Numeric
Definition: types.hpp:69
@ eDB_BigInt
Definition: types.hpp:56
@ eDB_BigDateTime
Definition: types.hpp:64
@ eDB_Binary
Definition: types.hpp:60
@ eDB_Text
Definition: types.hpp:66
@ eDB_SmallInt
Definition: types.hpp:54
@ eDB_DateTime
Definition: types.hpp:63
@ eDB_LongBinary
Definition: types.hpp:71
@ eDB_VarBinary
Definition: types.hpp:59
@ eDB_VarBinaryMax
Definition: types.hpp:73
#define _VERIFY(expr)
Definition: ncbidbg.hpp:161
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
unsigned int uintptr_t
Definition: ncbitype.h:197
#define kMax_UInt
Definition: ncbi_limits.h:185
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
EEncoding
Definition: ncbistr.hpp:199
#define kEmptyStr
Definition: ncbistr.hpp:123
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
Definition: ncbistr.hpp:330
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5078
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3883
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ fSplit_Truncate
Definition: ncbistr.hpp:2503
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2500
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
yy_size_t n
int len
@ eText
Definition: map_control.hpp:50
const string version
version string
Definition: variables.hpp:66
string ConvertN2A(Uint4 host)
SIZE_TYPE GetValidUTF8Len(const CTempString &ts)
mdb_mode_t mode
Definition: lmdb++.h:38
const struct ncbi::grid::netcache::search::fields::SIZE size
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
EIPRangeType t
Definition: ncbi_localip.c:101
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
#define DEFAULT_ODBC_DRIVER_NAME
Definition: connection.cpp:48
static bool ODBC_xSendDataGetId(CStatementBase &stmt, SQLPOINTER *id)
Definition: connection.cpp:688
static bool ODBC_xCheckSIE(int rc, CStatementBase &stmt)
Definition: connection.cpp:568
bool IsBCPCapable(void)
Definition: connection.cpp:66
static bool ODBC_xSendDataPrepare(CStatementBase &stmt, CDB_BlobDescriptor &descr_in, SQLLEN size, bool is_text, bool logit, SQLPOINTER id, SQLLEN *ph)
Definition: connection.cpp:583
TSqlString x_MakeTSqlString(const CTempString &s, EEncoding enc)
Definition: odbc_utils.hpp:107
#define _T_NCBI_ODBC(x)
Definition: odbc_utils.hpp:101
CGenericSqlString< TSqlChar > TSqlString
Definition: odbc_utils.hpp:105
#define memmove(a, b, c)
static uint8_t * buffer
Definition: pcre2test.c:1016
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define SQL_REAL
Definition: sql.h:173
SQLRETURN SQLRowCount(SQLHSTMT StatementHandle, SQLINTEGER *RowCount)
SQLRETURN SQLPutData(SQLHSTMT StatementHandle, SQLPOINTER Data, SQLINTEGER StrLen_or_Ind)
#define SQL_FLOAT
Definition: sql.h:172
SQLRETURN SQLPrepare(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength)
Definition: odbc_export.h:848
#define SQL_HANDLE_STMT
Definition: sql.h:66
SQLRETURN SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1, SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication, SQLSMALLINT NameLength3)
Definition: odbc_export.h:488
SQLRETURN SQLGetInfo(SQLHDBC ConnectionHandle, SQLUSMALLINT InfoType, SQLPOINTER InfoValue, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
SQLRETURN SQLExecute(SQLHSTMT StatementHandle)
Definition: odbc.c:3558
#define SQL_SUCCESS
Definition: sql.h:31
#define SQL_DATA_AT_EXEC
Definition: sql.h:30
SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
Definition: odbc.c:4237
#define SQL_UNKNOWN_TYPE
Definition: sql.h:166
#define SQL_TYPE_TIMESTAMP
Definition: sql.h:184
#define SQL_SMALLINT
Definition: sql.h:171
#define SQL_NEED_DATA
Definition: sql.h:39
SQLRETURN SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandle)
#define SQL_NUMERIC
Definition: sql.h:168
#define SQL_INTEGER
Definition: sql.h:170
SQLRETURN SQLSetStmtAttr(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER StringLength)
#define SQL_INVALID_HANDLE
Definition: sql.h:37
#define SQL_SUCCESS_WITH_INFO
Definition: sql.h:32
SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle)
Definition: odbc.c:2313
SQLRETURN SQLNumResultCols(SQLHSTMT StatementHandle, SQLSMALLINT *ColumnCount)
#define SQL_NULL_DATA
Definition: sql.h:29
SQLRETURN SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
#define SQL_SUCCEEDED(rc)
Definition: sql.h:40
SQLRETURN SQLGetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER BufferLength, SQLINTEGER *StringLength)
Definition: odbc_export.h:1020
SQLRETURN SQLParamData(SQLHSTMT StatementHandle, SQLPOINTER *Value)
#define SQL_HANDLE_DBC
Definition: sql.h:65
#define SQL_VARCHAR
Definition: sql.h:178
#define SQL_ERROR
Definition: sql.h:36
#define SQL_CLOSE
Definition: sql.h:253
#define SQL_NO_DATA
Definition: sql.h:34
#define SQL_ATTR_CONNECTION_TIMEOUT
Definition: sqlext.h:125
#define SQL_PARAM_INPUT
Definition: sqlext.h:1852
#define SQL_DRIVER_NAME
Definition: sqlext.h:775
#define SQL_C_DOUBLE
Definition: sqlext.h:515
#define SQL_C_TYPE_TIMESTAMP
Definition: sqlext.h:531
SQLRETURN SQLBindParameter(SQLHSTMT hstmt, SQLUSMALLINT ipar, SQLSMALLINT fParamType, SQLSMALLINT fCType, SQLSMALLINT fSqlType, SQLUINTEGER cbColDef, SQLSMALLINT ibScale, SQLPOINTER rgbValue, SQLINTEGER cbValueMax, SQLINTEGER *pcbValue)
#define SQL_LONGVARBINARY
Definition: sqlext.h:435
#define SQL_LEN_DATA_AT_EXEC(length)
Definition: sqlext.h:618
#define SQL_LONGVARCHAR
Definition: sqlext.h:432
#define SQL_ATTR_LOGIN_TIMEOUT
Definition: sqlext.h:130
#define SQL_C_SLONG
Definition: sqlext.h:553
#define SQL_C_BINARY
Definition: sqlext.h:546
#define SQL_ATTR_CONNECTION_DEAD
Definition: sqlext.h:141
#define SQL_ATTR_QUERY_TIMEOUT
Definition: sqlext.h:271
#define SQL_C_FLOAT
Definition: sqlext.h:514
#define SQL_ATTR_PACKET_SIZE
Definition: sqlext.h:132
#define SQL_CD_FALSE
Definition: sqlext.h:217
#define SQL_TINYINT
Definition: sqlext.h:437
#define SQL_C_SSHORT
Definition: sqlext.h:554
SQLRETURN SQLMoreResults(SQLHSTMT hstmt)
Definition: odbc.c:865
#define SQL_VARBINARY
Definition: sqlext.h:434
#define SQL_C_UTINYINT
Definition: sqlext.h:558
#define SQL_DRIVER_VER
Definition: sqlext.h:776
#define SQL_C_SBIGINT
Definition: sqlext.h:549
#define SQL_IS_INTEGER
Definition: sqlext.h:307
#define SQL_C_CHAR
Definition: sqlext.h:511
#define SQL_DRIVER_NOPROMPT
Definition: sqlext.h:1785
SQLRETURN SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn, SQLCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT *pcbConnStrOut, SQLUSMALLINT fDriverCompletion)
unsigned long SQLUINTEGER
Definition: sqltypes.h:177
void * SQLPOINTER
Definition: sqltypes.h:195
SQLHANDLE SQLHDBC
Definition: sqltypes.h:215
long SQLINTEGER
Definition: sqltypes.h:176
signed short int SQLSMALLINT
Definition: sqltypes.h:201
TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT
Definition: sqltypes.h:316
SQLSMALLINT SQLRETURN
Definition: sqltypes.h:210
#define SQL_WVARCHAR
Definition: sqlucode.h:15
#define SQL_C_WCHAR
Definition: sqlucode.h:17
#define SQL_WLONGVARCHAR
Definition: sqlucode.h:16
static string query
SQLUSMALLINT hour
Definition: sqltypes.h:309
SQLUINTEGER fraction
Definition: sqltypes.h:312
SQLUSMALLINT second
Definition: sqltypes.h:311
SQLSMALLINT year
Definition: sqltypes.h:306
SQLUSMALLINT month
Definition: sqltypes.h:307
SQLUSMALLINT day
Definition: sqltypes.h:308
SQLUSMALLINT minute
Definition: sqltypes.h:310
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:58:00 2024 by modify_doxy.py rev. 669887