File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Original file line number Diff line number Diff line change @@ -1037,15 +1037,39 @@ _mysql_ResultObject_describe(
1037
1037
{
1038
1038
PyObject * d ;
1039
1039
MYSQL_FIELD * fields ;
1040
+ MY_CHARSET_INFO cs ;
1041
+ int isutf8 = 0 ;
1040
1042
unsigned int i , n ;
1043
+
1041
1044
check_result_connection (self );
1045
+
1046
+ mysql_get_character_set_info (& result_connection (self )-> connection , & cs );
1047
+ if (strncmp ("utf8" , cs .name , 4 ) == 0 ) { // utf8, utf8mb3, utf8mb4
1048
+ isutf8 = 1 ;
1049
+ }
1050
+
1042
1051
n = mysql_num_fields (self -> result );
1043
1052
fields = mysql_fetch_fields (self -> result );
1044
1053
if (!(d = PyTuple_New (n ))) return NULL ;
1045
1054
for (i = 0 ; i < n ; i ++ ) {
1046
1055
PyObject * t ;
1056
+ #ifdef IS_PY3K
1057
+ PyObject * name ;
1058
+ if (isutf8 ) {
1059
+ name = PyUnicode_DecodeUTF8 (fields [i ].name , fields [i ].name_length , "replace" );
1060
+ } else {
1061
+ name = PyUnicode_Decode (fields [i ].name , fields [i ].name_length , cs .name , "replace" );
1062
+ }
1063
+ if (name == NULL ) {
1064
+ goto error ;
1065
+ }
1066
+
1067
+ t = Py_BuildValue ("(Niiiiii)" ,
1068
+ name ,
1069
+ #else
1047
1070
t = Py_BuildValue ("(siiiiii)" ,
1048
1071
fields [i ].name ,
1072
+ #endif
1049
1073
(long ) fields [i ].type ,
1050
1074
(long ) fields [i ].max_length ,
1051
1075
(long ) fields [i ].length ,
You can’t perform that action at this time.
0 commit comments