From 58f4917086863aaee5451c92c0e7c3d5b3603e63 Mon Sep 17 00:00:00 2001
From: unknown <serg@serg.mylan>
Date: Mon, 28 Jul 2003 16:58:52 +0200
Subject: [PATCH] bugs #701 and #783 - old .frm files were read in incorrectly
 in 4.1 (each field was assigned a charset, BLOBs were converted to TEXT)

---
 sql/field.h  |  5 +++--
 sql/table.cc | 10 ++++------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/sql/field.h b/sql/field.h
index 5df7d554c35..79c45a99a43 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1132,7 +1132,7 @@ bool test_if_int(const char *str, int length, const char *int_end,
 */
 
 #define FIELDFLAG_DECIMAL		1
-#define FIELDFLAG_BINARY		1	// Shares same flag 
+#define FIELDFLAG_BINARY		1	// Shares same flag
 #define FIELDFLAG_NUMBER		2
 #define FIELDFLAG_ZEROFILL		4
 #define FIELDFLAG_PACK			120	// Bits used for packing
@@ -1163,7 +1163,8 @@ bool test_if_int(const char *str, int length, const char *int_end,
 #define f_packtype(x)		(((x) >> FIELDFLAG_PACK_SHIFT) & 15)
 #define f_decimals(x)		((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
 #define f_is_alpha(x)		(!f_is_num(x))
-#define f_is_enum(x)	((x) & FIELDFLAG_INTERVAL)
+#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
+#define f_is_enum(x)            ((x) & FIELDFLAG_INTERVAL)
 #define f_is_bitfield(x)	((x) & FIELDFLAG_BITFIELD)
 #define f_is_blob(x)		(((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
 #define f_is_geom(x)		((x) & FIELDFLAG_GEOM)
diff --git a/sql/table.cc b/sql/table.cc
index 0fc2a09f749..1cee0587f17 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -138,7 +138,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
     outparam->raid_chunks= head[42];
     outparam->raid_chunksize= uint4korr(head+43);
     if (!(outparam->table_charset=get_charset((uint) head[38],MYF(0))))
-      outparam->table_charset=NULL; // QQ display error message?
+      outparam->table_charset=default_charset_info; // QQ display error message?
     null_field_first=1;
   }
   outparam->db_record_offset=1;
@@ -398,8 +398,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
 	if (!strpos[14])
 	  charset= &my_charset_bin;
 	else if (!(charset=get_charset((uint) strpos[14], MYF(0))))
-	  charset= (outparam->table_charset ? outparam->table_charset: 
-		  default_charset_info);
+	  charset= outparam->table_charset;
       }
       if (!comment_length)
       {
@@ -423,8 +422,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
 
       /* old frm file */
       field_type= (enum_field_types) f_packtype(pack_flag);
-      charset=(outparam->table_charset ? outparam->table_charset :
-	       default_charset_info);
+      charset=f_is_binary(pack_flag) ? &my_charset_bin : outparam->table_charset;
       bzero((char*) &comment, sizeof(comment));
     }
     *field_ptr=reg_field=
@@ -599,7 +597,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
       }
       keyinfo->usable_key_parts=usable_parts; // Filesort
     }
-    if (primary_key < MAX_KEY && 
+    if (primary_key < MAX_KEY &&
 	(outparam->keys_in_use & ((key_map) 1 << primary_key)))
     {
       outparam->primary_key=primary_key;
-- 
2.30.9