summaryrefslogtreecommitdiff
path: root/psycopg/adapter_qstring.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-18 05:02:11 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-21 04:02:14 +0000
commite182201e6ee8075a88b63c9d8338f833bd2471b0 (patch)
tree6b4adf73afd5f61c6cc549422e2be38fd720172e /psycopg/adapter_qstring.c
parentae06fb03e75c47f662606490203f365be26afd46 (diff)
downloadpsycopg2-e182201e6ee8075a88b63c9d8338f833bd2471b0.tar.gz
Added Python codec name to the connection.
This allows dropping repeated dictionary lookups with unicode query/parameters.
Diffstat (limited to 'psycopg/adapter_qstring.c')
-rw-r--r--psycopg/adapter_qstring.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 9da6a21..72240c8 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -49,22 +49,9 @@ qstring_quote(qstringObject *self)
Dprintf("qstring_quote: encoding to %s", self->encoding);
if (PyUnicode_Check(self->wrapped) && self->encoding) {
- PyObject *enc = PyDict_GetItemString(psycoEncodings, self->encoding);
- /* note that enc is a borrowed reference */
-
- if (enc) {
- const char *s = PyString_AsString(enc);
- Dprintf("qstring_quote: encoding unicode object to %s", s);
- str = PyUnicode_AsEncodedString(self->wrapped, s, NULL);
- Dprintf("qstring_quote: got encoded object at %p", str);
- if (str == NULL) return NULL;
- }
- else {
- /* can't find the right encoder, raise exception */
- PyErr_Format(InterfaceError,
- "can't encode unicode string to %s", self->encoding);
- return NULL;
- }
+ str = PyUnicode_AsEncodedString(self->wrapped, self->encoding, NULL);
+ Dprintf("qstring_quote: got encoded object at %p", str);
+ if (str == NULL) return NULL;
}
/* if the wrapped object is a simple string, we don't know how to
@@ -144,8 +131,8 @@ qstring_prepare(qstringObject *self, PyObject *args)
we don't need the encoding if that's not the case */
if (PyUnicode_Check(self->wrapped)) {
if (self->encoding) free(self->encoding);
- self->encoding = strdup(conn->encoding);
- Dprintf("qstring_prepare: set encoding to %s", conn->encoding);
+ self->encoding = strdup(conn->codec);
+ Dprintf("qstring_prepare: set encoding to %s", conn->codec);
}
Py_CLEAR(self->conn);