Apply changes from pysqlite3.
This commit is contained in:
parent
941a18dcac
commit
d354b48238
4 changed files with 24 additions and 16 deletions
28
src/blob.c
28
src/blob.c
|
|
@ -208,12 +208,17 @@ PyObject* pysqlite_blob_write(pysqlite_Blob *self, PyObject *data)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pysqlite_check_blob(self)) {
|
if (data_buffer.len > self->length - self->offset) {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"data longer than blob length");
|
||||||
PyBuffer_Release(&data_buffer);
|
PyBuffer_Release(&data_buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: throw better error on data bigger then blob. */
|
if (!pysqlite_check_blob(self)) {
|
||||||
|
PyBuffer_Release(&data_buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
rc = write_inner(self, data_buffer.buf, data_buffer.len, self->offset);
|
rc = write_inner(self, data_buffer.buf, data_buffer.len, self->offset);
|
||||||
|
|
||||||
|
|
@ -257,19 +262,22 @@ PyObject* pysqlite_blob_seek(pysqlite_Blob *self, PyObject *args)
|
||||||
offset = self->length + offset;
|
offset = self->length + offset;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return PyErr_Format(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"from_what should be 0, 1 or 2");
|
"from_what should be 0, 1 or 2");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset < 0 || offset > self->length) {
|
if (offset < 0 || offset > self->length) {
|
||||||
return PyErr_Format(PyExc_ValueError, "offset out of blob range");
|
PyErr_SetString(PyExc_ValueError, "offset out of blob range");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->offset = offset;
|
self->offset = offset;
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
overflow:
|
overflow:
|
||||||
return PyErr_Format(PyExc_OverflowError, "seek offset result in overflow");
|
PyErr_SetString(PyExc_OverflowError, "seek offset result in overflow");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -332,7 +340,7 @@ static int pysqlite_blob_contains(pysqlite_Blob *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (pysqlite_check_blob(self)) {
|
if (pysqlite_check_blob(self)) {
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"Blob don't support cotains operation");
|
"Blob don't support contains operation");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -407,11 +415,11 @@ static PyObject * pysqlite_blob_subscript(pysqlite_Blob *self, PyObject *item)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slicelen <= 0)
|
if (slicelen <= 0) {
|
||||||
return PyBytes_FromStringAndSize("", 0);
|
return PyBytes_FromStringAndSize("", 0);
|
||||||
else if (step == 1)
|
} else if (step == 1) {
|
||||||
return inner_read(self, slicelen, start);
|
return inner_read(self, slicelen, start);
|
||||||
else {
|
} else {
|
||||||
char *result_buf = (char *)PyMem_Malloc(slicelen);
|
char *result_buf = (char *)PyMem_Malloc(slicelen);
|
||||||
char *data_buff = NULL;
|
char *data_buff = NULL;
|
||||||
Py_ssize_t cur, i;
|
Py_ssize_t cur, i;
|
||||||
|
|
@ -586,7 +594,7 @@ static int pysqlite_blob_ass_subscript(pysqlite_Blob *self, PyObject *item, PyOb
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"mmap indices must be integer");
|
"Blob indices must be integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,8 @@ void pysqlite_cache_dealloc(pysqlite_Cache* self)
|
||||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
|
PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key)
|
||||||
{
|
{
|
||||||
PyObject* key = args;
|
|
||||||
pysqlite_Node* node;
|
pysqlite_Node* node;
|
||||||
pysqlite_Node* ptr;
|
pysqlite_Node* ptr;
|
||||||
PyObject* data;
|
PyObject* data;
|
||||||
|
|
@ -184,6 +183,9 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We cannot replace this by PyObject_CallOneArg() since
|
||||||
|
* PyObject_CallFunction() has a special case when using a
|
||||||
|
* single tuple as argument. */
|
||||||
data = PyObject_CallFunction(self->factory, "O", key);
|
data = PyObject_CallFunction(self->factory, "O", key);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@
|
||||||
#include "prepare_protocol.h"
|
#include "prepare_protocol.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include "pythread.h"
|
|
||||||
|
|
||||||
#define ACTION_FINALIZE 1
|
#define ACTION_FINALIZE 1
|
||||||
#define ACTION_RESET 2
|
#define ACTION_RESET 2
|
||||||
|
|
||||||
|
|
@ -1833,7 +1831,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
|
||||||
const char *uppercase_name_str;
|
const char *uppercase_name_str;
|
||||||
int rc;
|
int rc;
|
||||||
unsigned int kind;
|
unsigned int kind;
|
||||||
void *data;
|
const void *data;
|
||||||
|
|
||||||
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
|
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
|
||||||
|
|
@ -593,7 +593,7 @@ class BlobTests(unittest.TestCase):
|
||||||
self.assertEqual(self.blob.tell(), 50)
|
self.assertEqual(self.blob.tell(), 50)
|
||||||
|
|
||||||
def CheckBlobWriteMoreThenBlobSize(self):
|
def CheckBlobWriteMoreThenBlobSize(self):
|
||||||
with self.assertRaises(sqlite.OperationalError):
|
with self.assertRaises(ValueError):
|
||||||
self.blob.write(b"a" * 1000)
|
self.blob.write(b"a" * 1000)
|
||||||
|
|
||||||
def CheckBlobReadAfterRowChange(self):
|
def CheckBlobReadAfterRowChange(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue