Diff for /sql/odbc/parser3odbc.C between versions 1.28 and 1.32

version 1.28, 2008/06/27 13:38:36 version 1.32, 2008/07/01 10:21:03
Line 96  public: Line 96  public:
                 @param url                  @param url
                         format: @b DSN=dsn;UID=user;PWD=password? (ODBC connect string)                          format: @b DSN=dsn;UID=user;PWD=password? (ODBC connect string)
                                 ClientCharset=charset&  // transcode with parser                                  ClientCharset=charset&  // transcode with parser
                                 MultiRowFetch=1&        // 0 -- disable (slower)  
                                 autocommit=1&           // 0 -- disable auto commit                                  autocommit=1&           // 0 -- disable auto commit
                                   FastOffsetSearch=0
                         WARNING: must be used only to connect, for buffer doesn't live long                          WARNING: must be used only to connect, for buffer doesn't live long
         */          */
   
Line 110  public: Line 110  public:
                 *connection_ref=&connection;                  *connection_ref=&connection;
                 connection.services=&services;                  connection.services=&services;
                 connection.client_charset=0;                  connection.client_charset=0;
                 connection.fast_offset_search=true;                  connection.fast_offset_search=false;
                 connection.autocommit=true;                  connection.autocommit=true;
   
                 size_t url_length=strlen(url);                  size_t url_length=strlen(url);
                 char *options=lsplit(url, '?');                  char *options=lsplit(url, '?');
   
                   // todo: analize connect string and if 'SQL Server' found, modify query and add TOP into SELECTs
   
                 while(options){                  while(options){
                         if(char *key=lsplit(&options, '&')){                          if(char *key=lsplit(&options, '&')){
                                 if(*key){                                  if(*key){
Line 127  public: Line 129  public:
                                                         if(atoi(value)==0)                                                          if(atoi(value)==0)
                                                                 connection.autocommit=false;                                                                  connection.autocommit=false;
                                                 } else if(strcmp(key, "FastOffsetSearch")==0){                                                  } else if(strcmp(key, "FastOffsetSearch")==0){
                                                         if(atoi(value)==0)                                                          if(atoi(value)==1)
                                                                 connection.fast_offset_search=false;                                                                  connection.fast_offset_search=true;
                                                 } else                                                  } else
                                                         services._throw("unknown connect option" /*key*/);                                                          services._throw("unknown connect option" /*key*/);
                                         } else                                           } else 
Line 140  public: Line 142  public:
                 TRY {                  TRY {
                         connection.db=new CDatabase();                          connection.db=new CDatabase();
                         connection.db->OpenEx(url, CDatabase::noOdbcDialog);                          connection.db->OpenEx(url, CDatabase::noOdbcDialog);
                           connection.db->BeginTrans();
                         if(!connection.autocommit)  
                                 connection.db->BeginTrans();  
                 }                   } 
                 CATCH_ALL (e) {                  CATCH_ALL (e) {
                         _throw(services, e);                          _throw(services, e);
Line 163  public: Line 163  public:
   
         void commit(void *aconnection){          void commit(void *aconnection){
                 Connection& connection=*static_cast<Connection*>(aconnection);                  Connection& connection=*static_cast<Connection*>(aconnection);
                 if(!connection.autocommit){                  TRY
                         TRY                          connection.db->CommitTrans();
                                 connection.db->CommitTrans();                          connection.db->BeginTrans();
                                 connection.db->BeginTrans();                  CATCH_ALL (e) {
                         CATCH_ALL (e) {                          _throw(*connection.services, e);
                                 _throw(*connection.services, e);  
                         }  
                         END_CATCH_ALL  
                 }                  }
                   END_CATCH_ALL
         }          }
   
         void rollback(void *aconnection){          void rollback(void *aconnection){
                 Connection& connection=*static_cast<Connection*>(aconnection);                  Connection& connection=*static_cast<Connection*>(aconnection);
                 if(!connection.autocommit){                  TRY
                         TRY                          connection.db->Rollback();
                                 connection.db->Rollback();                          connection.db->BeginTrans();
                                 connection.db->BeginTrans();                  CATCH_ALL (e) {
                         CATCH_ALL (e) {                          _throw(*connection.services, e);
                                 _throw(*connection.services, e);  
                         }  
                         END_CATCH_ALL  
                 }                  }
                   END_CATCH_ALL
         }          }
   
         bool ping(void *connection){          bool ping(void *connection){
Line 220  public: Line 216  public:
                 if(placeholders_count>0)                  if(placeholders_count>0)
                         services._throw("bind variables not supported (yet)");                          services._throw("bind variables not supported (yet)");
   
                 bool transcode_needed=_transcode_required(connection);                  const char* client_charset=connection.client_charset;
                   const char* request_charset=services.request_charset();
                   bool transcode_needed=(client_charset && strcmp(client_charset, request_charset)!=0);
   
                 // transcode query from $request:charset to ?ClientCharset                  // transcode query from $request:charset to ?ClientCharset
                 if(transcode_needed){                  if(transcode_needed){
                         size_t length=strlen(statement);                          size_t length=strlen(statement);
                         services.transcode(statement, length,                          services.transcode(statement, length,
                                 statement, length,                                  statement, length,
                                 services.request_charset(),                                  request_charset,
                                 connection.client_charset);                                  client_charset);
                 }                  }
   
                 while(isspace((unsigned char)*statement))                   while(isspace((unsigned char)*statement)) 
Line 289  public: Line 287  public:
                                         column_count=MAX_COLS;                                          column_count=MAX_COLS;
   
                                 SWORD column_types[MAX_COLS];                                  SWORD column_types[MAX_COLS];
                                   bool transcode_column[MAX_COLS];
   
                                 SQL_Error sql_error;                                  SQL_Error sql_error;
 #define CHECK(afailed) if(afailed) services._throw(sql_error)  #define CHECK(afailed) if(afailed) services._throw(sql_error)
Line 298  public: Line 297  public:
                                         CODBCFieldInfo fieldinfo;                                          CODBCFieldInfo fieldinfo;
                                         rs.GetODBCFieldInfo(i, fieldinfo);                                          rs.GetODBCFieldInfo(i, fieldinfo);
                                         column_types[i]=fieldinfo.m_nSQLType;                                          column_types[i]=fieldinfo.m_nSQLType;
                                           switch(fieldinfo.m_nSQLType){
                                                   case SQL_NUMERIC:
                                                   case SQL_DECIMAL:
                                                   case SQL_INTEGER:
                                                   case SQL_SMALLINT:
                                                   case SQL_FLOAT:
                                                   case SQL_REAL:
                                                   case SQL_DOUBLE:
                                                   case SQL_DATETIME:
                                                   case SQL_SMALLDATETIME:
                                                   case SQL_BIGINT:
                                                   case SQL_TINYINT:
                                                           transcode_column[i]=false;
                                                           break;
                                                   default:
                                                           transcode_column[i]=transcode_needed;
                                                           break;
                                           }
                                         size_t length=fieldinfo.m_strName.GetLength();                                          size_t length=fieldinfo.m_strName.GetLength();
                                         char *str=0;                                          char *str=0;
                                         if(length){                                          if(length){
Line 308  public: Line 325  public:
                                                 if(transcode_needed){                                                  if(transcode_needed){
                                                         services.transcode(str, length,                                                          services.transcode(str, length,
                                                                 str, length,                                                                  str, length,
                                                                 connection.client_charset,                                                                  client_charset,
                                                                 services.request_charset());                                                                  request_charset);
                                                 }                                                  }
                                         }                                          }
                                         CHECK(handlers.add_column(sql_error, str, length));                                          CHECK(handlers.add_column(sql_error, str, length));
Line 323  public: Line 340  public:
                                                 rs.Move(offset);                                                  rs.Move(offset);
                                         } else {                                          } else {
                                                 unsigned long row=offset;                                                  unsigned long row=offset;
                                                 while(!rs.IsEOF() && row>0){                                                  while(!rs.IsEOF() && row--)
                                                         rs.MoveNext();                                                          rs.MoveNext();
                                                         row--;  
                                                 }  
                                         }                                          }
                                 }                                  }
   
Line 340  public: Line 355  public:
                                                 char* str;                                                  char* str;
                                                 switch(column_types[i]){                                                  switch(column_types[i]){
                                                         //case xBOOL:                                                          //case xBOOL:
                                                         //case SQL_INTEGER: // serg@design.ru did that in parser2. test first!  
                                                         //case SQL_DATETIME: << default: handles that more properly (?)                                                          //case SQL_DATETIME: << default: handles that more properly (?)
                                                         case SQL_BINARY:                                                           case SQL_BINARY: 
                                                         case SQL_VARBINARY:                                                          case SQL_VARBINARY:
Line 358  public: Line 372  public:
                                                 }                                                  }
   
                                                 // transcode cell value from ?ClientCharset to $request:charset                                                  // transcode cell value from ?ClientCharset to $request:charset
                                                 if(transcode_needed && length)                                                  if(length && transcode_column[i]){
                                                         services.transcode(str, length,                                                          services.transcode(str, length,
                                                                 str, length,                                                                  str, length,
                                                                 connection.client_charset,                                                                  client_charset,
                                                                 services.request_charset());                                                                  request_charset);
                                                   }
   
                                                 CHECK(handlers.add_row_cell(sql_error, str, length));                                                  CHECK(handlers.add_row_cell(sql_error, str, length));
                                         }                                          }
Line 377  public: Line 392  public:
                 } CATCH_ALL (e) {                  } CATCH_ALL (e) {
                         _throw(services, e);                          _throw(services, e);
                 } END_CATCH_ALL                  } END_CATCH_ALL
   
                   if(connection.autocommit)
                           commit(aconnection);
         }          }
   
 private:  private:
Line 401  private: Line 419  private:
                         ptr=v.m_boolVal?"1":"0";                          ptr=v.m_boolVal?"1":"0";
                         length=1;                          length=1;
                         break;*/                          break;*/
 /*                                                      case DBVT_UCHAR:  /*              case DBVT_UCHAR:
                         length=strlen(ptr=v.m_chVal);                          length=strlen(ptr=v.m_chVal);
                         break;                          break;
                 case DBVT_SHORT:                  case DBVT_SHORT:
Line 478  private: Line 496  private:
                 connection.services->_throw(msg);                  connection.services->_throw(msg);
         }          }
   
         bool _transcode_required(Connection& connection){  
                 return (connection.client_charset && strcmp(connection.client_charset, connection.services->request_charset())!=0);  
         }  
   
 };  };
   
 extern "C" SQL_Driver *SQL_DRIVER_CREATE() {  extern "C" SQL_Driver *SQL_DRIVER_CREATE() {

Removed from v.1.28  
changed lines
  Added in v.1.32


E-mail: