--- sql/odbc/parser3odbc.C 2008/06/27 14:02:24 1.29 +++ sql/odbc/parser3odbc.C 2008/07/01 10:21:03 1.32 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char *RCSId="$Id: parser3odbc.C,v 1.29 2008/06/27 14:02:24 misha Exp $"; +static const char *RCSId="$Id: parser3odbc.C,v 1.32 2008/07/01 10:21:03 misha Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -96,8 +96,8 @@ public: @param url format: @b DSN=dsn;UID=user;PWD=password? (ODBC connect string) ClientCharset=charset& // transcode with parser - FastOffsetSearch=0& // 0 -- disable (slower) autocommit=1& // 0 -- disable auto commit + FastOffsetSearch=0 WARNING: must be used only to connect, for buffer doesn't live long */ @@ -116,6 +116,8 @@ public: size_t url_length=strlen(url); char *options=lsplit(url, '?'); + // todo: analize connect string and if 'SQL Server' found, modify query and add TOP into SELECTs + while(options){ if(char *key=lsplit(&options, '&')){ if(*key){ @@ -140,9 +142,7 @@ public: TRY { connection.db=new CDatabase(); connection.db->OpenEx(url, CDatabase::noOdbcDialog); - - if(!connection.autocommit) - connection.db->BeginTrans(); + connection.db->BeginTrans(); } CATCH_ALL (e) { _throw(services, e); @@ -163,28 +163,24 @@ public: void commit(void *aconnection){ Connection& connection=*static_cast(aconnection); - if(!connection.autocommit){ - TRY - connection.db->CommitTrans(); - connection.db->BeginTrans(); - CATCH_ALL (e) { - _throw(*connection.services, e); - } - END_CATCH_ALL + TRY + connection.db->CommitTrans(); + connection.db->BeginTrans(); + CATCH_ALL (e) { + _throw(*connection.services, e); } + END_CATCH_ALL } void rollback(void *aconnection){ Connection& connection=*static_cast(aconnection); - if(!connection.autocommit){ - TRY - connection.db->Rollback(); - connection.db->BeginTrans(); - CATCH_ALL (e) { - _throw(*connection.services, e); - } - END_CATCH_ALL + TRY + connection.db->Rollback(); + connection.db->BeginTrans(); + CATCH_ALL (e) { + _throw(*connection.services, e); } + END_CATCH_ALL } bool ping(void *connection){ @@ -220,15 +216,17 @@ public: if(placeholders_count>0) 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 if(transcode_needed){ size_t length=strlen(statement); services.transcode(statement, length, statement, length, - services.request_charset(), - connection.client_charset); + request_charset, + client_charset); } while(isspace((unsigned char)*statement)) @@ -289,6 +287,7 @@ public: column_count=MAX_COLS; SWORD column_types[MAX_COLS]; + bool transcode_column[MAX_COLS]; SQL_Error sql_error; #define CHECK(afailed) if(afailed) services._throw(sql_error) @@ -298,6 +297,24 @@ public: CODBCFieldInfo fieldinfo; rs.GetODBCFieldInfo(i, fieldinfo); 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(); char *str=0; if(length){ @@ -308,8 +325,8 @@ public: if(transcode_needed){ services.transcode(str, length, str, length, - connection.client_charset, - services.request_charset()); + client_charset, + request_charset); } } CHECK(handlers.add_column(sql_error, str, length)); @@ -323,10 +340,8 @@ public: rs.Move(offset); } else { unsigned long row=offset; - while(!rs.IsEOF() && row>0){ + while(!rs.IsEOF() && row--) rs.MoveNext(); - row--; - } } } @@ -340,7 +355,6 @@ public: char* str; switch(column_types[i]){ //case xBOOL: - //case SQL_INTEGER: // serg@design.ru did that in parser2. test first! //case SQL_DATETIME: << default: handles that more properly (?) case SQL_BINARY: case SQL_VARBINARY: @@ -358,11 +372,12 @@ public: } // transcode cell value from ?ClientCharset to $request:charset - if(transcode_needed && length) + if(length && transcode_column[i]){ services.transcode(str, length, str, length, - connection.client_charset, - services.request_charset()); + client_charset, + request_charset); + } CHECK(handlers.add_row_cell(sql_error, str, length)); } @@ -377,6 +392,9 @@ public: } CATCH_ALL (e) { _throw(services, e); } END_CATCH_ALL + + if(connection.autocommit) + commit(aconnection); } private: @@ -401,7 +419,7 @@ private: ptr=v.m_boolVal?"1":"0"; length=1; break;*/ -/* case DBVT_UCHAR: +/* case DBVT_UCHAR: length=strlen(ptr=v.m_chVal); break; case DBVT_SHORT: @@ -478,10 +496,6 @@ private: 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() {