mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
* Added set_character_set(charset) method to database connections
* Added get_character_set_info() method to database connections * Added charset option to database connections * Updated docs, added FAQ * 1.2.1c6
This commit is contained in:
@ -1485,6 +1485,78 @@ _mysql_ConnectionObject_character_set_name(
|
||||
return PyString_FromString(s);
|
||||
}
|
||||
|
||||
#if MYSQL_VERSION_ID >= 50007
|
||||
static char _mysql_ConnectionObject_set_character_set__doc__[] =
|
||||
"Sets the default character set for the current connection.\n\
|
||||
Non-standard.\n\
|
||||
";
|
||||
|
||||
static PyObject *
|
||||
_mysql_ConnectionObject_set_character_set(
|
||||
_mysql_ConnectionObject *self,
|
||||
PyObject *args)
|
||||
{
|
||||
const char *s;
|
||||
int err;
|
||||
if (!PyArg_ParseTuple(args, "s", &s)) return NULL;
|
||||
check_connection(self);
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
err = mysql_set_character_set(&(self->connection), s);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (err) return _mysql_Exception(self);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYSQL_VERSION_ID >= 50010
|
||||
static char _mysql_ConnectionObject_get_character_set_info__doc__[] =
|
||||
"Returns a dict with information about the current character set:\n\
|
||||
\n\
|
||||
collation\n\
|
||||
collation name\n\
|
||||
name\n\
|
||||
character set name\n\
|
||||
comment\n\
|
||||
comment or descriptive name\n\
|
||||
dir\n\
|
||||
character set directory\n\
|
||||
mbminlen\n\
|
||||
min. length for multibyte string\n\
|
||||
mbmaxlen\n\
|
||||
max. length for multibyte string\n\
|
||||
\n\
|
||||
Not all keys may be present, particularly dir.\n\
|
||||
\n\
|
||||
Non-standard.\n\
|
||||
";
|
||||
|
||||
static PyObject *
|
||||
_mysql_ConnectionObject_get_character_set_info(
|
||||
_mysql_ConnectionObject *self,
|
||||
PyObject *args)
|
||||
{
|
||||
PyObject *result;
|
||||
MY_CHARSET_INFO cs;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
check_connection(self);
|
||||
mysql_get_character_set_info(&(self->connection), &cs);
|
||||
if (!(result = PyDict_New())) return NULL;
|
||||
if (cs.csname)
|
||||
PyDict_SetItemString(result, "name", PyString_FromString(cs.csname));
|
||||
if (cs.name)
|
||||
PyDict_SetItemString(result, "collation", PyString_FromString(cs.name));
|
||||
if (cs.comment)
|
||||
PyDict_SetItemString(result, "comment", PyString_FromString(cs.comment));
|
||||
if (cs.dir)
|
||||
PyDict_SetItemString(result, "dir", PyString_FromString(cs.dir));
|
||||
PyDict_SetItemString(result, "mbminlen", PyInt_FromLong(cs.mbminlen));
|
||||
PyDict_SetItemString(result, "mbmaxlen", PyInt_FromLong(cs.mbmaxlen));
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char _mysql_get_client_info__doc__[] =
|
||||
"get_client_info() -- Returns a string that represents\n\
|
||||
the client library version.";
|
||||
@ -2063,6 +2135,22 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
|
||||
METH_VARARGS,
|
||||
_mysql_ConnectionObject_character_set_name__doc__
|
||||
},
|
||||
#if MYSQL_VERSION_ID >= 50007
|
||||
{
|
||||
"set_character_set",
|
||||
(PyCFunction)_mysql_ConnectionObject_set_character_set,
|
||||
METH_VARARGS,
|
||||
_mysql_ConnectionObject_set_character_set__doc__
|
||||
},
|
||||
#endif
|
||||
#if MYSQL_VERSION_ID >= 50010
|
||||
{
|
||||
"get_character_set_info",
|
||||
(PyCFunction)_mysql_ConnectionObject_get_character_set_info,
|
||||
METH_VARARGS,
|
||||
_mysql_ConnectionObject_get_character_set_info__doc__
|
||||
},
|
||||
#endif
|
||||
{
|
||||
"close",
|
||||
(PyCFunction)_mysql_ConnectionObject_close,
|
||||
|
Reference in New Issue
Block a user