mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-13 04:26:33 +03:00
Encodings from Karsten (part 2.)
This commit is contained in:
parent
5642a68adb
commit
3a94e747d7
|
@ -180,21 +180,30 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *pos, *enc = NULL;
|
char *buffer, *enc = NULL;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
EXC_IF_CONN_CLOSED(self);
|
EXC_IF_CONN_CLOSED(self);
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &enc)) return NULL;
|
if (!PyArg_ParseTuple(args, "s", &enc)) return NULL;
|
||||||
|
|
||||||
/* convert to upper case */
|
/* convert to upper case and remove '-' and '_' from string */
|
||||||
for (pos = enc ; *pos != '\0' ; pos++)
|
buffer = PyMem_Malloc(strlen(enc));
|
||||||
*pos = toupper(*pos);
|
for (i=j=0 ; i < strlen(enc) ; i++) {
|
||||||
|
if (enc[i] == '_' || enc[i] == '-')
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
buffer[j++] = toupper(enc[i]);
|
||||||
|
}
|
||||||
|
buffer[j] = '\0';
|
||||||
|
|
||||||
if (conn_set_client_encoding(self, enc) == 0) {
|
if (conn_set_client_encoding(self, buffer) == 0) {
|
||||||
|
PyMem_Free(buffer);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
PyMem_Free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user