Commit 6016f23f authored by unknown's avatar unknown

WL# 2094

This patch contains all that my previous patch (1.1814) contained, with the addition of using cli_fetch_lengths for
handling binary data (Bar noted this on the review of 1.1814, Guilhem suggested using cli_fetch_lenghts by 
making available via removal of static in method definition and declaration in mysql.h, but
Konstantin had some reservations, but he said to commit the patch using this anyway,
and I suppose this can be discussed. I abandoned 1.1814 because Monty made a couple
fixes to my code as well as formatting changes, and I thought it would just be easier
to hand-edit my changes into a fresh clone and then make a patch. 

The reason for using cli_fetch_lengths is so that I can correctly get the length of
the field I am setting into the field. I was previously using 'strlen' but Bar pointed out this
won't correctly get the length of binary data and is also less effecient. Upon testing,
it was in fact verified that binary data in a blob table was being inserted correctly,
but not being retrieved correctly, all due to not having the correct value for the
field:

(*field)->store(row[x], strlen(row[x]), &my_charset_bin);

was changed to:

(*field)->store(row[x], lengths[x], &my_charset_bin);

lengths being a unsigned long pointer to the values of the field lengths from a 
MYSQL_ROW.

Since the server doesn't have the function "mysql_fetch_lengths" available, I tried 
to use "result->lengths", but this isn't set, so I finally successfully used 
cli_fetch_lenghts, which does give the correct lengths, and now the binary data gets
retrieved correctly.

I've also run the code through indent-ex and am using Brian's vimrc to ensure correct formatting!

This code passes the entire test suite, without any errors or warning on both my 
workstation and build.mysql.com


include/mysql.h:
  added cli_fetch_lengths to mysql.h in order to use this function in the federated handler
mysql-test/r/federated.result:
  - Moved countries to be created and inserted prior to federated test table
  - Added a test of inserting binary values into a blob table
mysql-test/t/federated.test:
  - Moved order of countries table creation to prior to test table creation
  - Test insertion of binary values in a blob table
sql-common/client.c:
  removed 'static' to allow cli_fetch_lengths to be used in the federated handler
sql/ha_federated.cc:
  1. share->scheme that was created in parse_url was not being freed
  2. HASH federated_open_tables was being deleted, but not freed
  3. 'result' from mysql_store_result was not being free in several instances
  4. Fixed the problem where a table scan was being performed after
  index_read_idx, which didn't cause a problem because the result set from
  idx_read_idx was not being freed, but once the result set was properly freed,
  it broke update_row. Now, I'm using the bool 'scan' to determine if I need to
  perform a table scan, which it magically is false when the query is an update
  with an index.
  5. Changed all stings containing the query to perform in mysql_real_query
  calls from string.c_ptr_quick() to string.ptr() per Monty's suggestion
  (better performance)
  6. Fixed various cast/type/truth compile warnings.
  7. Removed 'load_conn_info' and just let 'parse_url' handle it.
  8. Added the use of cli_fetch_lengths, needed to fix binary values being retrieved 
  from the database in rnd_next/convert_row_to_internal_format
  9. Formatting changes by using indent-ex!
sql/ha_federated.h:
  added scan flag, setting defaults for result and scan_flag
parent 2c0acb32
...@@ -499,6 +499,8 @@ MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, ...@@ -499,6 +499,8 @@ MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
MYSQL_FIELD_OFFSET offset); MYSQL_FIELD_OFFSET offset);
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
void STDCALL cli_fetch_lengths(ulong *to, MYSQL_ROW column,
unsigned int field_count);
MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
const char *wild); const char *wild);
......
...@@ -644,14 +644,19 @@ select * from federated.t1 where fileguts = 'jimbob'; ...@@ -644,14 +644,19 @@ select * from federated.t1 where fileguts = 'jimbob';
id code fileguts creation_date entered_time id code fileguts creation_date entered_time
3 DEUEUEUEUEUEUEUEUEU jimbob 2004-04-04 04:04:04 2004-04-04 04:04:04 3 DEUEUEUEUEUEUEUEUEU jimbob 2004-04-04 04:04:04 2004-04-04 04:04:04
drop table if exists federated.t1; drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id)); CREATE TABLE federated.t1 (a BLOB);
drop table if exists federated.t1; drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id) ) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 COMMENT='mysql://root@127.0.0.1:9308/federated/t1'; CREATE TABLE federated.t1 (a BLOB) ENGINE="FEDERATED" COMMENT='mysql://root@127.0.0.1:9308/federated/t1';
insert into federated.t1 (name, country_id, other) values ('Kumar', 1, 11111); INSERT INTO federated.t1 VALUES (0x00);
insert into federated.t1 (name, country_id, other) values ('Lenz', 2, 22222); INSERT INTO federated.t1 VALUES (0x0001);
insert into federated.t1 (name, country_id, other) values ('Marizio', 3, 33333); INSERT INTO federated.t1 VALUES (0x0100);
insert into federated.t1 (name, country_id, other) values ('Monty', 4, 33333); SELECT HEX(a) FROM federated.t1;
insert into federated.t1 (name, country_id, other) values ('Sanja', 5, 33333); HEX(a)
00
0001
0100
drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id));
drop table if exists federated.countries; drop table if exists federated.countries;
Warnings: Warnings:
Note 1051 Unknown table 'countries' Note 1051 Unknown table 'countries'
...@@ -661,6 +666,13 @@ insert into federated.countries (country) values ('Germany'); ...@@ -661,6 +666,13 @@ insert into federated.countries (country) values ('Germany');
insert into federated.countries (country) values ('Italy'); insert into federated.countries (country) values ('Italy');
insert into federated.countries (country) values ('Finland'); insert into federated.countries (country) values ('Finland');
insert into federated.countries (country) values ('Ukraine'); insert into federated.countries (country) values ('Ukraine');
drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id) ) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 COMMENT='mysql://root@127.0.0.1:9308/federated/t1';
insert into federated.t1 (name, country_id, other) values ('Kumar', 1, 11111);
insert into federated.t1 (name, country_id, other) values ('Lenz', 2, 22222);
insert into federated.t1 (name, country_id, other) values ('Marizio', 3, 33333);
insert into federated.t1 (name, country_id, other) values ('Monty', 4, 33333);
insert into federated.t1 (name, country_id, other) values ('Sanja', 5, 33333);
select federated.t1.*, federated.countries.country from federated.t1 left join federated.countries on federated.t1.country_id = federated.countries.id; select federated.t1.*, federated.countries.country from federated.t1 left join federated.countries on federated.t1.country_id = federated.countries.id;
id country_id name other country id country_id name other country
1 1 Kumar 11111 India 1 1 Kumar 11111 India
......
...@@ -522,8 +522,22 @@ insert into federated.t1 (code, fileguts, creation_date) values ('ASDFWERQWETWET ...@@ -522,8 +522,22 @@ insert into federated.t1 (code, fileguts, creation_date) values ('ASDFWERQWETWET
insert into federated.t1 (code, fileguts, creation_date) values ('DEUEUEUEUEUEUEUEUEU', '*()w*09*$()*#)(*09*^90*d)(*s()d8g)(s*ned)(*)(s*d)(*hn(d*)(*sbn)D((#$*(#*%%&#&^$#&#&#&#&^&#*&*#$*&^*(&#(&Q*&&(*!&!(*&*(#&*(%&#<S-F8>*<S-F8><S-F8><S-F8>#<S-F8>#<S-F8>#<S-F8>[[', '2004-04-04 04:04:04'); insert into federated.t1 (code, fileguts, creation_date) values ('DEUEUEUEUEUEUEUEUEU', '*()w*09*$()*#)(*09*^90*d)(*s()d8g)(s*ned)(*)(s*d)(*hn(d*)(*sbn)D((#$*(#*%%&#&^$#&#&#&#&^&#*&*#$*&^*(&#(&Q*&&(*!&!(*&*(#&*(%&#<S-F8>*<S-F8><S-F8><S-F8>#<S-F8>#<S-F8>#<S-F8>[[', '2004-04-04 04:04:04');
insert into federated.t1 (code, fileguts, creation_date) values ('DEUEUEUEUEUEUEUEUEU', 'jimbob', '2004-04-04 04:04:04'); insert into federated.t1 (code, fileguts, creation_date) values ('DEUEUEUEUEUEUEUEUEU', 'jimbob', '2004-04-04 04:04:04');
select * from federated.t1; select * from federated.t1;
select * from federated.t1 where fileguts = 'jimbob';
# test blob indexes # test blob indexes
select * from federated.t1 where fileguts = 'jimbob';
# test blob with binary
connection slave;
drop table if exists federated.t1;
CREATE TABLE federated.t1 (a BLOB);
connection master;
drop table if exists federated.t1;
CREATE TABLE federated.t1 (a BLOB) ENGINE="FEDERATED" COMMENT='mysql://root@127.0.0.1:9308/federated/t1';
INSERT INTO federated.t1 VALUES (0x00);
INSERT INTO federated.t1 VALUES (0x0001);
INSERT INTO federated.t1 VALUES (0x0100);
SELECT HEX(a) FROM federated.t1;
# TODO # TODO
# #
...@@ -559,15 +573,6 @@ drop table if exists federated.t1; ...@@ -559,15 +573,6 @@ drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id)); CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id));
connection master; connection master;
drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id) ) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 COMMENT='mysql://root@127.0.0.1:9308/federated/t1';
insert into federated.t1 (name, country_id, other) values ('Kumar', 1, 11111);
insert into federated.t1 (name, country_id, other) values ('Lenz', 2, 22222);
insert into federated.t1 (name, country_id, other) values ('Marizio', 3, 33333);
insert into federated.t1 (name, country_id, other) values ('Monty', 4, 33333);
insert into federated.t1 (name, country_id, other) values ('Sanja', 5, 33333);
drop table if exists federated.countries; drop table if exists federated.countries;
CREATE TABLE federated.countries ( `id` int(20) NOT NULL auto_increment, `country` varchar(32), primary key (id)); CREATE TABLE federated.countries ( `id` int(20) NOT NULL auto_increment, `country` varchar(32), primary key (id));
insert into federated.countries (country) values ('India'); insert into federated.countries (country) values ('India');
...@@ -576,6 +581,14 @@ insert into federated.countries (country) values ('Italy'); ...@@ -576,6 +581,14 @@ insert into federated.countries (country) values ('Italy');
insert into federated.countries (country) values ('Finland'); insert into federated.countries (country) values ('Finland');
insert into federated.countries (country) values ('Ukraine'); insert into federated.countries (country) values ('Ukraine');
drop table if exists federated.t1;
CREATE TABLE federated.t1 ( `id` int(20) NOT NULL auto_increment, `country_id` int(20) NOT NULL DEFAULT 0, `name` varchar(32), `other` varchar(20), PRIMARY KEY (`id`), key (country_id) ) ENGINE="FEDERATED" DEFAULT CHARSET=latin1 COMMENT='mysql://root@127.0.0.1:9308/federated/t1';
insert into federated.t1 (name, country_id, other) values ('Kumar', 1, 11111);
insert into federated.t1 (name, country_id, other) values ('Lenz', 2, 22222);
insert into federated.t1 (name, country_id, other) values ('Marizio', 3, 33333);
insert into federated.t1 (name, country_id, other) values ('Monty', 4, 33333);
insert into federated.t1 (name, country_id, other) values ('Sanja', 5, 33333);
select federated.t1.*, federated.countries.country from federated.t1 left join federated.countries on federated.t1.country_id = federated.countries.id; select federated.t1.*, federated.countries.country from federated.t1 left join federated.countries on federated.t1.country_id = federated.countries.id;
drop table federated.countries; drop table federated.countries;
......
...@@ -1121,7 +1121,7 @@ void mysql_read_default_options(struct st_mysql_options *options, ...@@ -1121,7 +1121,7 @@ void mysql_read_default_options(struct st_mysql_options *options,
else the lengths are calculated from the offset between pointers. else the lengths are calculated from the offset between pointers.
**************************************************************************/ **************************************************************************/
static void cli_fetch_lengths(ulong *to, MYSQL_ROW column, void cli_fetch_lengths(ulong *to, MYSQL_ROW column,
unsigned int field_count) unsigned int field_count)
{ {
ulong *prev_length; ulong *prev_length;
......
This diff is collapsed.
...@@ -62,6 +62,7 @@ class ha_federated: public handler ...@@ -62,6 +62,7 @@ class ha_federated: public handler
FEDERATED_SHARE *share; /* Shared lock info */ FEDERATED_SHARE *share; /* Shared lock info */
MYSQL *mysql; MYSQL *mysql;
MYSQL_RES *result; MYSQL_RES *result;
bool scan_flag;
uint ref_length; uint ref_length;
uint fetch_num; // stores the fetch num uint fetch_num; // stores the fetch num
MYSQL_ROW_OFFSET current_position; // Current position used by ::position() MYSQL_ROW_OFFSET current_position; // Current position used by ::position()
...@@ -76,7 +77,7 @@ private: ...@@ -76,7 +77,7 @@ private:
public: public:
ha_federated(TABLE *table): handler(table), ha_federated(TABLE *table): handler(table),
mysql(0), mysql(0), result(0), scan_flag(0),
ref_length(sizeof(MYSQL_ROW_OFFSET)), current_position(0) ref_length(sizeof(MYSQL_ROW_OFFSET)), current_position(0)
{ {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment