--- sql/odbc/parser3odbc.C 2001/10/29 08:36:51 1.2 +++ sql/odbc/parser3odbc.C 2002/04/25 17:51:38 1.7 @@ -1,11 +1,11 @@ /** @file Parser ODBC driver. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char *RCSId="$Id: parser3odbc.C,v 1.2 2001/10/29 08:36:51 paf Exp $"; +static const char *RCSId="$Id: parser3odbc.C,v 1.7 2002/04/25 17:51:38 paf Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -21,6 +21,19 @@ static const char *RCSId="$Id: parser3od #include #define MAX_STRING 0x400 +#define MAX_NUMBER 40 + +// MSSQL2000 +#ifndef SQL_NVARCHAR +#define SQL_NVARCHAR (-9) +#endif +#ifndef SQL_NTEXT +#define SQL_NTEXT (-10) +#endif +#ifndef SQL_SMALLDATETIME +#define SQL_SMALLDATETIME 11 +#endif +// create table test (id int, a smalldatetime, b ntext, c nvarchar(100)) #define snprintf _snprintf #ifndef strncasecmp @@ -49,7 +62,7 @@ public: /// get api version int api_version() { return SQL_DRIVER_API_VERSION; } - const char *initialize(const char *dlopen_file_spec) { return 0; } + const char *initialize(char *dlopen_file_spec) { return 0; } /** connect @param used_only_in_connect_url format: @b DSN=dsn;UID=user;PWD=password (ODBC connect string) @@ -112,21 +125,17 @@ public: unsigned int quote( SQL_Driver_services&, void *connection, char *to, const char *from, unsigned int length) { - /* - You must allocate the to buffer to be at least length*2+1 bytes long. - (In the worse case, each character may need to be encoded as using two bytes, - and you need room for the terminating null byte.) - - it's already UNTAINT_TIMES_BIGGER - */ - // ' -> '' - unsigned int result=length; - while(length--) { - if(*from=='\'') - *to++='\''; - *to++=*from++; - } - return result; + if(to) { // store mode + unsigned int result=length; + while(length--) { + if(*from=='\'') { // ' -> '' + *to++='\''; result++; + } + *to++=*from++; + } + return result; + } else // estimate mode + return length*2; } void query( SQL_Driver_services& services, void *connection, @@ -171,13 +180,28 @@ public: if(row>=offset) { handlers.add_row(); for(int i=0; iyear, + v.m_pdate->month, + v.m_pdate->day, + v.m_pdate->hour, + v.m_pdate->minute, + v.m_pdate->second, + v.m_pdate->fraction); + ptr=services.malloc(size); + memcpy(ptr, local_buf, size); + break; + } + default: + char msg[MAX_STRING]; + snprintf(msg, MAX_STRING, "unknown column return variant type (%d)", + v.m_dwType); + services._throw(msg); + } + } + + void getFromString(SQL_Driver_services& services, CString& s, void *& ptr, size_t& size) { + if(s.IsEmpty()) { + ptr=0; + size=0; + } else { + const char *cstr=LPCTSTR(s); + size=strlen(cstr); //string.GetLength() works wrong with non-string types: + ptr=services.malloc(size); + memcpy(ptr, cstr, size); + } + } + void _throw(SQL_Driver_services& services, CException *e) { char szCause[MAX_STRING]; szCause[0]=0; e->GetErrorMessage(szCause, MAX_STRING);