diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index d48beafaf..3cceb151a 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -1120,18 +1120,52 @@ unsigned char * MySQL_Data_Stream::resultset2buffer(bool del) { return mybuff; }; +#define RESULTSET_BUFLEN_DS_16K 16000 +#define RESULTSET_BUFLEN_DS_1M 1000*1024 void MySQL_Data_Stream::buffer2resultset(unsigned char *ptr, unsigned int size) { unsigned char *__ptr=ptr; mysql_hdr hdr; unsigned int l; void *pkt; + void *buff = NULL; + unsigned int bl; + unsigned int bf; while (__ptradd(buff,bl-bf); + buff=NULL; + } + } + if (buff == NULL) { + if (__ptr+RESULTSET_BUFLEN_DS_1M <= ptr+size) { + bl = RESULTSET_BUFLEN_DS_1M; + } else { + bl = RESULTSET_BUFLEN_DS_16K; + } + if (l > bl) { + bl = l; // make sure there is the space to copy a packet + } + buff = malloc(bl); + bf = bl; + } + memcpy(buff + (bl-bf), __ptr, l); + bf -= l; + __ptr+=l; +/* l=hdr.pkt_length+sizeof(mysql_hdr); pkt=l_alloc(l); memcpy(pkt,__ptr,l); resultset->add(pkt,l); __ptr+=l; +*/ + } + if (buff) { + // last buffer to add + resultset->add(buff,bl-bf); } };