--- sql/odbc/parser3odbc.C 2008/07/04 16:20:02 1.34 +++ sql/odbc/parser3odbc.C 2012/04/18 09:39:15 1.39 @@ -1,11 +1,10 @@ /** @file Parser ODBC driver. - Copyright(c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char *RCSId="$Id: parser3odbc.C,v 1.34 2008/07/04 16:20:02 misha Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -21,6 +20,8 @@ static const char *RCSId="$Id: parser3od #define WINVER 0x0400 #include +volatile const char * IDENT_PARSER3ODBC_C="$Id: parser3odbc.C,v 1.39 2012/04/18 09:39:15 moko Exp $" IDENT_PA_SQL_DRIVER_H; + // defines #define MAX_COLS 500 @@ -210,16 +211,33 @@ public: return true; } - const char* quote(void *aconnection, const char *from, unsigned int length){ + // charset here is services.request_charset(), not connection.client_charset + // thus we can't use the sql server quoting support + const char* quote(void *aconnection, const char *str, unsigned int length) + { + const char* from; + const char* from_end=str+length; + + size_t quoted=0; + + for(from=str; from(aconnection); - char *result=(char*)connection.services->malloc_atomic(length*2+1); - char *to=result; - while(length--){ - if(*from=='\'') { // ' -> '' - *to++='\''; - } - *to++=*from++; + char *result=(char*)connection.services->malloc_atomic(length + quoted + 1); + char *to = result; + + for(from=str; from '' + *to++=*from; } + *to=0; return result; } @@ -350,7 +368,7 @@ public: CHECK(handlers.before_rows(sql_error)); // skip offset rows - if(offset && !mstatement.offset){ + if(offset && limit!=0 && !mstatement.offset){ unsigned long row=offset; while(!rs.IsEOF() && row--) rs.MoveNext(); @@ -511,10 +529,10 @@ private: +1/*terminator*/ ); - result.limit=true; // with TOP we can't skip offset records easily + result.limit=true; result.statement=statement_limited; - snprintf(statement_limited, MAX_NUMBER+11, "SELECT TOP %u", (limit)?limit+offset:0/*no reasons to skip something if we need 0 rows*/); + snprintf(statement_limited, MAX_NUMBER+11, "SELECT TOP %u", (limit)?limit+offset:0/*no point to skip anything if we need 0 rows*/); astatement+=6;/*skip 'select'*/ strcat(statement_limited, astatement);