Diff for /sql/odbc/parser3odbc.C between versions 1.27 and 1.30

version 1.27, 2008/06/27 12:54:44 version 1.30, 2008/07/01 08:51:16
Line 44  static const char *RCSId="$Id$"; Line 44  static const char *RCSId="$Id$";
 #ifndef strncasecmp  #ifndef strncasecmp
 #       define strncasecmp _strnicmp  #       define strncasecmp _strnicmp
 #endif  #endif
   #ifndef strcasecmp
   #       define strcasecmp _stricmp
   #endif
   
 static char *lsplit(char *string, char delim){  static char *lsplit(char *string, char delim){
         if(string){          if(string){
Line 55  static char *lsplit(char *string, char d Line 58  static char *lsplit(char *string, char d
         return 0;          return 0;
 }  }
   
   static char *lsplit(char **string_ref, char delim){
           char *result=*string_ref;
           char *next=lsplit(*string_ref, delim);
           *string_ref=next;
           return result;
   }
   
 static void toupper_str(char *out, const char *in, size_t size){  static void toupper_str(char *out, const char *in, size_t size){
         while(size--)          while(size--)
                 *out++=(char)toupper(*in++);                  *out++=(char)toupper(*in++);
Line 66  struct Connection { Line 76  struct Connection {
         CDatabase* db;          CDatabase* db;
         const char* client_charset;          const char* client_charset;
         bool autocommit;          bool autocommit;
         bool use_multi_row_fetch;          bool fast_offset_search;
 };  };
   
 /**  /**
Line 84  public: Line 94  public:
         const char *initialize(char *dlopen_file_spec) { return 0; }          const char *initialize(char *dlopen_file_spec) { return 0; }
         /**     connect          /**     connect
                 @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 100  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.use_multi_row_fetch=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, '?');
   
                 if(const char* key_start=strstr(url, "ClientCharset=")){                  while(options){
                         const char* value_start=key_start+14/*strlen("ClientCharset=")*/;                          if(char *key=lsplit(&options, '&')){
                         const char* value_end=strchr(value_start, ';');                                  if(*key){
                         if(!value_end)                                          if(char *value=lsplit(key, '=')){
                                 value_end=url+url_length;                                                  if(strcmp(key, "ClientCharset")==0){
                                                           toupper_str(value, value, strlen(value));
                         if(size_t value_length=value_end-value_start){                                                          connection.client_charset=value;
                                 char* client_charset=(char*)services.malloc_atomic(value_length+1);                                                  } else if(strcasecmp(key, "autocommit")==0){
                                 toupper_str(client_charset, value_start, value_length);                                                          if(atoi(value)==0)
                                 client_charset[value_length]=0;                                                                  connection.autocommit=false;
                                                   } else if(strcmp(key, "FastOffsetSearch")==0){
                                 connection.client_charset=client_charset;                                                          if(atoi(value)==1)
                         }                                                                  connection.fast_offset_search=true;
                 }                                                  } else
                 if(const char* key_start=strstr(url, "MultiRowFetch=")){                                                          services._throw("unknown connect option" /*key*/);
                         const char* value_start=key_start+14/*strlen("MultiRowFetch=")*/;                                          } else 
                         const char* value_end=strchr(value_start, ';');                                                  services._throw("connect option without =value" /*key*/);
                         if(!value_end)                                  }
                                 value_end=url+url_length;  
   
                         if(size_t value_length=value_end-value_start){  
                                 char* value=(char*)services.malloc_atomic(value_length+1);  
                                 memcpy(value, value_start, value_length);  
                                 value[value_length]=0;  
                                 if(atoi(value)==0)  
                                         connection.use_multi_row_fetch=false;  
                         }  
                 }  
                 if(const char* key_start=strstr(url, "autocommit=")){  
                         const char* value_start=key_start+11/*strlen("autocommit=")*/;  
                         const char* value_end=strchr(value_start, ';');  
                         if(!value_end)  
                                 value_end=url+url_length;  
   
                         if(size_t value_length=value_end-value_start){  
                                 char* value=(char*)services.malloc_atomic(value_length+1);  
                                 memcpy(value, value_start, value_length);  
                                 value[value_length]=0;  
                                 if(atoi(value)==0)  
                                         connection.autocommit=false;  
                         }                          }
                 }                  }
   
Line 231  public: Line 220  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 266  public: Line 257  public:
                                 //CRecordset::useMultiRowFetch                                  //CRecordset::useMultiRowFetch
                                 //CRecordset::userAllocMultiRowBuffers                                  //CRecordset::userAllocMultiRowBuffers
                                 //CRecordset::useExtendedFetch                                  //CRecordset::useExtendedFetch
                                 /*  /*
                                 if(connection.use_multi_row_fetch){                                  if(connection.fast_offset_search){
                                         options+=CRecordset::useMultiRowFetch+CRecordset::userAllocMultiRowBuffers;                                          options+=CRecordset::useMultiRowFetch+CRecordset::userAllocMultiRowBuffers;
                                 } else {                                  } else {
                                         options+=CRecordset::skipDeletedRecords;                                          options+=CRecordset::skipDeletedRecords;
                                 }                                  }
                                 */  */
                                 TRY {                                  TRY {
                                         rs.Open(                                          rs.Open(
                                                 (connection.use_multi_row_fetch)?CRecordset::dynamic:CRecordset::forwardOnly,                                                  (connection.fast_offset_search)?CRecordset::dynamic:CRecordset::forwardOnly,
                                                 statement,                                                  statement,
                                                 options                                                  options
                                         );                                          );
Line 300  public: Line 291  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 309  public: Line 301  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;
   
                                           }
                                         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 319  public: Line 329  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 330  public: Line 340  public:
                                                                   
                                 // skip offset rows                                  // skip offset rows
                                 if(offset){                                  if(offset){
                                         if(connection.use_multi_row_fetch){                                          if(connection.fast_offset_search){
                                                 rs.Move(offset);                                                  rs.Move(offset);
                                         } else {                                          } else {
                                                 unsigned long row=offset;                                                  unsigned long row=offset;
Line 351  public: Line 361  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 369  public: Line 378  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 489  private: Line 499  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.27  
changed lines
  Added in v.1.30


E-mail: