summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorjonas@eel.(none) <>2005-08-21 16:35:27 +0200
committerjonas@eel.(none) <>2005-08-21 16:35:27 +0200
commita58c0e7dae2374c0f14a59f89b3f2027366b1a8d (patch)
tree410c5fcff79fc5d901a0f88de65b730d1946b084 /sql
parent3aede000a2d7914446e8c30227d0a78b5b2af12f (diff)
parentd9e3ad09e5d2bc72e1457588d4ef80c0d9a75bab (diff)
downloadmariadb-git-a58c0e7dae2374c0f14a59f89b3f2027366b1a8d.tar.gz
Merge joreland@bk-internal.mysql.com:/home/bk/mysql-4.1
into eel.(none):/home/jonas/src/mysql-4.1-push
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc15
-rw-r--r--sql/item.h3
-rw-r--r--sql/log_event.cc2
-rw-r--r--sql/log_event.h2
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/sql_db.cc74
-rw-r--r--sql/sql_prepare.cc9
-rw-r--r--sql/sql_select.cc4
-rw-r--r--sql/sql_table.cc3
-rw-r--r--sql/table.h3
10 files changed, 94 insertions, 23 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 79579eeeb67..2ae56d17b07 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1230,7 +1230,7 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
CHARSET_INFO *tocs= thd->variables.collation_connection;
uint32 dummy_offset;
- value.cs_info.character_set_client= fromcs;
+ value.cs_info.character_set_of_placeholder= fromcs;
/*
Setup source and destination character sets so that they
are different only if conversion is necessary: this will
@@ -1443,7 +1443,7 @@ String *Item_param::val_str(String* str)
and avoid one more memcpy/alloc between str and log string.
*/
-const String *Item_param::query_val_str(String* str, THD *thd) const
+const String *Item_param::query_val_str(String* str) const
{
switch (state) {
case INT_VALUE:
@@ -1482,18 +1482,17 @@ const String *Item_param::query_val_str(String* str, THD *thd) const
buf= str->c_ptr_quick();
ptr= buf;
- if (thd->charset()->escape_with_backslash_is_dangerous)
+ if (value.cs_info.character_set_client->escape_with_backslash_is_dangerous)
{
- ptr= strmov(ptr, "x\'");
- ptr= bare_str_to_hex(ptr, str_value.ptr(), str_value.length());
+ ptr= str_to_hex(ptr, str_value.ptr(), str_value.length());
}
else
{
*ptr++= '\'';
ptr+= escape_string_for_mysql(str_value.charset(), ptr,
str_value.ptr(), str_value.length());
+ *ptr++='\'';
}
- *ptr++='\'';
str->length(ptr - buf);
break;
}
@@ -1523,10 +1522,10 @@ bool Item_param::convert_str_value(THD *thd)
here only if conversion is really necessary.
*/
if (value.cs_info.final_character_set_of_str_value !=
- value.cs_info.character_set_client)
+ value.cs_info.character_set_of_placeholder)
{
rc= thd->convert_string(&str_value,
- value.cs_info.character_set_client,
+ value.cs_info.character_set_of_placeholder,
value.cs_info.final_character_set_of_str_value);
}
else
diff --git a/sql/item.h b/sql/item.h
index ff34dfad025..080b804c730 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -532,6 +532,7 @@ public:
struct CONVERSION_INFO
{
CHARSET_INFO *character_set_client;
+ CHARSET_INFO *character_set_of_placeholder;
/*
This points at character set of connection if conversion
to it is required (i. e. if placeholder typecode is not BLOB).
@@ -591,7 +592,7 @@ public:
*/
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
- const String *query_val_str(String *str, THD *thd) const;
+ const String *query_val_str(String *str) const;
bool convert_str_value(THD *thd);
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 4d260763491..66c732e8cb0 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -207,7 +207,7 @@ static inline int read_str(char * &buf, char *buf_end, char * &str,
/*
Transforms a string into "" or its expression in 0x... form.
*/
-static char *str_to_hex(char *to, char *from, uint len)
+char *str_to_hex(char *to, const char *from, uint len)
{
char *p= to;
if (len)
diff --git a/sql/log_event.h b/sql/log_event.h
index 7ae4e863fc2..5c81d0c92f0 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -1069,5 +1069,5 @@ public:
bool is_valid() { return 1; }
};
#endif
-
+char *str_to_hex(char *to, const char *from, uint len);
#endif /* _log_event_h */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 55995a71980..2e38ec98c08 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -4328,7 +4328,7 @@ Disable with --skip-bdb (will save memory).",
(gptr*) &default_collation_name, (gptr*) &default_collation_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{"default-storage-engine", OPT_STORAGE_ENGINE,
- "Set the default storage engine (table tyoe) for tables.", 0, 0,
+ "Set the default storage engine (table type) for tables.", 0, 0,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default-table-type", OPT_STORAGE_ENGINE,
"(deprecated) Use --default-storage-engine.", 0, 0,
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index ad6845572e1..6dcc7be0904 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -25,14 +25,20 @@
#include <direct.h>
#endif
+#define MAX_DROP_TABLE_Q_LEN 1024
+
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts, NULL};
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
- const char *db, const char *path,
- uint level);
+ const char *db, const char *path, uint level,
+ TABLE_LIST** dropped_tables);
+
+static inline void write_to_binlog(THD* thd, char* query, uint q_len,
+ char* db, uint db_len);
+
/* Database options hash */
static HASH dboptions;
static my_bool dboptions_init= 0;
@@ -57,6 +63,19 @@ static byte* dboptions_get_key(my_dbopt_t *opt, uint *length,
return (byte*) opt->name;
}
+/*
+ Helper function to write a query to binlog used by mysql_rm_db()
+ */
+static inline void write_to_binlog(THD* thd, char* query, uint q_len,
+ char* db, uint db_len)
+{
+ Query_log_event qinfo(thd, query, q_len, 0, 0);
+ qinfo.error_code= 0;
+ qinfo.db= db;
+ qinfo.db_len= db_len;
+ mysql_bin_log.write(&qinfo);
+}
+
/*
Function to free dboptions hash element
@@ -585,6 +604,7 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
char path[FN_REFLEN+16], tmp_db[NAME_LEN+1];
MY_DIR *dirp;
uint length;
+ TABLE_LIST* dropped_tables= 0;
DBUG_ENTER("mysql_rm_db");
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
@@ -621,8 +641,10 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
remove_db_from_cache(db);
pthread_mutex_unlock(&LOCK_open);
+
error= -1;
- if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0)) >= 0)
+ if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0,
+ &dropped_tables)) >= 0)
{
ha_drop_database(path);
query_cache_invalidate1(db);
@@ -672,6 +694,45 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
send_ok(thd, (ulong) deleted);
thd->server_status&= ~SERVER_STATUS_DB_DROPPED;
}
+ else if (mysql_bin_log.is_open())
+ {
+ char* query= thd->alloc(MAX_DROP_TABLE_Q_LEN);
+
+ if (!query)
+ goto exit; /* not much else we can do */
+ char* p= strmov(query,"drop table ");
+ char* p_end= query + MAX_DROP_TABLE_Q_LEN;
+ TABLE_LIST* tbl;
+ bool last_query_needs_write= 0;
+ uint db_len= strlen(db);
+
+ for (tbl= dropped_tables;tbl;tbl= tbl->next)
+ {
+ if (!tbl->was_dropped)
+ continue;
+
+ /* 3 for the quotes and the comma*/
+ uint tbl_name_len= strlen(tbl->real_name) + 3;
+ if (p + tbl_name_len + 1 >= p_end)
+ {
+ *--p= 0; /* kill , */
+ write_to_binlog(thd, query, p - query, db, db_len);
+ p= query + 11; /* reuse the initial "drop table" */
+ }
+
+ *p++ = '`';
+ p= strmov(p,tbl->real_name);
+ *p++ = '`';
+ *p++ = ',';
+ last_query_needs_write= 1;
+ }
+
+ if (last_query_needs_write)
+ {
+ *--p= 0;
+ write_to_binlog(thd, query, p - query, db, db_len);
+ }
+ }
exit:
start_waiting_global_read_lock(thd);
@@ -716,7 +777,7 @@ exit2:
*/
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
- const char *org_path, uint level)
+ const char *org_path, uint level, TABLE_LIST** dropped_tables)
{
long deleted=0;
ulong found_other_files=0;
@@ -758,7 +819,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
if ((new_dirp = my_dir(newpath,MYF(MY_DONT_SORT))))
{
DBUG_PRINT("my",("New subdir found: %s", newpath));
- if ((mysql_rm_known_files(thd, new_dirp, NullS, newpath,1)) < 0)
+ if ((mysql_rm_known_files(thd, new_dirp, NullS, newpath,1,0)) < 0)
goto err;
if (!(copy_of_path= thd->memdup(newpath, length+1)) ||
!(dir= new (thd->mem_root) String(copy_of_path, length,
@@ -818,6 +879,9 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
}
my_dirend(dirp);
+ if (dropped_tables)
+ *dropped_tables= tot_list;
+
/*
If the directory is a symbolic link, remove the link first, then
remove the directory the symbolic link pointed at
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index d0c06a3eaf7..8a50d0bd50e 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -528,7 +528,9 @@ static void setup_one_conversion_function(THD *thd, Item_param *param,
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
param->set_param_func= set_param_str;
- param->value.cs_info.character_set_client= &my_charset_bin;
+ param->value.cs_info.character_set_of_placeholder= &my_charset_bin;
+ param->value.cs_info.character_set_client=
+ thd->variables.character_set_client;
param->value.cs_info.final_character_set_of_str_value= &my_charset_bin;
param->item_type= Item::STRING_ITEM;
param->item_result_type= STRING_RESULT;
@@ -544,6 +546,7 @@ static void setup_one_conversion_function(THD *thd, Item_param *param,
CHARSET_INFO *tocs= thd->variables.collation_connection;
uint32 dummy_offset;
+ param->value.cs_info.character_set_of_placeholder= fromcs;
param->value.cs_info.character_set_client= fromcs;
/*
@@ -601,7 +604,7 @@ static bool insert_params_withlog(Prepared_statement *stmt, uchar *null_array,
param->set_param_func(param, &read_pos, data_end - read_pos);
}
}
- res= param->query_val_str(&str, thd);
+ res= param->query_val_str(&str);
if (param->convert_str_value(thd))
DBUG_RETURN(1); /* out of memory */
@@ -749,7 +752,7 @@ static bool emb_insert_params_withlog(Prepared_statement *stmt, String *query)
client_param->buffer_length);
}
}
- res= param->query_val_str(&str, thd);
+ res= param->query_val_str(&str);
if (param->convert_str_value(thd))
DBUG_RETURN(1); /* out of memory */
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9984cb4138f..3b67af8eea7 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8517,9 +8517,7 @@ create_distinct_group(THD *thd, Item **ref_pointer_array,
li.rewind();
while ((item=li++))
{
- if (item->const_item() || item->with_sum_func)
- continue;
- if (!item->marker)
+ if (!item->const_item() && !item->with_sum_func && !item->marker)
{
ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER));
if (!ord)
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 87b864c73fa..80ac9e007b9 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -220,6 +220,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
for (table=tables ; table ; table=table->next)
{
char *db=table->db;
+ table->was_dropped= 0;
mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL);
if (!close_temporary_table(thd, db, table->real_name))
{
@@ -280,6 +281,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
wrong_tables.append(',');
wrong_tables.append(String(table->real_name,system_charset_info));
}
+ else
+ table->was_dropped= 1;
}
thd->tmp_table_used= tmp_table_deleted;
error= 0;
diff --git a/sql/table.h b/sql/table.h
index 77153e5d8cd..fb742acf804 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -235,6 +235,9 @@ typedef struct st_table_list
bool cacheable_table; /* stop PS caching */
/* used in multi-upd privelege check */
bool table_in_update_from_clause;
+
+ /* used for proper partially successful DROP DATABASE binlogging */
+ bool was_dropped;
} TABLE_LIST;
typedef struct st_changed_table_list