diff options
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/cursor.c | 6 | ||||
-rw-r--r-- | Modules/_sqlite/row.c | 28 | ||||
-rw-r--r-- | Modules/_sqlite/statement.c | 7 |
3 files changed, 31 insertions, 10 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 8efa812..10ce2e1 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -202,7 +202,11 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self) decltype = sqlite3_column_decltype(self->statement->st, i); if (decltype) { for (pos = decltype;;pos++) { - if (*pos == ' ' || *pos == 0) { + /* Converter names are split at '(' and blanks. + * This allows 'INTEGER NOT NULL' to be treated as 'INTEGER' and + * 'NUMBER(10)' to be treated as 'NUMBER', for example. + * In other words, it will work as people expect it to work.*/ + if (*pos == ' ' || *pos == '(' || *pos == 0) { py_decltype = PyUnicode_FromStringAndSize(decltype, pos - decltype); if (!py_decltype) { return -1; diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index 47b91ed..008f19e 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -164,6 +164,30 @@ static PyObject* pysqlite_iter(pysqlite_Row* self) return PyObject_GetIter(self->data); } +static long pysqlite_row_hash(pysqlite_Row *self) +{ + return PyObject_Hash(self->description) ^ PyObject_Hash(self->data); +} + +static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid) +{ + if (opid != Py_EQ && opid != Py_NE) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) { + pysqlite_Row *other = (pysqlite_Row *)_other; + PyObject *res = PyObject_RichCompare(self->description, other->description, opid); + if (opid == Py_EQ && res == Py_True + || opid == Py_NE && res == Py_False) { + Py_DECREF(res); + return PyObject_RichCompare(self->data, other->data, opid); + } + } + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; +} + PyMappingMethods pysqlite_row_as_mapping = { /* mp_length */ (lenfunc)pysqlite_row_length, /* mp_subscript */ (binaryfunc)pysqlite_row_subscript, @@ -191,7 +215,7 @@ PyTypeObject pysqlite_RowType = { 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + (hashfunc)pysqlite_row_hash, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ @@ -201,7 +225,7 @@ PyTypeObject pysqlite_RowType = { 0, /* tp_doc */ (traverseproc)0, /* tp_traverse */ 0, /* tp_clear */ - 0, /* tp_richcompare */ + (richcmpfunc)pysqlite_row_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ (getiterfunc)pysqlite_iter, /* tp_iter */ 0, /* tp_iternext */ diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 66adff3..ebf948b 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -89,10 +89,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars) { int rc = SQLITE_OK; - long longval; -#ifdef HAVE_LONG_LONG PY_LONG_LONG longlongval; -#endif const char* buffer; char* string; Py_ssize_t buflen; @@ -136,12 +133,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec switch (paramtype) { case TYPE_LONG: /* in the overflow error case, longval/longlongval is -1, and an exception is set */ -#ifdef HAVE_LONG_LONG longlongval = PyLong_AsLongLong(parameter); rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval); -#else - rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval); -#endif break; case TYPE_FLOAT: rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); |