2004-04-01 11:02:42 +02:00
|
|
|
/* Copyright (C) 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.
|
2004-04-01 11:02:42 +02: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 */
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
/**
|
|
|
|
@file ha_example.cc
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
The ha_example engine is a stubbed storage engine for example purposes only;
|
|
|
|
it does nothing at this point. Its purpose is to provide a source
|
|
|
|
code illustration of how to begin writing new storage engines; see also
|
|
|
|
/storage/example/ha_example.h.
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
|
|
|
ha_example will let you create/open/delete tables, but
|
|
|
|
nothing further (for example, indexes are not supported nor can data
|
|
|
|
be stored in the table). Use this example as a template for
|
|
|
|
implementing the same functionality in your own storage engine. You
|
|
|
|
can enable the example storage engine in your build by doing the
|
|
|
|
following during your build process:<br> ./configure
|
|
|
|
--with-example-storage-engine
|
2004-06-23 21:26:34 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Once this is done, MySQL will let you create tables with:<br>
|
|
|
|
CREATE TABLE <table name> (...) ENGINE=EXAMPLE;
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
The example storage engine is set up to use table locks. It
|
|
|
|
implements an example "SHARE" that is inserted into a hash by table
|
|
|
|
name. You can use this to store information of state that any
|
|
|
|
example handler object will be able to see when it is using that
|
|
|
|
table.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Please read the object definition in ha_example.h before reading the rest
|
2006-12-19 03:08:38 +01:00
|
|
|
of this file.
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@note
|
|
|
|
When you create an EXAMPLE table, the MySQL Server creates a table .frm
|
|
|
|
(format) file in the database directory, using the table name as the file
|
|
|
|
name as is customary with MySQL. No other files are created. To get an idea
|
|
|
|
of what occurs, here is an example select that would do a scan of an entire
|
|
|
|
table:
|
|
|
|
|
|
|
|
@code
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_example::store_lock
|
|
|
|
ha_example::external_lock
|
|
|
|
ha_example::info
|
|
|
|
ha_example::rnd_init
|
|
|
|
ha_example::extra
|
2006-12-19 03:08:38 +01:00
|
|
|
ENUM HA_EXTRA_CACHE Cache record in HA_rrnd()
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::extra
|
2006-12-19 03:08:38 +01:00
|
|
|
ENUM HA_EXTRA_NO_CACHE End caching of records (def)
|
2004-06-23 21:26:34 +02:00
|
|
|
ha_example::external_lock
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_example::extra
|
2006-12-19 03:08:38 +01:00
|
|
|
ENUM HA_EXTRA_RESET Reset database to after open
|
2007-01-29 00:47:35 +01:00
|
|
|
@endcode
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
Here you see that the example storage engine has 9 rows called before
|
|
|
|
rnd_next signals that it has reached the end of its data. Also note that
|
|
|
|
the table in question was already opened; had it not been open, a call to
|
|
|
|
ha_example::open() would also have been necessary. Calls to
|
|
|
|
ha_example::extra() are hints as to what will be occuring to the request.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Happy coding!<br>
|
2004-05-12 00:59:20 +02:00
|
|
|
-Brian
|
|
|
|
*/
|
|
|
|
|
2005-06-02 02:43:32 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2004-04-01 11:02:42 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
2006-08-19 06:19:19 +02:00
|
|
|
#define MYSQL_SERVER 1
|
2005-12-21 23:03:57 +01:00
|
|
|
#include "mysql_priv.h"
|
2004-04-01 11:02:42 +02:00
|
|
|
#include "ha_example.h"
|
2006-02-14 10:51:25 +01:00
|
|
|
#include <mysql/plugin.h>
|
2005-12-21 23:03:57 +01:00
|
|
|
|
2006-09-30 02:19:02 +02:00
|
|
|
static handler *example_create_handler(handlerton *hton,
|
|
|
|
TABLE_SHARE *table,
|
|
|
|
MEM_ROOT *mem_root);
|
2005-07-19 20:21:12 +02:00
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
handlerton *example_hton;
|
2005-07-19 20:21:12 +02:00
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
/* Variables for example share methods */
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
/*
|
|
|
|
Hash used to track the number of open tables; variable for example share
|
|
|
|
methods
|
|
|
|
*/
|
|
|
|
static HASH example_open_tables;
|
|
|
|
|
|
|
|
/* The mutex used to init the hash; variable for example share methods */
|
|
|
|
pthread_mutex_t example_mutex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Function we use in the creation of our hash to get key.
|
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
static uchar* example_get_key(EXAMPLE_SHARE *share,uint *length,
|
2004-04-01 11:02:42 +02:00
|
|
|
my_bool not_used __attribute__((unused)))
|
|
|
|
{
|
|
|
|
*length=share->table_name_length;
|
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
|
|
|
return (uchar*) share->table_name;
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
static int example_init_func(void *p)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2006-04-19 09:39:57 +02:00
|
|
|
DBUG_ENTER("example_init_func");
|
2006-11-20 03:01:54 +01:00
|
|
|
|
|
|
|
example_hton= (handlerton *)p;
|
|
|
|
VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST));
|
|
|
|
(void) hash_init(&example_open_tables,system_charset_info,32,0,0,
|
|
|
|
(hash_get_key) example_get_key,0,0);
|
|
|
|
|
|
|
|
example_hton->state= SHOW_OPTION_YES;
|
|
|
|
example_hton->db_type= DB_TYPE_EXAMPLE_DB;
|
|
|
|
example_hton->create= example_create_handler;
|
|
|
|
example_hton->flags= HTON_CAN_RECREATE;
|
|
|
|
|
2006-04-19 09:39:57 +02:00
|
|
|
DBUG_RETURN(0);
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
static int example_done_func(void *p)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2006-04-19 09:39:57 +02:00
|
|
|
int error= 0;
|
|
|
|
DBUG_ENTER("example_done_func");
|
|
|
|
|
2006-11-20 03:01:54 +01:00
|
|
|
if (example_open_tables.records)
|
|
|
|
error= 1;
|
|
|
|
hash_free(&example_open_tables);
|
|
|
|
pthread_mutex_destroy(&example_mutex);
|
|
|
|
|
2006-04-19 09:39:57 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
|
|
|
Example of simple lock controls. The "share" it creates is a
|
|
|
|
structure we will pass to each example handler. Do you have to have
|
|
|
|
one of these? Well, you have pieces that are used for locking, and
|
|
|
|
they are needed to function.
|
2004-04-01 11:02:42 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
2004-04-06 07:57:53 +02:00
|
|
|
EXAMPLE_SHARE *share;
|
2004-04-01 11:02:42 +02:00
|
|
|
uint length;
|
|
|
|
char *tmp_name;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&example_mutex);
|
|
|
|
length=(uint) strlen(table_name);
|
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!(share=(EXAMPLE_SHARE*) hash_search(&example_open_tables,
|
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*) table_name,
|
2004-04-13 06:01:45 +02:00
|
|
|
length)))
|
|
|
|
{
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!(share=(EXAMPLE_SHARE *)
|
2004-04-01 11:02:42 +02:00
|
|
|
my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
|
|
|
|
&share, sizeof(*share),
|
|
|
|
&tmp_name, length+1,
|
2004-06-23 21:26:34 +02:00
|
|
|
NullS)))
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
share->use_count=0;
|
|
|
|
share->table_name_length=length;
|
|
|
|
share->table_name=tmp_name;
|
|
|
|
strmov(share->table_name,table_name);
|
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 (my_hash_insert(&example_open_tables, (uchar*) share))
|
2004-04-01 11:02:42 +02:00
|
|
|
goto error;
|
|
|
|
thr_lock_init(&share->lock);
|
|
|
|
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
|
|
|
|
}
|
|
|
|
share->use_count++;
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
|
|
|
|
return share;
|
|
|
|
|
|
|
|
error:
|
2005-06-02 02:34:10 +02:00
|
|
|
pthread_mutex_destroy(&share->mutex);
|
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
|
|
|
my_free(share, MYF(0));
|
2004-04-01 11:02:42 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Free lock controls. We call this whenever we close a table. If the table had
|
2006-12-19 03:08:38 +01:00
|
|
|
the last reference to the share, then we free memory associated with it.
|
2004-04-01 11:02:42 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
static int free_share(EXAMPLE_SHARE *share)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&example_mutex);
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!--share->use_count)
|
|
|
|
{
|
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
|
|
|
hash_delete(&example_open_tables, (uchar*) share);
|
2004-04-01 11:02:42 +02:00
|
|
|
thr_lock_delete(&share->lock);
|
|
|
|
pthread_mutex_destroy(&share->mutex);
|
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
|
|
|
my_free(share, MYF(0));
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-30 02:19:02 +02:00
|
|
|
static handler* example_create_handler(handlerton *hton,
|
|
|
|
TABLE_SHARE *table,
|
|
|
|
MEM_ROOT *mem_root)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
2006-09-30 02:19:02 +02:00
|
|
|
return new (mem_root) ha_example(hton, table);
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
|
|
|
|
2006-09-30 02:19:02 +02:00
|
|
|
ha_example::ha_example(handlerton *hton, TABLE_SHARE *table_arg)
|
|
|
|
:handler(hton, table_arg)
|
2005-07-19 20:21:12 +02:00
|
|
|
{}
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
/**
|
|
|
|
@brief
|
|
|
|
If frm_error() is called then we will use this to determine
|
|
|
|
the file extensions that exist for the storage engine. This is also
|
|
|
|
used by the default rename_table and delete_table method in
|
|
|
|
handler.cc.
|
|
|
|
|
2007-03-30 10:00:21 +02:00
|
|
|
For engines that have two file name extentions (separate meta/index file
|
|
|
|
and data file), the order of elements is relevant. First element of engine
|
|
|
|
file name extentions array should be meta/index file extention. Second
|
|
|
|
element - data file extention. This order is assumed by
|
|
|
|
prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
|
2007-03-31 14:29:40 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
rename_table method in handler.cc and
|
|
|
|
delete_table method in handler.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2005-04-27 11:25:08 +02:00
|
|
|
static const char *ha_example_exts[] = {
|
|
|
|
NullS
|
|
|
|
};
|
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
const char **ha_example::bas_ext() const
|
2005-04-27 11:25:08 +02:00
|
|
|
{
|
|
|
|
return ha_example_exts;
|
|
|
|
}
|
2004-04-01 11:02:42 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Used for opening tables. The name will be the name of the file.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
2006-12-19 03:08:38 +01:00
|
|
|
A table is opened when it needs to be opened; e.g. when a request comes in
|
|
|
|
for a SELECT on the table (tables are not open and closed for each request,
|
|
|
|
they are cached).
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
Called from handler.cc by handler::ha_open(). The server opens all tables by
|
|
|
|
calling ha_open() which then calls the handler specific open().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
handler::ha_open() in handler.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::open(const char *name, int mode, uint test_if_locked)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::open");
|
|
|
|
|
|
|
|
if (!(share = get_share(name, table)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
thr_lock_data_init(&share->lock,&lock,NULL);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-06-23 21:26:34 +02:00
|
|
|
Closes a table. We call the free_share() function to free any resources
|
2004-05-12 00:59:20 +02:00
|
|
|
that we have allocated in the "shared" structure.
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
2006-12-19 03:08:38 +01:00
|
|
|
Called from sql_base.cc, sql_select.cc, and table.cc. In sql_select.cc it is
|
2007-01-29 00:47:35 +01:00
|
|
|
only used to close up temporary tables or during the process where a
|
|
|
|
temporary table is converted over to being a myisam table.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
For sql_base.cc look at close_data_tables().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
sql_base.cc, sql_select.cc and table.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::close(void)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::close");
|
|
|
|
DBUG_RETURN(free_share(share));
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
write_row() inserts a row. No extra() hint is given currently if a bulk load
|
2006-12-19 03:08:38 +01:00
|
|
|
is happening. buf() is a byte array of data. You can use the field
|
2004-05-12 00:59:20 +02:00
|
|
|
information to extract the data from the native byte array type.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
Example of this would be:
|
2006-12-19 03:08:38 +01:00
|
|
|
@code
|
2004-05-12 00:59:20 +02:00
|
|
|
for (Field **field=table->field ; *field ; field++)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
2006-12-19 03:08:38 +01:00
|
|
|
@endcode
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
See ha_tina.cc for an example of extracting all of the data as strings.
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_berekly.cc has an example of how to store it intact by "packing" it
|
|
|
|
for ha_berkeley's own native storage type.
|
|
|
|
|
|
|
|
See the note for update_row() on auto_increments and timestamps. This
|
2006-12-19 03:08:38 +01:00
|
|
|
case also applies to write_row().
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc,
|
2004-05-12 00:59:20 +02:00
|
|
|
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc,
|
|
|
|
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
int ha_example::write_row(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::write_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Yes, update_row() does what you expect, it updates a row. old_data will have
|
2006-12-19 03:08:38 +01:00
|
|
|
the previous row record in it, while new_data will have the newest data in it.
|
2004-05-12 00:59:20 +02:00
|
|
|
Keep in mind that the server can do updates based on ordering if an ORDER BY
|
2006-12-19 03:08:38 +01:00
|
|
|
clause was used. Consecutive ordering is not guaranteed.
|
|
|
|
|
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
Currently new_data will not have an updated auto_increament record, or
|
2006-12-19 03:08:38 +01:00
|
|
|
and updated timestamp field. You can do these for example by doing:
|
|
|
|
@code
|
2004-10-18 08:32:52 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
|
|
|
table->timestamp_field->set_time();
|
2004-05-12 00:59:20 +02:00
|
|
|
if (table->next_number_field && record == table->record[0])
|
|
|
|
update_auto_increment();
|
2006-12-19 03:08:38 +01:00
|
|
|
@endcode
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
sql_select.cc, sql_acl.cc, sql_update.cc and sql_insert.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
int ha_example::update_row(const uchar *old_data, uchar *new_data)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
DBUG_ENTER("ha_example::update_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
This will delete a row. buf will contain a copy of the row to be deleted.
|
|
|
|
The server will call this right after the current row has been called (from
|
|
|
|
either a previous rnd_nexT() or index call).
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
2004-06-23 21:26:34 +02:00
|
|
|
If you keep a pointer to the last row or can access a primary key it will
|
2006-12-19 03:08:38 +01:00
|
|
|
make doing the deletion quite a bit easier. Keep in mind that the server does
|
|
|
|
not guarantee consecutive deletions. ORDER BY clauses can be used.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
Called in sql_acl.cc and sql_udf.cc to manage internal table
|
|
|
|
information. Called in sql_delete.cc, sql_insert.cc, and
|
|
|
|
sql_select.cc. In sql_select it is used for removing duplicates
|
|
|
|
while in insert it is used for REPLACE calls.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
sql_acl.cc, sql_udf.cc, sql_delete.cc, sql_insert.cc and sql_select.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
int ha_example::delete_row(const uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Positions an index cursor to the index specified in the handle. Fetches the
|
|
|
|
row if available. If the key value is null, begin at the first key of the
|
|
|
|
index.
|
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
int ha_example::index_read(uchar *buf, const uchar *key,
|
2007-03-17 00:13:25 +01:00
|
|
|
key_part_map keypart_map __attribute__((unused)),
|
2004-04-01 11:02:42 +02:00
|
|
|
enum ha_rkey_function find_flag
|
|
|
|
__attribute__((unused)))
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_read");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Used to read forward through the index.
|
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
int ha_example::index_next(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_next");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
Used to read backwards through the index.
|
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
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
|
|
|
int ha_example::index_prev(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_prev");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
index_first() asks for the first key in the index.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
|
|
|
Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc.
|
|
|
|
|
|
|
|
@see
|
|
|
|
opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
int ha_example::index_first(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_first");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
index_last() asks for the last key in the index.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
|
|
|
Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc.
|
|
|
|
|
|
|
|
@see
|
|
|
|
opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
int ha_example::index_last(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_last");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
rnd_init() is called when the system wants the storage engine to do a table
|
2006-12-19 03:08:38 +01:00
|
|
|
scan. See the example in the introduction at the top of this file to see when
|
2004-05-12 00:59:20 +02:00
|
|
|
rnd_init() is called.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc,
|
|
|
|
and sql_update.cc.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rnd_init(bool scan)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_init");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
int ha_example::rnd_end()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_end");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
This is called for each row of the table scan. When you run out of records
|
|
|
|
you should return HA_ERR_END_OF_FILE. Fill buff up with the row information.
|
|
|
|
The Field structure for the table is the key to getting data into buf
|
|
|
|
in a manner that will allow the server to understand it.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc,
|
|
|
|
and sql_update.cc.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
int ha_example::rnd_next(uchar *buf)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_next");
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
position() is called after each call to rnd_next() if the data needs
|
|
|
|
to be ordered. You can do something like the following to store
|
|
|
|
the position:
|
2006-12-19 03:08:38 +01:00
|
|
|
@code
|
2005-02-20 20:52:28 +01:00
|
|
|
my_store_ptr(ref, ref_length, current_position);
|
2006-12-19 03:08:38 +01:00
|
|
|
@endcode
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
The server uses ref to store data. ref_length in the above case is
|
|
|
|
the size needed to store current_position. ref is just a byte array
|
|
|
|
that the server will maintain. If you are using offsets to mark rows, then
|
|
|
|
current_position should be the offset. If it is a primary key like in
|
2004-06-23 21:26:34 +02:00
|
|
|
BDB, then it needs to be a primary key.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Called from filesort.cc, sql_select.cc, sql_delete.cc, and sql_update.cc.
|
|
|
|
|
|
|
|
@see
|
|
|
|
filesort.cc, sql_select.cc, sql_delete.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
void ha_example::position(const uchar *record)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::position");
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
This is like rnd_next, but you are given a position to use
|
|
|
|
to determine the row. The position will be of the type that you stored in
|
|
|
|
ref. You can use ha_get_ptr(pos,ref_length) to retrieve whatever key
|
|
|
|
or position you saved when position() was called.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@details
|
|
|
|
Called from filesort.cc, records.cc, sql_insert.cc, sql_select.cc, and sql_update.cc.
|
|
|
|
|
|
|
|
@see
|
|
|
|
filesort.cc, records.cc, sql_insert.cc, sql_select.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
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
|
|
|
int ha_example::rnd_pos(uchar *buf, uchar *pos)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_pos");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
::info() is used to return information to the optimizer. See my_base.h for
|
|
|
|
the complete description.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
|
|
|
Currently this table handler doesn't implement most of the fields really needed.
|
|
|
|
SHOW also makes use of this data.
|
2005-11-26 08:54:13 +01:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
You will probably want to have the following in your code:
|
|
|
|
@code
|
2004-05-12 00:59:20 +02:00
|
|
|
if (records < 2)
|
|
|
|
records = 2;
|
2006-12-19 03:08:38 +01:00
|
|
|
@endcode
|
2004-05-12 00:59:20 +02:00
|
|
|
The reason is that the server will optimize for cases of only a single
|
2006-12-19 03:08:38 +01:00
|
|
|
record. If, in a table scan, you don't know the number of records, it
|
|
|
|
will probably be better to set records to two so you can return as many
|
|
|
|
records as you need. Along with records, a few more variables you may wish
|
|
|
|
to set are:
|
2004-05-12 00:59:20 +02:00
|
|
|
records
|
|
|
|
deleted
|
|
|
|
data_file_length
|
|
|
|
index_file_length
|
|
|
|
delete_length
|
|
|
|
check_time
|
|
|
|
Take a look at the public variables in handler.h for more information.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Called in filesort.cc, ha_heap.cc, item_sum.cc, opt_sum.cc, sql_delete.cc,
|
|
|
|
sql_delete.cc, sql_derived.cc, sql_select.cc, sql_select.cc, sql_select.cc,
|
|
|
|
sql_select.cc, sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc,
|
|
|
|
sql_table.cc, sql_union.cc, and sql_update.cc.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@see
|
|
|
|
filesort.cc, ha_heap.cc, item_sum.cc, opt_sum.cc, sql_delete.cc, sql_delete.cc,
|
|
|
|
sql_derived.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc,
|
|
|
|
sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_table.cc,
|
|
|
|
sql_union.cc and sql_update.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2006-08-10 16:55:20 +02:00
|
|
|
int ha_example::info(uint flag)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::info");
|
2006-08-10 16:55:20 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
extra() is called whenever the server wishes to send a hint to
|
|
|
|
the storage engine. The myisam engine implements the most hints.
|
|
|
|
ha_innodb.cc has the most exhaustive list of these hints.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
ha_innodb.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::extra(enum ha_extra_function operation)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::extra");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
Used to delete all rows in a table, including cases of truncate and cases where
|
|
|
|
the optimizer realizes that all rows will be removed as a result of an SQL statement.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from item_sum.cc by Item_func_group_concat::clear(),
|
2004-05-12 00:59:20 +02:00
|
|
|
Item_sum_count_distinct::clear(), and Item_func_group_concat::clear().
|
|
|
|
Called from sql_delete.cc by mysql_delete().
|
|
|
|
Called from sql_select.cc by JOIN::reinit().
|
|
|
|
Called from sql_union.cc by st_select_lex_unit::exec().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
Item_func_group_concat::clear(), Item_sum_count_distinct::clear() and
|
|
|
|
Item_func_group_concat::clear() in item_sum.cc;
|
|
|
|
mysql_delete() in sql_delete.cc;
|
|
|
|
JOIN::reinit() in sql_select.cc and
|
|
|
|
st_select_lex_unit::exec() in sql_union.cc.
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::delete_all_rows()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_all_rows");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
This create a lock on the table. If you are implementing a storage engine
|
|
|
|
that can handle transacations look at ha_berkely.cc to see how you will
|
2006-12-19 03:08:38 +01:00
|
|
|
want to go about doing this. Otherwise you should consider calling flock()
|
|
|
|
here. Hint: Read the section "locking functions for mysql" in lock.cc to understand
|
|
|
|
this.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from lock.cc by lock_external() and unlock_external(). Also called
|
|
|
|
from sql_table.cc by copy_data_between_tables().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
lock.cc by lock_external() and unlock_external() in lock.cc;
|
|
|
|
the section "locking functions for mysql" in lock.cc;
|
|
|
|
copy_data_between_tables() in sql_table.cc.
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::external_lock(THD *thd, int lock_type)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::external_lock");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
The idea with handler::store_lock() is: The statement decides which locks
|
|
|
|
should be needed for the table. For updates/deletes/inserts we get WRITE
|
|
|
|
locks, for SELECT... we get read locks.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
|
|
|
Before adding the lock into the table lock handler (see thr_lock.c),
|
|
|
|
mysqld calls store lock with the requested locks. Store lock can now
|
2004-05-12 00:59:20 +02:00
|
|
|
modify a write lock to a read lock (or some other lock), ignore the
|
2006-12-19 03:08:38 +01:00
|
|
|
lock (if we don't want to use MySQL table locks at all), or add locks
|
2004-05-12 00:59:20 +02:00
|
|
|
for many tables (like we do when we are using a MERGE handler).
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Berkeley DB, for example, changes all WRITE locks to TL_WRITE_ALLOW_WRITE
|
|
|
|
(which signals that we are doing WRITES, but are still allowing other
|
|
|
|
readers and writers).
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
When releasing locks, store_lock() is also called. In this case one
|
2004-05-12 00:59:20 +02:00
|
|
|
usually doesn't have to do anything.
|
|
|
|
|
|
|
|
In some exceptional cases MySQL may send a request for a TL_IGNORE;
|
|
|
|
This means that we are requesting the same lock as last time and this
|
|
|
|
should also be ignored. (This may happen when someone does a flush
|
|
|
|
table when we have opened a part of the tables, in which case mysqld
|
|
|
|
closes and reopens the tables and tries to get the same locks at last
|
2006-12-19 03:08:38 +01:00
|
|
|
time). In the future we will probably try to remove this.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
Called from lock.cc by get_lock_data().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
@note
|
|
|
|
In this method one should NEVER rely on table->in_use, it may, in fact,
|
|
|
|
refer to a different thread! (this happens if get_lock_data() is called
|
|
|
|
from mysql_lock_abort_for_thread() function)
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@see
|
|
|
|
get_lock_data() in lock.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
THR_LOCK_DATA **ha_example::store_lock(THD *thd,
|
|
|
|
THR_LOCK_DATA **to,
|
|
|
|
enum thr_lock_type lock_type)
|
|
|
|
{
|
|
|
|
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
|
|
|
|
lock.type=lock_type;
|
|
|
|
*to++= &lock;
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-06-23 21:26:34 +02:00
|
|
|
Used to delete a table. By the time delete_table() has been called all
|
2004-05-12 00:59:20 +02:00
|
|
|
opened references to this table will have been closed (and your globally
|
2006-12-19 03:08:38 +01:00
|
|
|
shared references released). The variable name will just be the name of
|
2004-05-12 00:59:20 +02:00
|
|
|
the table. You will need to remove any files you have created at this point.
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
@details
|
2004-06-07 11:06:33 +02:00
|
|
|
If you do not implement this, the default delete_table() is called from
|
2006-12-19 03:08:38 +01:00
|
|
|
handler.cc and it will delete all files with the file extensions returned
|
2004-06-07 11:06:33 +02:00
|
|
|
by bas_ext().
|
|
|
|
|
2006-12-19 03:08:38 +01:00
|
|
|
Called from handler.cc by delete_table and ha_create_table(). Only used
|
2004-05-12 00:59:20 +02:00
|
|
|
during create if the table_flag HA_DROP_BEFORE_CREATE was specified for
|
|
|
|
the storage engine.
|
2006-12-19 03:08:38 +01:00
|
|
|
|
|
|
|
@see
|
|
|
|
delete_table and ha_create_table() in handler.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::delete_table(const char *name)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_table");
|
2004-04-13 06:01:45 +02:00
|
|
|
/* This is not implemented but we want someone to be able that it works. */
|
|
|
|
DBUG_RETURN(0);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
Renames a table from one name to another via an alter table call.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
2004-06-07 11:06:33 +02:00
|
|
|
If you do not implement this, the default rename_table() is called from
|
2006-12-19 03:08:38 +01:00
|
|
|
handler.cc and it will delete all files with the file extensions returned
|
2004-06-07 11:06:33 +02:00
|
|
|
by bas_ext().
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from sql_table.cc by mysql_rename_table().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
mysql_rename_table() in sql_table.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rename_table(const char * from, const char * to)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rename_table ");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2006-12-19 03:08:38 +01:00
|
|
|
Given a starting key and an ending key, estimate the number of rows that
|
|
|
|
will exist between the two keys.
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
2006-12-19 03:08:38 +01:00
|
|
|
end_key may be empty, in which case determine if start_key matches any rows.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
Called from opt_range.cc by check_quick_keys().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
check_quick_keys() in opt_range.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2004-05-16 13:48:32 +02:00
|
|
|
ha_rows ha_example::records_in_range(uint inx, key_range *min_key,
|
|
|
|
key_range *max_key)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
2004-05-16 13:48:32 +02:00
|
|
|
DBUG_ENTER("ha_example::records_in_range");
|
|
|
|
DBUG_RETURN(10); // low number to force index usage
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief
|
2004-05-12 00:59:20 +02:00
|
|
|
create() is called to create a database. The variable name will have the name
|
2006-12-19 03:08:38 +01:00
|
|
|
of the table.
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@details
|
|
|
|
When create() is called you do not need to worry about
|
|
|
|
opening the table. Also, the .frm file will have already been
|
|
|
|
created so adjusting create_info is not necessary. You can overwrite
|
|
|
|
the .frm file at this point if you wish to change the table
|
|
|
|
definition, but there are no methods currently provided for doing
|
|
|
|
so.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
Called from handle.cc by ha_create_table().
|
2006-12-19 03:08:38 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
@see
|
2006-12-19 03:08:38 +01:00
|
|
|
ha_create_table() in handle.cc
|
2004-05-12 00:59:20 +02:00
|
|
|
*/
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
int ha_example::create(const char *name, TABLE *table_arg,
|
2004-05-12 00:59:20 +02:00
|
|
|
HA_CREATE_INFO *create_info)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::create");
|
2007-01-29 00:47:35 +01:00
|
|
|
/*
|
|
|
|
This is not implemented but we want someone to be able to see that it
|
|
|
|
works.
|
|
|
|
*/
|
2004-04-13 06:01:45 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
|
2006-05-28 14:51:01 +02:00
|
|
|
struct st_mysql_storage_engine example_storage_engine=
|
2006-09-27 06:26:04 +02:00
|
|
|
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2006-04-13 22:49:29 +02:00
|
|
|
mysql_declare_plugin(example)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN,
|
2006-05-28 14:51:01 +02:00
|
|
|
&example_storage_engine,
|
|
|
|
"EXAMPLE",
|
2005-12-21 19:18:40 +01:00
|
|
|
"Brian Aker, MySQL AB",
|
2006-05-28 14:51:01 +02:00
|
|
|
"Example storage engine",
|
2006-10-05 09:41:29 +02:00
|
|
|
PLUGIN_LICENSE_GPL,
|
2007-01-29 00:47:35 +01:00
|
|
|
example_init_func, /* Plugin Init */
|
|
|
|
example_done_func, /* Plugin Deinit */
|
2005-12-21 21:50:50 +01:00
|
|
|
0x0001 /* 0.1 */,
|
2007-01-29 00:47:35 +01:00
|
|
|
NULL, /* status variables */
|
|
|
|
NULL, /* system variables */
|
|
|
|
NULL /* config options */
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
mysql_declare_plugin_end;
|