diff options
author | Gerhard Häring <gh@ghaering.de> | 2007-08-10 18:15:11 +0000 |
---|---|---|
committer | Gerhard Häring <gh@ghaering.de> | 2007-08-10 18:15:11 +0000 |
commit | e7032b0d3ad5babba5c2de8f691a679d22114ff1 (patch) | |
tree | 487f5bce631961eac947fd314698fdba0f0c993d /Modules/_sqlite | |
parent | b5032769966118611d536ca7b15223925f46b58f (diff) | |
download | cpython-e7032b0d3ad5babba5c2de8f691a679d22114ff1.tar.gz |
Make the sqlite tests pass.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/connection.c | 6 | ||||
-rw-r--r-- | Modules/_sqlite/cursor.c | 18 | ||||
-rw-r--r-- | Modules/_sqlite/row.c | 4 | ||||
-rw-r--r-- | Modules/_sqlite/statement.c | 3 |
4 files changed, 14 insertions, 17 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index add2e6f0a4..41b94aa69d 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -435,10 +435,8 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) } else if (PyString_Check(py_val)) { sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT); } else if (PyUnicode_Check(py_val)) { - stringval = PyUnicode_AsUTF8String(py_val); if (stringval) { - sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT); - Py_DECREF(stringval); + sqlite3_result_text(context, PyUnicode_AsString(stringval), -1, SQLITE_TRANSIENT); } } else { /* TODO: raise error */ @@ -1094,7 +1092,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args) goto finally; } - if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) { + if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyUnicode_Type, &name, &callable)) { goto finally; } diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 055e544b5e..412e38679e 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -248,7 +248,7 @@ PyObject* _pysqlite_build_column_name(const char* colname) if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) { pos--; } - return PyString_FromStringAndSize(colname, pos - colname); + return PyUnicode_FromStringAndSize(colname, pos - colname); } } } @@ -372,8 +372,10 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) } } else if (self->connection->text_factory == (PyObject*)&PyString_Type) { converted = PyString_FromString(val_str); + } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { + converted = PyBytes_FromStringAndSize(val_str, strlen(val_str)); } else { - converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str); + converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str); } } else { /* coltype == SQLITE_BLOB */ @@ -746,17 +748,13 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args) return NULL; } - if (PyString_Check(script_obj)) { - script_cstr = PyString_AsString(script_obj); - } else if (PyUnicode_Check(script_obj)) { - script_str = PyUnicode_AsUTF8String(script_obj); - if (!script_str) { + if (PyUnicode_Check(script_obj)) { + script_cstr = PyUnicode_AsString(script_obj); + if (!script_cstr) { return NULL; } - - script_cstr = PyString_AsString(script_str); } else { - PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string."); + PyErr_SetString(PyExc_ValueError, "script argument must be unicode."); return NULL; } diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index 6bd1887761..b2f105a9c4 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -86,8 +86,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) item = PyTuple_GetItem(self->data, _idx); Py_XINCREF(item); return item; - } else if (PyString_Check(idx)) { - key = PyString_AsString(idx); + } else if (PyUnicode_Check(idx)) { + key = PyUnicode_AsString(idx); nitems = PyTuple_Size(self->description); diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 5987b2a68e..b80b955847 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -113,7 +113,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); } else if PyUnicode_Check(parameter) { stringval = PyUnicode_AsUTF8String(parameter); - string = PyString_AsString(stringval); + string = PyBytes_AsString(stringval); + rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); Py_DECREF(stringval); } else { |