--- sql/mysql/parser3mysql.C 2002/12/09 11:07:46 1.8 +++ sql/mysql/parser3mysql.C 2003/07/24 10:09:40 1.13 @@ -1,7 +1,7 @@ /** @file Parser MySQL driver. - Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright(c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) @@ -10,7 +10,7 @@ 2001.11.06 numrows on "HP-UX istok1 B.11.00 A 9000/869 448594332 two-user license" 3.23.42 & 4.0.0.alfa never worked, both subst & .sl version returned 0 */ -static const char *RCSId="$Id: parser3mysql.C,v 1.8 2002/12/09 11:07:46 paf Exp $"; +static const char *RCSId="$Id: parser3mysql.C,v 1.13 2003/07/24 10:09:40 paf Exp $"; #include "config_includes.h" @@ -151,19 +151,18 @@ public: return mysql_ping((MYSQL *)connection)==0; } - unsigned int quote( - SQL_Driver_services&, void *connection, - char *to, const char *from, unsigned int length) { + const char* quote( + SQL_Driver_services& services, void *connection, + const char *from, unsigned int length) { /* 3.23.22b 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.) */ - if(to) // store mode - return mysql_escape_string(to, from, length); - else // estimate mode - return length*2+1; + char *result=(char*)services.malloc_atomic(length*2+1); + mysql_escape_string(result, from, length); + return result; } void query( SQL_Driver_services& services, void *connection, @@ -176,7 +175,7 @@ public: const char *statement; if(offset || limit) { size_t statement_size=strlen(astatement); - char *statement_limited=(char *)services.malloc( + char *statement_limited=(char *)services.malloc_atomic( statement_size+MAX_NUMBER*2+8/* limit #,#*/+1); char *cur=statement_limited; memcpy(cur, astatement, statement_size); cur+=statement_size; @@ -205,42 +204,49 @@ public: services._throw("result contains no columns"); } - try { + bool failed=false; + SQL_Error sql_error; +#define CHECK(afailed) \ + if(afailed) { \ + failed=true; \ + goto cleanup; \ + } - for(int i=0; iname); - void *ptr=services.malloc(size); - memcpy(ptr, field->name, size); - handlers.add_column(ptr, size); + for(int i=0; iname); + char* str=(char*)services.malloc_atomic(length+1); + memcpy(str, field->name, length+1); + CHECK(handlers.add_column(sql_error, str, length)); + } else { + // seen some broken client, + // which reported "44" for column count of response to "select 2+2" + column_count=i; + break; } - - handlers.before_rows(); - - while(MYSQL_ROW mysql_row=mysql_fetch_row(res)) { - handlers.add_row(); - unsigned long *lengths=mysql_fetch_lengths(res); - for(int i=0; i