@@ -1074,6 +1074,9 @@ _mysql_escape_string(
1074
1074
len = mysql_escape_string (out , in , size );
1075
1075
#else
1076
1076
check_server_init (NULL );
1077
+
1078
+ if (PyModule_Check ((PyObject * )self ))
1079
+ self = NULL ;
1077
1080
if (self && self -> open )
1078
1081
len = mysql_real_escape_string (& (self -> connection ), out , in , size );
1079
1082
else
@@ -1101,21 +1104,31 @@ _mysql_string_literal(
1101
1104
PyObject * str , * s , * o , * d ;
1102
1105
char * in , * out ;
1103
1106
int len , size ;
1107
+ if (PyModule_Check ((PyObject * )self ))
1108
+ self = NULL ;
1104
1109
if (!PyArg_ParseTuple (args , "O|O:string_literal" , & o , & d )) return NULL ;
1105
- s = PyObject_Str (o );
1106
- if (!s ) return NULL ;
1110
+ if (PyBytes_Check (o )) {
1111
+ s = o ;
1112
+ Py_INCREF (s );
1113
+ } else {
1114
+ s = PyObject_Str (o );
1115
+ if (!s ) return NULL ;
1107
1116
#ifdef IS_PY3K
1108
- {
1109
- PyObject * t = PyUnicode_AsASCIIString (s );
1110
- if (! t ) return NULL ;
1111
- Py_DECREF ( s ) ;
1112
- s = t ;
1113
- }
1117
+ {
1118
+ PyObject * t = PyUnicode_AsASCIIString (s );
1119
+ Py_DECREF ( s ) ;
1120
+ if (! t ) return NULL ;
1121
+ s = t ;
1122
+ }
1114
1123
#endif
1124
+ }
1115
1125
in = PyBytes_AsString (s );
1116
1126
size = PyBytes_GET_SIZE (s );
1117
1127
str = PyBytes_FromStringAndSize ((char * ) NULL , size * 2 + 3 );
1118
- if (!str ) return PyErr_NoMemory ();
1128
+ if (!str ) {
1129
+ Py_DECREF (s );
1130
+ return PyErr_NoMemory ();
1131
+ }
1119
1132
out = PyBytes_AS_STRING (str );
1120
1133
#if MYSQL_VERSION_ID < 32321
1121
1134
len = mysql_escape_string (out + 1 , in , size );
@@ -1336,7 +1349,11 @@ _mysql_field_to_python(
1336
1349
if (rowitem ) {
1337
1350
if (converter != Py_None ) {
1338
1351
v = PyObject_CallFunction (converter ,
1352
+ #ifdef IS_PY3K
1353
+ "y#" ,
1354
+ #else
1339
1355
"s#" ,
1356
+ #endif
1340
1357
rowitem ,
1341
1358
(int )length );
1342
1359
} else {
0 commit comments