diff options
author | unknown <patg@patrick-galbraiths-computer.local> | 2005-01-24 11:31:21 -0800 |
---|---|---|
committer | unknown <patg@patrick-galbraiths-computer.local> | 2005-01-24 11:31:21 -0800 |
commit | 409ddae4b86cbdfc42c2cae84825fb4d2e7c2fcb (patch) | |
tree | 0c9d35930306684c5d665082289e9ad4bb9e98c0 /sql/ha_federated.cc | |
parent | 7d358a015f0bd1cefdabce0ef796569239690053 (diff) | |
parent | 66b62e051930dbcd9dc1d38f0cac574692932834 (diff) | |
download | mariadb-git-409ddae4b86cbdfc42c2cae84825fb4d2e7c2fcb.tar.gz |
Merge pgalbraith@bk-internal.mysql.com:/home/bk/mysql-5.0
into patrick-galbraiths-computer.local:/Users/patg/mysql-5.0
BitKeeper/etc/logging_ok:
auto-union
sql/field.cc:
Auto merged
sql/field.h:
Auto merged
sql/ha_federated.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/set_var.cc:
Auto merged
Diffstat (limited to 'sql/ha_federated.cc')
-rw-r--r-- | sql/ha_federated.cc | 269 |
1 files changed, 132 insertions, 137 deletions
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index ea8633febe6..1f7c089d60a 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -123,8 +123,8 @@ ha_federated::write_row <for every field/column> - ha_federated::quote_data - ha_federated::quote_data + Field::quote_data + Field::quote_data </for every field/column> ha_federated::reset @@ -136,18 +136,18 @@ ha_federated::index_init ha_federated::index_read ha_federated::index_read_idx - ha_federated::quote_data + Field::quote_data ha_federated::rnd_next ha_federated::convert_row_to_internal_format ha_federated::update_row <quote 3 cols, new and old data> - <ha_federated::quote_data - <ha_federated::quote_data - <ha_federated::quote_data - <ha_federated::quote_data - <ha_federated::quote_data - <ha_federated::quote_data + Field::quote_data + Field::quote_data + Field::quote_data + Field::quote_data + Field::quote_data + Field::quote_data </quote 3 cols, new and old data> ha_federated::extra @@ -586,126 +586,116 @@ uint ha_federated::convert_row_to_internal_format(byte *record, MYSQL_ROW row) DBUG_RETURN(0); } -/* - SYNOPSIS - quote_data() - unquoted_string Pointer pointing to the value of a field - field MySQL Field pointer to field being checked for type - - DESCRIPTION - Simple method that passes the field type to the method "type_quote" - To get a true/false value as to whether the value in string1 needs - to be enclosed with quotes. This ensures that values in the final - sql statement to be passed to the remote server will be quoted properly - - RETURN_VALUE - void Immediately - if string doesn't need quote - void Upon prepending/appending quotes on each side of variable - -*/ -void ha_federated::quote_data(String *unquoted_string, Field *field ) +bool ha_federated::create_where_from_key( + String *to, + KEY *key_info, + const byte *key, + uint key_length + ) { - char escaped_string[IO_SIZE]; - char *unquoted_string_buffer; - - unquoted_string_buffer= unquoted_string->c_ptr_quick(); - - int quote_flag; - DBUG_ENTER("ha_federated::quote_data"); - // this is the same call that mysql_real_escape_string() calls - escape_string_for_mysql(&my_charset_bin, (char *)escaped_string, - unquoted_string->c_ptr_quick(), unquoted_string->length()); - - DBUG_PRINT("ha_federated::quote_data", - ("escape_string_for_mysql unescaped %s escaped %s", - unquoted_string->c_ptr_quick(), escaped_string)); - - if (field->is_null()) - { - DBUG_PRINT("ha_federated::quote_data", - ("NULL, no quoted needed for unquoted_string %s, returning.", - unquoted_string->c_ptr_quick())); - DBUG_VOID_RETURN; - } + uint second_loop= 0; + KEY_PART_INFO *key_part; + bool needs_quotes; - quote_flag= type_quote(field->type()); - - if (quote_flag == 0) - { - DBUG_PRINT("ha_federated::quote_data", - ("quote flag 0 no quoted needed for unquoted_string %s, returning.", - unquoted_string->c_ptr_quick())); - DBUG_VOID_RETURN; - } - else + DBUG_ENTER("ha_federated::create_where_from_key"); + for (key_part= key_info->key_part ; (int) key_length > 0 ; key_part++) { - // reset string, then re-append with quotes and escaped values - unquoted_string->length(0); - unquoted_string->append("'"); - unquoted_string->append((char *)escaped_string); - unquoted_string->append("'"); - } - DBUG_PRINT("ha_federated::quote_data", - ("FINAL quote_flag %d unquoted_string %s escaped_string %s", - quote_flag, unquoted_string->c_ptr_quick(), escaped_string)); - DBUG_VOID_RETURN; -} - -/* - Quote a field type if needed + Field *field= key_part->field; + needs_quotes= field->needs_quotes(); + //bool needs_quotes= type_quote(field->type()); + DBUG_PRINT("ha_federated::create_where_from_key", ("key name %s type %d", field->field_name, field->type())); + uint length= key_part->length; + + if (second_loop++ && to->append(" AND ",5)) + DBUG_RETURN(1); + if (to->append('`') || to->append(field->field_name) || + to->append("` ",2)) + DBUG_RETURN(1); // Out of memory + + if (key_part->null_bit) + { + if (*key++) + { + if (to->append("IS NULL",7)) + DBUG_PRINT("ha_federated::create_where_from_key", ("NULL type %s", to->c_ptr_quick())); + DBUG_RETURN(1); + key_length-= key_part->store_length; + key+= key_part->store_length-1; + continue; + } + key_length--; + } + if (to->append("= ")) + DBUG_RETURN(1); + if (needs_quotes && to->append("'")) + DBUG_RETURN(1); + if (key_part->type == HA_KEYTYPE_BIT) + { + /* This is can be threated as a hex string */ + Field_bit *field= (Field_bit *) (key_part->field); + char buff[64+2], *ptr; + byte *end= (byte *)(key) + length; + + buff[0]='0'; + buff[1]='x'; + for (ptr= buff+2 ; key < end ; key++) + { + uint tmp= (uint) (uchar) *key; + *ptr++=_dig_vec_upper[tmp >> 4]; + *ptr++=_dig_vec_upper[tmp & 15]; + } + if (to->append(buff, (uint) (ptr-buff))) + DBUG_RETURN(1); - SYNOPSIS - ha_federated::type_quote - int field Enumerated field type number + DBUG_PRINT("ha_federated::create_where_from_key", ("bit type %s", to->c_ptr_quick())); + key_length-= length; + continue; + } + if (key_part->key_part_flag & HA_BLOB_PART) + { + uint blob_length= uint2korr(key); + key+= HA_KEY_BLOB_LENGTH; + key_length-= HA_KEY_BLOB_LENGTH; + if (append_escaped(to, (char *)(key), blob_length)) + DBUG_RETURN(1); + + DBUG_PRINT("ha_federated::create_where_from_key", ("blob type %s", to->c_ptr_quick())); + length= key_part->length; + } + else if (key_part->key_part_flag & HA_VAR_LENGTH_PART) + { + length= uint2korr(key); + key+= HA_KEY_BLOB_LENGTH; + if (append_escaped(to, (char *)(key), length)) + DBUG_RETURN(1); - DESCRIPTION - Simple method to give true/false whether a field should be quoted. - Used when constructing INSERT and UPDATE queries to the remote server - see write_row and update_row + DBUG_PRINT("ha_federated::create_where_from_key", ("varchar type %s", to->c_ptr_quick())); + } + else + { + DBUG_PRINT("ha_federated::create_where_from_key", ("else block, unknown type so far")); + char buff[MAX_FIELD_WIDTH]; + String str(buff, sizeof(buff), field->charset()), *res; - RETURN VALUE - 0 if value is of type NOT needing quotes - 1 if value is of type needing quotes -*/ -uint ha_federated::type_quote(int type) -{ - DBUG_ENTER("ha_federated::type_quote"); - DBUG_PRINT("ha_federated::type_quote", ("field type %d", type)); - - switch(type) { - //FIX this is a bug, fix when kernel is fixed - case MYSQL_TYPE_VARCHAR : - case FIELD_TYPE_STRING : - case FIELD_TYPE_VAR_STRING : - case FIELD_TYPE_YEAR : - case FIELD_TYPE_NEWDATE : - case FIELD_TYPE_TIME : - case FIELD_TYPE_TIMESTAMP : - case FIELD_TYPE_DATE : - case FIELD_TYPE_DATETIME : - case FIELD_TYPE_TINY_BLOB : - case FIELD_TYPE_BLOB : - case FIELD_TYPE_MEDIUM_BLOB : - case FIELD_TYPE_LONG_BLOB : - case FIELD_TYPE_GEOMETRY : - DBUG_RETURN(1); + res= field->val_str(&str, (char *)(key)); + if (field->result_type() == STRING_RESULT) + { + if (append_escaped(to, (char *) res->ptr(), res->length())) + DBUG_RETURN(1); + res= field->val_str(&str, (char *)(key)); - case FIELD_TYPE_DECIMAL : - case FIELD_TYPE_TINY : - case FIELD_TYPE_SHORT : - case FIELD_TYPE_INT24 : - case FIELD_TYPE_LONG : - case FIELD_TYPE_FLOAT : - case FIELD_TYPE_DOUBLE : - case FIELD_TYPE_LONGLONG : - case FIELD_TYPE_NULL : - case FIELD_TYPE_SET : - case FIELD_TYPE_ENUM : + DBUG_PRINT("ha_federated::create_where_from_key", ("else block, string type", to->c_ptr_quick())); + } + else if (to->append(res->ptr(), res->length())) + DBUG_RETURN(1); + } + if (needs_quotes && to->append("'")) + DBUG_RETURN(1); + DBUG_PRINT("ha_federated::create_where_from_key", ("final value for 'to' %s", to->c_ptr_quick())); + key+= length; + key_length-= length; DBUG_RETURN(0); - - default: DBUG_RETURN(0); } - DBUG_RETURN(0); } int load_conn_info(FEDERATED_SHARE *share, TABLE *table) @@ -1060,7 +1050,8 @@ int ha_federated::write_row(byte * buf) insert_string.append((*field)->field_name); // quote these fields if they require it - quote_data(&insert_field_value_string, *field); + + (*field)->quote_data(&insert_field_value_string); // append the value values_string.append(insert_field_value_string); insert_field_value_string.length(0); @@ -1068,9 +1059,10 @@ int ha_federated::write_row(byte * buf) // append commas between both fields and fieldnames insert_string.append(','); values_string.append(','); - DBUG_PRINT("ha_federated::write_row", - ("insert_string %s values_string %s insert_field_value_string %s", - insert_string.c_ptr_quick(), values_string.c_ptr_quick(), insert_field_value_string.c_ptr_quick())); + DBUG_PRINT("ha_federated::write_row", + ("insert_string %s values_string %s insert_field_value_string %s", + insert_string.c_ptr_quick(), values_string.c_ptr_quick(), + insert_field_value_string.c_ptr_quick())); } } @@ -1205,7 +1197,7 @@ int ha_federated::update_row( { // otherwise = (*field)->val_str(&new_field_value); - quote_data(&new_field_value, *field); + (*field)->quote_data(&new_field_value); if ( has_a_primary_key ) { @@ -1223,7 +1215,7 @@ int ha_federated::update_row( { (*field)->val_str(&old_field_value, (char *)(old_data + (*field)->offset())); - quote_data(&old_field_value, *field); + (*field)->quote_data(&old_field_value); where_string.append(old_field_value); } } @@ -1235,7 +1227,7 @@ int ha_federated::update_row( { (*field)->val_str(&old_field_value, (char *)(old_data + (*field)->offset())); - quote_data(&old_field_value, *field); + (*field)->quote_data(&old_field_value); where_string.append(old_field_value); } } @@ -1312,7 +1304,7 @@ int ha_federated::delete_row(const byte * buf) { delete_string.append("="); (*field)->val_str(&data_string); - quote_data(&data_string, *field); + (*field)->quote_data(&data_string); } delete_string.append(data_string); @@ -1366,8 +1358,11 @@ int ha_federated::index_read_idx(byte * buf, uint index, const byte * key, __attribute__((unused))) { char index_value[IO_SIZE]; + char key_value[IO_SIZE]; + char test_value[IO_SIZE]; String index_string(index_value, sizeof(index_value), &my_charset_bin); index_string.length(0); + uint keylen; char sql_query_buffer[IO_SIZE]; String sql_query(sql_query_buffer, sizeof(sql_query_buffer), &my_charset_bin); @@ -1376,20 +1371,20 @@ int ha_federated::index_read_idx(byte * buf, uint index, const byte * key, DBUG_ENTER("ha_federated::index_read_idx"); statistic_increment(table->in_use->status_var.ha_read_key_count,&LOCK_status); - index_string.length(0); - sql_query.length(0); - sql_query.append(share->select_query); sql_query.append(" WHERE "); - sql_query.append(table->key_info[index].key_part->field->field_name); - sql_query.append(" = "); - table->key_info[index].key_part->field->val_str(&index_string, (char *)(key)); - quote_data(&index_string, table->key_info[index].key_part->field); + keylen= strlen((char *)(key)); + create_where_from_key(&index_string, &table->key_info[index], key, keylen); sql_query.append(index_string); DBUG_PRINT("ha_federated::index_read_idx", - ("sql_query %s", sql_query.c_ptr_quick())); + ("current key %d key value %s index_string value %s length %d", index, (char *)(key),index_string.c_ptr_quick(), + index_string.length())); + + DBUG_PRINT("ha_federated::index_read_idx", + ("current position %d sql_query %s", current_position, + sql_query.c_ptr_quick())); if (mysql_real_query(mysql, sql_query.c_ptr_quick(), sql_query.length())) { @@ -1540,7 +1535,7 @@ int ha_federated::rnd_pos(byte * buf, byte *pos) { DBUG_ENTER("ha_federated::rnd_pos"); statistic_increment(table->in_use->status_var.ha_read_rnd_count,&LOCK_status); - memcpy(current_position, pos, sizeof(MYSQL_ROW_OFFSET)); // pos is not aligned + memcpy_fixed(¤t_position, pos, sizeof(MYSQL_ROW_OFFSET)); // pos is not aligned result->current_row= 0; result->data_cursor= current_position; DBUG_RETURN(rnd_next(buf)); |