--- mysql-4.0.orig/client/client_priv.h	2004-12-14 19:27:18.000000000 +0900
+++ mysql-4.0.23/client/client_priv.h	2005-01-19 18:38:52.000000000 +0900
@@ -39,4 +39,4 @@
                OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT, OPT_LOCAL_INFILE,
 	       OPT_DELETE_MASTER_LOGS,
                OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION, OPT_FRM,
-               OPT_HEXBLOB };
+               OPT_HEXBLOB, OPT_HEXCHAR, OPT_CSV };
--- mysql-4.0.orig/client/mysqldump.c	2004-12-14 19:27:18.000000000 +0900
+++ mysql-4.0.23/client/mysqldump.c	2005-01-19 18:41:46.000000000 +0900
@@ -79,7 +79,7 @@
   opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0,
   opt_delete_master_logs=0, tty_password=0,
   opt_single_transaction=0, opt_comments= 0,
-  opt_hex_blob;
+  opt_hex_blob=0, opt_hex_char=0, opt_csv=0;
 static ulong opt_max_allowed_packet, opt_net_buffer_length;
 static MYSQL  mysql_connection,*sock=0;
 static char  insert_pat[12 * 1024],*opt_password=0,*current_user=0,
@@ -144,6 +144,8 @@
    "Allows utilization of the new, much faster INSERT syntax.",
    (gptr*) &extended_insert, (gptr*) &extended_insert, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
+  {"csv", OPT_CSV, "same as --fields-terminated-by=',' --fields-optionally-enclosed-by='\"' --lines-terminated-by='\\r\\n' ",
+   (gptr*) &opt_csv, (gptr*) &opt_csv, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"fields-terminated-by", OPT_FTB,
    "Fields in the textfile are terminated by ...", (gptr*) &fields_terminated,
    (gptr*) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -169,9 +171,12 @@
    0, 0, 0, 0, 0, 0},
   {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"hex-blob", OPT_HEXBLOB, "Dump binary strings (CHAR BINARY, "
-    "VARCHAR BINARY, BLOB) in hexadecimal format.",
+  {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BLOB) "
+    "in hexadecimal format.",
    (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"hex-char", OPT_HEXCHAR, "Dump binary strings (CHAR BINARY, "
+    "VARCHAR BINARY) in hexadecimal format.",
+   (gptr*) &opt_hex_char, (gptr*) &opt_hex_char, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"host", 'h', "Connect to host.", (gptr*) &current_host,
    (gptr*) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
@@ -425,6 +430,11 @@
 
   if (opt_delayed)
     opt_lock=0;				/* Can't have lock with delayed */
+
+  if (opt_csv) { /* by sakaik */
+    fields_terminated = ","; opt_enclosed = "\""; lines_terminated = "\\r\\n";
+  }
+
   if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
 		fields_terminated))
   {
@@ -1119,12 +1129,18 @@
 	}
 	
         is_blob= (opt_hex_blob && (field->flags & BINARY_FLAG) &&
-                  (field->type == FIELD_TYPE_STRING ||
-                   field->type == FIELD_TYPE_VAR_STRING ||
+                  (
                    field->type == FIELD_TYPE_BLOB ||
                    field->type == FIELD_TYPE_LONG_BLOB ||
                    field->type == FIELD_TYPE_MEDIUM_BLOB ||
                    field->type == FIELD_TYPE_TINY_BLOB)) ? 1 : 0;
+
+        if (opt_hex_char && (field->flags & BINARY_FLAG) &&
+                  (field->type == FIELD_TYPE_STRING ||
+                   field->type == FIELD_TYPE_VAR_STRING) ) {
+	  is_blob = 1;
+	}
+
 	if (extended_insert)
 	{
 	  ulong length = lengths[i];
@@ -1152,9 +1168,9 @@
 		  error= EX_EOM;
 		  goto err;
 		}
-                if (opt_hex_blob && is_blob)
+                if ( (opt_hex_blob || opt_hex_char) && is_blob)
                 {
-                  dynstr_append(&extended_row, "0x");
+                  if (extended_row.length > 0) { dynstr_append(&extended_row, "0x"); }
                   extended_row.length+= mysql_hex_string(extended_row.str + 
                                                          extended_row.length,
                                                          row[i], length);
@@ -1212,12 +1228,12 @@
 	      if (opt_xml)
 		print_quoted_xml(md_result_file, field->name, row[i],
 				 lengths[i]);
-	      else if (opt_hex_blob && is_blob)
+	      else if ( (opt_hex_blob || opt_hex_char) && is_blob)
               { /* sakaik got this idea. */
                 ulong counter;
                 char xx[4];
                 unsigned char *ptr= row[i];
-                fputs("0x", md_result_file);
+                if (lengths[i] > 0) { fputs("0x", md_result_file); }
                 for (counter = 0; counter < lengths[i]; counter++)
                 {
                   sprintf(xx, "%02X", ptr[counter]);
