2003-12-01 14:19:10 +01:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2003-12-01 14:19:10 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#ifdef HAVE_QUERY_CACHE
|
|
|
|
#include <mysql.h>
|
|
|
|
#include "emb_qcache.h"
|
2006-02-24 17:34:15 +01:00
|
|
|
#include "embedded_priv.h"
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
void Querycache_stream::store_uchar(uchar c)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
|
|
|
if (data_end == cur_data)
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2003-12-01 14:19:10 +01:00
|
|
|
*(cur_data++)= c;
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
stored_size++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_short(ushort s)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
stored_size+= 2;
|
|
|
|
#endif
|
|
|
|
if (data_end - cur_data > 1)
|
|
|
|
{
|
|
|
|
int2store(cur_data, s);
|
|
|
|
cur_data+= 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data_end == cur_data)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2003-12-01 14:19:10 +01:00
|
|
|
int2store(cur_data, s);
|
|
|
|
cur_data+= 2;
|
|
|
|
return;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
*cur_data= ((uchar *)(&s))[0];
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
*(cur_data++)= ((uchar *)(&s))[1];
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_int(uint i)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
stored_size+= 4;
|
|
|
|
#endif
|
|
|
|
size_t rest_len= data_end - cur_data;
|
|
|
|
if (rest_len > 3)
|
|
|
|
{
|
|
|
|
int4store(cur_data, i);
|
|
|
|
cur_data+= 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!rest_len)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2003-12-01 14:19:10 +01:00
|
|
|
int4store(cur_data, i);
|
|
|
|
cur_data+= 4;
|
|
|
|
return;
|
|
|
|
}
|
2005-02-12 17:09:40 +01:00
|
|
|
char buf[4];
|
|
|
|
int4store(buf, i);
|
|
|
|
memcpy(cur_data, buf, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2005-02-12 17:09:40 +01:00
|
|
|
memcpy(cur_data, buf+rest_len, 4-rest_len);
|
2003-12-01 14:19:10 +01:00
|
|
|
cur_data+= 4-rest_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_ll(ulonglong ll)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
stored_size+= 8;
|
|
|
|
#endif
|
|
|
|
size_t rest_len= data_end - cur_data;
|
|
|
|
if (rest_len > 7)
|
|
|
|
{
|
|
|
|
int8store(cur_data, ll);
|
|
|
|
cur_data+= 8;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!rest_len)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2003-12-01 14:19:10 +01:00
|
|
|
int8store(cur_data, ll);
|
|
|
|
cur_data+= 8;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(cur_data, &ll, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
memcpy(cur_data, ((uchar*)&ll)+rest_len, 8-rest_len);
|
2003-12-01 14:19:10 +01:00
|
|
|
cur_data+= 8-rest_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_str_only(const char *str, uint str_len)
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
stored_size+= str_len;
|
|
|
|
#endif
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t rest_len= data_end - cur_data;
|
2005-04-01 05:17:45 +02:00
|
|
|
if (rest_len >= str_len)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
|
|
|
memcpy(cur_data, str, str_len);
|
|
|
|
cur_data+= str_len;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(cur_data, str, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(TRUE);
|
2003-12-01 14:19:10 +01:00
|
|
|
str_len-= rest_len;
|
|
|
|
str+= rest_len;
|
|
|
|
} while(str_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_str(const char *str, uint str_len)
|
|
|
|
{
|
|
|
|
store_int(str_len);
|
|
|
|
store_str_only(str, str_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::store_safe_str(const char *str, uint str_len)
|
|
|
|
{
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
store_int(str_len+1);
|
|
|
|
store_str_only(str, str_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
store_int(0);
|
|
|
|
}
|
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
uchar Querycache_stream::load_uchar()
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
|
|
|
if (cur_data == data_end)
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2003-12-01 14:19:10 +01:00
|
|
|
return *(cur_data++);
|
|
|
|
}
|
|
|
|
|
|
|
|
ushort Querycache_stream::load_short()
|
|
|
|
{
|
|
|
|
ushort result;
|
|
|
|
if (data_end-cur_data > 1)
|
|
|
|
{
|
|
|
|
result= uint2korr(cur_data);
|
|
|
|
cur_data+= 2;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (data_end == cur_data)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2003-12-01 14:19:10 +01:00
|
|
|
result= uint2korr(cur_data);
|
|
|
|
cur_data+= 2;
|
|
|
|
return result;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
((uchar*)&result)[0]= *cur_data;
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
((uchar*)&result)[1]= *(cur_data++);
|
2003-12-01 14:19:10 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint Querycache_stream::load_int()
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
size_t rest_len= data_end - cur_data;
|
|
|
|
if (rest_len > 3)
|
|
|
|
{
|
|
|
|
result= uint4korr(cur_data);
|
|
|
|
cur_data+= 4;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (!rest_len)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2003-12-01 14:19:10 +01:00
|
|
|
result= uint4korr(cur_data);
|
|
|
|
cur_data+= 4;
|
|
|
|
return result;
|
|
|
|
}
|
2005-02-12 17:09:40 +01:00
|
|
|
char buf[4];
|
|
|
|
memcpy(buf, cur_data, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2005-02-12 17:09:40 +01:00
|
|
|
memcpy(buf+rest_len, cur_data, 4-rest_len);
|
2003-12-01 14:19:10 +01:00
|
|
|
cur_data+= 4-rest_len;
|
2005-02-12 17:09:40 +01:00
|
|
|
result= uint4korr(buf);
|
2003-12-01 14:19:10 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulonglong Querycache_stream::load_ll()
|
|
|
|
{
|
|
|
|
ulonglong result;
|
|
|
|
size_t rest_len= data_end - cur_data;
|
|
|
|
if (rest_len > 7)
|
|
|
|
{
|
|
|
|
result= uint8korr(cur_data);
|
|
|
|
cur_data+= 8;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (!rest_len)
|
|
|
|
{
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2003-12-01 14:19:10 +01:00
|
|
|
result= uint8korr(cur_data);
|
|
|
|
cur_data+= 8;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
memcpy(&result, cur_data, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
memcpy(((uchar*)&result)+rest_len, cur_data, 8-rest_len);
|
2003-12-01 14:19:10 +01:00
|
|
|
cur_data+= 8-rest_len;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Querycache_stream::load_str_only(char *buffer, uint str_len)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t rest_len= data_end - cur_data;
|
2005-04-01 05:17:45 +02:00
|
|
|
if (rest_len >= str_len)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
|
|
|
memcpy(buffer, cur_data, str_len);
|
|
|
|
cur_data+= str_len;
|
|
|
|
buffer+= str_len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(buffer, cur_data, rest_len);
|
2005-04-01 05:17:45 +02:00
|
|
|
use_next_block(FALSE);
|
2003-12-01 14:19:10 +01:00
|
|
|
str_len-= rest_len;
|
|
|
|
buffer+= rest_len;
|
|
|
|
} while(str_len);
|
|
|
|
*buffer= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Querycache_stream::load_str(MEM_ROOT *alloc, uint *str_len)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
*str_len= load_int();
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(result= (char*) alloc_root(alloc, *str_len + 1)))
|
2003-12-01 14:19:10 +01:00
|
|
|
return 0;
|
|
|
|
load_str_only(result, *str_len);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Querycache_stream::load_safe_str(MEM_ROOT *alloc, char **str, uint *str_len)
|
|
|
|
{
|
|
|
|
if (!(*str_len= load_int()))
|
|
|
|
{
|
|
|
|
*str= NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
(*str_len)--;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(*str= (char*) alloc_root(alloc, *str_len + 1)))
|
2003-12-01 14:19:10 +01:00
|
|
|
return 1;
|
|
|
|
load_str_only(*str, *str_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Querycache_stream::load_column(MEM_ROOT *alloc, char** column)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
if (!(len = load_int()))
|
|
|
|
{
|
|
|
|
*column= NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len--;
|
2005-02-12 17:09:40 +01:00
|
|
|
if (!(*column= (char *)alloc_root(alloc, len + sizeof(uint) + 1)))
|
2003-12-01 14:19:10 +01:00
|
|
|
return 1;
|
2005-02-12 17:09:40 +01:00
|
|
|
*((uint*)*column)= len;
|
|
|
|
(*column)+= sizeof(uint);
|
2003-12-01 14:19:10 +01:00
|
|
|
load_str_only(*column, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint emb_count_querycache_size(THD *thd)
|
|
|
|
{
|
2006-02-24 17:34:15 +01:00
|
|
|
uint result= 0;
|
|
|
|
MYSQL_FIELD *field;
|
|
|
|
MYSQL_FIELD *field_end;
|
|
|
|
MYSQL_ROWS *cur_row;
|
|
|
|
my_ulonglong n_rows;
|
|
|
|
MYSQL_DATA *data= thd->first_data;
|
|
|
|
|
|
|
|
while (data->embedded_info->next)
|
|
|
|
data= data->embedded_info->next;
|
|
|
|
field= data->embedded_info->fields_list;
|
|
|
|
field_end= field + data->fields;
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2004-01-07 13:41:09 +01:00
|
|
|
if (!field)
|
2006-02-24 17:34:15 +01:00
|
|
|
return result;
|
|
|
|
*data->embedded_info->prev_ptr= NULL; // this marks the last record
|
|
|
|
cur_row= data->data;
|
|
|
|
n_rows= data->rows;
|
2007-11-30 19:17:11 +01:00
|
|
|
/* n_fields + n_rows + field_info * n_fields */
|
|
|
|
result+= (uint) (4+8 + 42*data->fields);
|
2003-12-01 14:19:10 +01:00
|
|
|
|
|
|
|
for(; field < field_end; field++)
|
|
|
|
{
|
|
|
|
result+= field->name_length + field->table_length +
|
|
|
|
field->org_name_length + field->org_table_length + field->db_length +
|
|
|
|
field->catalog_length;
|
|
|
|
if (field->def)
|
|
|
|
result+= field->def_length;
|
|
|
|
}
|
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
if (thd->protocol == &thd->protocol_binary)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
2007-11-30 19:17:11 +01:00
|
|
|
result+= (uint) (4*n_rows);
|
|
|
|
for (; cur_row; cur_row=cur_row->next)
|
|
|
|
result+= cur_row->length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result+= (uint) (4*n_rows*data->fields);
|
|
|
|
for (; cur_row; cur_row=cur_row->next)
|
|
|
|
{
|
|
|
|
MYSQL_ROW col= cur_row->data;
|
|
|
|
MYSQL_ROW col_end= col + data->fields;
|
|
|
|
for (; col < col_end; col++)
|
|
|
|
if (*col)
|
|
|
|
result+= *(uint *)((*col) - sizeof(uint));
|
|
|
|
}
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void emb_store_querycache_result(Querycache_stream *dst, THD *thd)
|
|
|
|
{
|
2006-02-24 17:34:15 +01:00
|
|
|
MYSQL_FIELD *field;
|
|
|
|
MYSQL_FIELD *field_end;
|
|
|
|
MYSQL_ROWS *cur_row;
|
|
|
|
my_ulonglong n_rows;
|
|
|
|
MYSQL_DATA *data= thd->first_data;
|
|
|
|
|
|
|
|
DBUG_ENTER("emb_store_querycache_result");
|
|
|
|
|
|
|
|
while (data->embedded_info->next)
|
|
|
|
data= data->embedded_info->next;
|
|
|
|
field= data->embedded_info->fields_list;
|
|
|
|
field_end= field + data->fields;
|
2004-01-07 13:41:09 +01:00
|
|
|
|
|
|
|
if (!field)
|
2006-02-24 17:34:15 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2004-01-07 13:41:09 +01:00
|
|
|
|
2006-02-24 17:34:15 +01:00
|
|
|
*data->embedded_info->prev_ptr= NULL; // this marks the last record
|
|
|
|
cur_row= data->data;
|
|
|
|
n_rows= data->rows;
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2006-02-24 17:34:15 +01:00
|
|
|
dst->store_int((uint)data->fields);
|
|
|
|
dst->store_ll((ulonglong)n_rows);
|
2003-12-01 14:19:10 +01:00
|
|
|
|
|
|
|
for(; field < field_end; field++)
|
|
|
|
{
|
|
|
|
dst->store_int((uint)field->length);
|
|
|
|
dst->store_int((uint)field->max_length);
|
2007-11-30 19:17:11 +01:00
|
|
|
dst->store_uchar((uchar)field->type);
|
2003-12-01 14:19:10 +01:00
|
|
|
dst->store_short((ushort)field->flags);
|
|
|
|
dst->store_short((ushort)field->charsetnr);
|
2007-11-30 19:17:11 +01:00
|
|
|
dst->store_uchar((uchar)field->decimals);
|
2003-12-01 14:19:10 +01:00
|
|
|
dst->store_str(field->name, field->name_length);
|
|
|
|
dst->store_str(field->table, field->table_length);
|
|
|
|
dst->store_str(field->org_name, field->org_name_length);
|
|
|
|
dst->store_str(field->org_table, field->org_table_length);
|
|
|
|
dst->store_str(field->db, field->db_length);
|
|
|
|
dst->store_str(field->catalog, field->catalog_length);
|
|
|
|
dst->store_safe_str(field->def, field->def_length);
|
|
|
|
}
|
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
if (thd->protocol == &thd->protocol_binary)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
2007-11-30 19:17:11 +01:00
|
|
|
for (; cur_row; cur_row=cur_row->next)
|
|
|
|
dst->store_str((char *) cur_row->data, cur_row->length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (; cur_row; cur_row=cur_row->next)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
2007-11-30 19:17:11 +01:00
|
|
|
MYSQL_ROW col= cur_row->data;
|
|
|
|
MYSQL_ROW col_end= col + data->fields;
|
|
|
|
for (; col < col_end; col++)
|
|
|
|
{
|
|
|
|
uint len= *col ? *(uint *)((*col) - sizeof(uint)) : 0;
|
|
|
|
dst->store_safe_str(*col, len);
|
|
|
|
}
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_ASSERT(emb_count_querycache_size(thd) == dst->stored_size);
|
2006-02-24 17:34:15 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int emb_load_querycache_result(THD *thd, Querycache_stream *src)
|
|
|
|
{
|
2006-02-24 17:34:15 +01:00
|
|
|
MYSQL_DATA *data= thd->alloc_new_dataset();
|
2003-12-01 14:19:10 +01:00
|
|
|
MYSQL_FIELD *field;
|
|
|
|
MYSQL_FIELD *field_end;
|
2006-02-24 17:34:15 +01:00
|
|
|
MEM_ROOT *f_alloc;
|
2003-12-01 14:19:10 +01:00
|
|
|
MYSQL_ROWS *row, *end_row;
|
|
|
|
MYSQL_ROWS **prev_row;
|
|
|
|
ulonglong rows;
|
|
|
|
MYSQL_ROW columns;
|
2006-02-24 17:34:15 +01:00
|
|
|
DBUG_ENTER("emb_load_querycache_result");
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
goto err;
|
|
|
|
init_alloc_root(&data->alloc, 8192,0);
|
|
|
|
f_alloc= &data->alloc;
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2006-02-24 17:34:15 +01:00
|
|
|
data->fields= src->load_int();
|
2003-12-01 14:19:10 +01:00
|
|
|
rows= src->load_ll();
|
|
|
|
|
|
|
|
if (!(field= (MYSQL_FIELD *)
|
2006-02-24 17:34:15 +01:00
|
|
|
alloc_root(f_alloc,data->fields*sizeof(MYSQL_FIELD))))
|
2003-12-01 14:19:10 +01:00
|
|
|
goto err;
|
2006-02-24 17:34:15 +01:00
|
|
|
data->embedded_info->fields_list= field;
|
|
|
|
for(field_end= field+data->fields; field < field_end; field++)
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
|
|
|
field->length= src->load_int();
|
|
|
|
field->max_length= (unsigned int)src->load_int();
|
2007-11-30 19:17:11 +01:00
|
|
|
field->type= (enum enum_field_types)src->load_uchar();
|
2003-12-01 14:19:10 +01:00
|
|
|
field->flags= (unsigned int)src->load_short();
|
|
|
|
field->charsetnr= (unsigned int)src->load_short();
|
2007-11-30 19:17:11 +01:00
|
|
|
field->decimals= src->load_uchar();
|
2003-12-01 14:19:10 +01:00
|
|
|
|
|
|
|
if (!(field->name= src->load_str(f_alloc, &field->name_length)) ||
|
2006-02-24 17:34:15 +01:00
|
|
|
!(field->table= src->load_str(f_alloc,&field->table_length)) ||
|
|
|
|
!(field->org_name= src->load_str(f_alloc, &field->org_name_length)) ||
|
|
|
|
!(field->org_table= src->load_str(f_alloc, &field->org_table_length))||
|
|
|
|
!(field->db= src->load_str(f_alloc, &field->db_length)) ||
|
|
|
|
!(field->catalog= src->load_str(f_alloc, &field->catalog_length)) ||
|
|
|
|
src->load_safe_str(f_alloc, &field->def, &field->def_length))
|
2003-12-01 14:19:10 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->rows= rows;
|
2006-02-24 17:34:15 +01:00
|
|
|
if (!rows)
|
|
|
|
goto return_ok;
|
2007-11-30 19:17:11 +01:00
|
|
|
if (thd->protocol == &thd->protocol_binary)
|
|
|
|
{
|
|
|
|
uint length;
|
2008-07-10 22:41:56 +02:00
|
|
|
row= (MYSQL_ROWS *)alloc_root(&data->alloc,
|
|
|
|
(size_t) (rows * sizeof(MYSQL_ROWS)));
|
2007-11-30 19:17:11 +01:00
|
|
|
end_row= row + rows;
|
|
|
|
data->data= row;
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
for (prev_row= &row->next; row < end_row; prev_row= &row->next, row++)
|
|
|
|
{
|
|
|
|
*prev_row= row;
|
|
|
|
row->data= (MYSQL_ROW) src->load_str(&data->alloc, &length);
|
|
|
|
row->length= length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2003-12-01 14:19:10 +01:00
|
|
|
{
|
2007-11-30 19:17:11 +01:00
|
|
|
row= (MYSQL_ROWS *)alloc_root(&data->alloc,
|
|
|
|
(uint) (rows * sizeof(MYSQL_ROWS) +
|
|
|
|
rows*(data->fields+1)*sizeof(char*)));
|
|
|
|
end_row= row + rows;
|
|
|
|
columns= (MYSQL_ROW)end_row;
|
2003-12-01 14:19:10 +01:00
|
|
|
|
2007-11-30 19:17:11 +01:00
|
|
|
data->data= row;
|
|
|
|
|
|
|
|
for (prev_row= &row->next; row < end_row; prev_row= &row->next, row++)
|
|
|
|
{
|
|
|
|
*prev_row= row;
|
|
|
|
row->data= columns;
|
|
|
|
MYSQL_ROW col_end= columns + data->fields;
|
|
|
|
for (; columns < col_end; columns++)
|
|
|
|
src->load_column(&data->alloc, columns);
|
|
|
|
|
|
|
|
*(columns++)= NULL;
|
|
|
|
}
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
*prev_row= NULL;
|
2006-02-24 17:34:15 +01:00
|
|
|
data->embedded_info->prev_ptr= prev_row;
|
|
|
|
return_ok:
|
2007-12-13 21:58:55 +01:00
|
|
|
net_send_eof(thd, thd->server_status, thd->total_warn_count);
|
2006-02-24 17:34:15 +01:00
|
|
|
DBUG_RETURN(0);
|
2003-12-01 14:19:10 +01:00
|
|
|
err:
|
2006-02-24 17:34:15 +01:00
|
|
|
DBUG_RETURN(1);
|
2003-12-01 14:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*HAVE_QUERY_CACHE*/
|
|
|
|
|