Compare commits
3 Commits
f4507231e3
...
bf64d9064a
Author | SHA1 | Date |
---|---|---|
Erlend Egeberg Aasland | bf64d9064a | |
Erlend Egeberg Aasland | 3ccef1ca47 | |
Serhiy Storchaka | b02ad2458b |
|
@ -138,9 +138,13 @@ class TclTest(unittest.TestCase):
|
|||
|
||||
def get_integers(self):
|
||||
integers = (0, 1, -1, 2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
|
||||
# bignum was added in Tcl 8.5, but its support is able only since 8.5.8
|
||||
if (get_tk_patchlevel() >= (8, 6, 0, 'final') or
|
||||
(8, 5, 8) <= get_tk_patchlevel() < (8, 6)):
|
||||
# bignum was added in Tcl 8.5, but its support is able only since 8.5.8.
|
||||
# Actually it is determined at compile time, so using get_tk_patchlevel()
|
||||
# is not reliable.
|
||||
# TODO: expose full static version.
|
||||
if tcl_version >= (8, 5):
|
||||
v = get_tk_patchlevel()
|
||||
if v >= (8, 6, 0, 'final') or (8, 5, 8) <= v < (8, 6):
|
||||
integers += (2**63, -2**63-1, 2**1000, -2**1000)
|
||||
return integers
|
||||
|
||||
|
|
|
@ -34,11 +34,8 @@ pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(key);
|
||||
node->key = key;
|
||||
|
||||
Py_INCREF(data);
|
||||
node->data = data;
|
||||
node->key = Py_NewRef(key);
|
||||
node->data = Py_NewRef(data);
|
||||
|
||||
node->prev = NULL;
|
||||
node->next = NULL;
|
||||
|
@ -81,8 +78,7 @@ int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs)
|
|||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(factory);
|
||||
self->factory = factory;
|
||||
self->factory = Py_NewRef(factory);
|
||||
|
||||
self->decref_factory = 1;
|
||||
|
||||
|
@ -218,8 +214,7 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key)
|
|||
self->last = node;
|
||||
}
|
||||
|
||||
Py_INCREF(node->data);
|
||||
return node->data;
|
||||
return Py_NewRef(node->data);
|
||||
}
|
||||
|
||||
PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
|
||||
|
|
|
@ -57,6 +57,24 @@ pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored
|
|||
return pysqlite_connection_close_impl(self);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_commit__doc__,
|
||||
"commit($self, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Commit the current transaction.");
|
||||
|
||||
#define PYSQLITE_CONNECTION_COMMIT_METHODDEF \
|
||||
{"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_commit_impl(pysqlite_Connection *self);
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return pysqlite_connection_commit_impl(self);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
|
||||
"rollback($self, /)\n"
|
||||
"--\n"
|
||||
|
@ -373,6 +391,95 @@ exit:
|
|||
|
||||
#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_execute__doc__,
|
||||
"execute($self, sql, parameters=<unrepresentable>, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Executes a SQL statement. Non-standard.");
|
||||
|
||||
#define PYSQLITE_CONNECTION_EXECUTE_METHODDEF \
|
||||
{"execute", (PyCFunction)(void(*)(void))pysqlite_connection_execute, METH_FASTCALL, pysqlite_connection_execute__doc__},
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
|
||||
PyObject *parameters);
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *sql;
|
||||
PyObject *parameters = NULL;
|
||||
|
||||
if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyUnicode_Check(args[0])) {
|
||||
_PyArg_BadArgument("execute", "argument 1", "str", args[0]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[0]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
sql = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
parameters = args[1];
|
||||
skip_optional:
|
||||
return_value = pysqlite_connection_execute_impl(self, sql, parameters);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
|
||||
"executemany($self, sql, parameters, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Repeatedly executes a SQL statement. Non-standard.");
|
||||
|
||||
#define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF \
|
||||
{"executemany", (PyCFunction)(void(*)(void))pysqlite_connection_executemany, METH_FASTCALL, pysqlite_connection_executemany__doc__},
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_executemany_impl(pysqlite_Connection *self,
|
||||
PyObject *sql, PyObject *parameters);
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *sql;
|
||||
PyObject *parameters;
|
||||
|
||||
if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyUnicode_Check(args[0])) {
|
||||
_PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[0]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
sql = args[0];
|
||||
parameters = args[1];
|
||||
return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
|
||||
"executescript($self, sql_script, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Executes a multiple SQL statements at once. Non-standard.");
|
||||
|
||||
#define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \
|
||||
{"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
|
||||
"interrupt($self, /)\n"
|
||||
"--\n"
|
||||
|
@ -411,6 +518,107 @@ pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(igno
|
|||
return pysqlite_connection_iterdump_impl(self);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_backup__doc__,
|
||||
"backup($self, /, target=<unrepresentable>, *, pages=-1, progress=None,\n"
|
||||
" name=\'main\', sleep=0.25)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Makes a backup of the database. Non-standard.");
|
||||
|
||||
#define PYSQLITE_CONNECTION_BACKUP_METHODDEF \
|
||||
{"backup", (PyCFunction)(void(*)(void))pysqlite_connection_backup, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_backup_impl(pysqlite_Connection *self,
|
||||
pysqlite_Connection *target, int pages,
|
||||
PyObject *progress, const char *name,
|
||||
double sleep);
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
|
||||
static _PyArg_Parser _parser = {NULL, _keywords, "backup", 0};
|
||||
PyObject *argsbuf[5];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
pysqlite_Connection *target = NULL;
|
||||
int pages = -1;
|
||||
PyObject *progress = Py_None;
|
||||
const char *name = "main";
|
||||
double sleep = 0.25;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
if (!PyObject_TypeCheck(args[0], pysqlite_ConnectionType)) {
|
||||
_PyArg_BadArgument("backup", "argument 'target'", (pysqlite_ConnectionType)->tp_name, args[0]);
|
||||
goto exit;
|
||||
}
|
||||
target = (pysqlite_Connection *)args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
}
|
||||
skip_optional_pos:
|
||||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
if (args[1]) {
|
||||
pages = _PyLong_AsInt(args[1]);
|
||||
if (pages == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[2]) {
|
||||
progress = args[2];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[3]) {
|
||||
if (!PyUnicode_Check(args[3])) {
|
||||
_PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
|
||||
goto exit;
|
||||
}
|
||||
Py_ssize_t name_length;
|
||||
name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
|
||||
if (name == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
if (strlen(name) != (size_t)name_length) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (PyFloat_CheckExact(args[4])) {
|
||||
sleep = PyFloat_AS_DOUBLE(args[4]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep = PyFloat_AsDouble(args[4]);
|
||||
if (sleep == -1.0 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
skip_optional_kwonly:
|
||||
return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
|
||||
"create_collation($self, name, callback, /)\n"
|
||||
"--\n"
|
||||
|
@ -511,4 +719,4 @@ exit:
|
|||
#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
|
||||
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
|
||||
#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
|
||||
/*[clinic end generated code: output=eb14a52e4c682f3b input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=7cb13d491a5970aa input=a9049054013a1b77]*/
|
||||
|
|
|
@ -407,7 +407,15 @@ error:
|
|||
}
|
||||
}
|
||||
|
||||
PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
|
||||
/*[clinic input]
|
||||
_sqlite3.Connection.commit as pysqlite_connection_commit
|
||||
|
||||
Commit the current transaction.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_commit_impl(pysqlite_Connection *self)
|
||||
/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
|
||||
{
|
||||
int rc;
|
||||
const char* tail;
|
||||
|
@ -567,8 +575,7 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_
|
|||
/* TODO: have a way to show errors here */
|
||||
if (!cur_py_value) {
|
||||
PyErr_Clear();
|
||||
Py_INCREF(Py_None);
|
||||
cur_py_value = Py_None;
|
||||
cur_py_value = Py_NewRef(Py_None);
|
||||
}
|
||||
break;
|
||||
case SQLITE_BLOB:
|
||||
|
@ -578,8 +585,7 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_
|
|||
break;
|
||||
case SQLITE_NULL:
|
||||
default:
|
||||
Py_INCREF(Py_None);
|
||||
cur_py_value = Py_None;
|
||||
cur_py_value = Py_NewRef(Py_None);
|
||||
}
|
||||
|
||||
if (!cur_py_value) {
|
||||
|
@ -845,12 +851,11 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
|
|||
flags |= SQLITE_DETERMINISTIC;
|
||||
#endif
|
||||
}
|
||||
Py_INCREF(func);
|
||||
rc = sqlite3_create_function_v2(self->db,
|
||||
name,
|
||||
narg,
|
||||
flags,
|
||||
(void*)func,
|
||||
(void*)Py_NewRef(func),
|
||||
_pysqlite_func_callback,
|
||||
NULL,
|
||||
NULL,
|
||||
|
@ -891,7 +896,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
|
|||
name,
|
||||
n_arg,
|
||||
SQLITE_UTF8,
|
||||
(void*)aggregate_class,
|
||||
(void*)Py_NewRef(aggregate_class),
|
||||
0,
|
||||
&_pysqlite_step_callback,
|
||||
&_pysqlite_final_callback,
|
||||
|
@ -1204,8 +1209,7 @@ int pysqlite_check_thread(pysqlite_Connection* self)
|
|||
|
||||
static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
|
||||
{
|
||||
Py_INCREF(self->isolation_level);
|
||||
return self->isolation_level;
|
||||
return Py_NewRef(self->isolation_level);
|
||||
}
|
||||
|
||||
static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused)
|
||||
|
@ -1339,89 +1343,108 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args)
|
||||
/*[clinic input]
|
||||
_sqlite3.Connection.execute as pysqlite_connection_execute
|
||||
|
||||
sql: unicode
|
||||
parameters: object = NULL
|
||||
/
|
||||
|
||||
Executes a SQL statement. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
|
||||
PyObject *parameters)
|
||||
/*[clinic end generated code: output=5be05ae01ee17ee4 input=fbd17c75c7140271]*/
|
||||
{
|
||||
_Py_IDENTIFIER(execute);
|
||||
PyObject* cursor = 0;
|
||||
PyObject* result = 0;
|
||||
PyObject* method = 0;
|
||||
|
||||
cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
|
||||
if (!cursor) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
method = PyObject_GetAttrString(cursor, "execute");
|
||||
if (!method) {
|
||||
Py_CLEAR(cursor);
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = PyObject_CallObject(method, args);
|
||||
result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_execute, sql, parameters, NULL);
|
||||
if (!result) {
|
||||
Py_CLEAR(cursor);
|
||||
}
|
||||
|
||||
error:
|
||||
Py_XDECREF(result);
|
||||
Py_XDECREF(method);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* args)
|
||||
/*[clinic input]
|
||||
_sqlite3.Connection.executemany as pysqlite_connection_executemany
|
||||
|
||||
sql: unicode
|
||||
parameters: object
|
||||
/
|
||||
|
||||
Repeatedly executes a SQL statement. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_executemany_impl(pysqlite_Connection *self,
|
||||
PyObject *sql, PyObject *parameters)
|
||||
/*[clinic end generated code: output=776cd2fd20bfe71f input=4feab80659ffc82b]*/
|
||||
{
|
||||
_Py_IDENTIFIER(executemany);
|
||||
PyObject* cursor = 0;
|
||||
PyObject* result = 0;
|
||||
PyObject* method = 0;
|
||||
|
||||
cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
|
||||
if (!cursor) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
method = PyObject_GetAttrString(cursor, "executemany");
|
||||
if (!method) {
|
||||
Py_CLEAR(cursor);
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = PyObject_CallObject(method, args);
|
||||
result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executemany, sql,
|
||||
parameters, NULL);
|
||||
if (!result) {
|
||||
Py_CLEAR(cursor);
|
||||
}
|
||||
|
||||
error:
|
||||
Py_XDECREF(result);
|
||||
Py_XDECREF(method);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject* args)
|
||||
/*[clinic input]
|
||||
_sqlite3.Connection.executescript as pysqlite_connection_executescript
|
||||
|
||||
sql_script as script_obj: object
|
||||
/
|
||||
|
||||
Executes a multiple SQL statements at once. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_executescript(pysqlite_Connection *self,
|
||||
PyObject *script_obj)
|
||||
/*[clinic end generated code: output=4c4f9d77aa0ae37d input=c0b14695aa6c81d9]*/
|
||||
{
|
||||
_Py_IDENTIFIER(executescript);
|
||||
PyObject* cursor = 0;
|
||||
PyObject* result = 0;
|
||||
PyObject* method = 0;
|
||||
|
||||
cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
|
||||
if (!cursor) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
method = PyObject_GetAttrString(cursor, "executescript");
|
||||
if (!method) {
|
||||
Py_CLEAR(cursor);
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = PyObject_CallObject(method, args);
|
||||
result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executescript,
|
||||
script_obj, NULL);
|
||||
if (!result) {
|
||||
Py_CLEAR(cursor);
|
||||
}
|
||||
|
||||
error:
|
||||
Py_XDECREF(result);
|
||||
Py_XDECREF(method);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
@ -1499,8 +1522,7 @@ pysqlite_connection_interrupt_impl(pysqlite_Connection *self)
|
|||
|
||||
sqlite3_interrupt(self->db);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
retval = Py_None;
|
||||
retval = Py_NewRef(Py_None);
|
||||
|
||||
finally:
|
||||
return retval;
|
||||
|
@ -1558,51 +1580,41 @@ finally:
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_sqlite3.Connection.backup as pysqlite_connection_backup
|
||||
|
||||
target: object(type='pysqlite_Connection *', subclass_of='pysqlite_ConnectionType') = NULL
|
||||
*
|
||||
pages: int = -1
|
||||
progress: object = None
|
||||
name: str = "main"
|
||||
sleep: double = 0.250
|
||||
|
||||
Makes a backup of the database. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *kwds)
|
||||
pysqlite_connection_backup_impl(pysqlite_Connection *self,
|
||||
pysqlite_Connection *target, int pages,
|
||||
PyObject *progress, const char *name,
|
||||
double sleep)
|
||||
/*[clinic end generated code: output=306a3e6a38c36334 input=2f3497ea530144b1]*/
|
||||
{
|
||||
PyObject *target = NULL;
|
||||
int pages = -1;
|
||||
PyObject *progress = Py_None;
|
||||
const char *name = "main";
|
||||
int rc;
|
||||
int callback_error = 0;
|
||||
PyObject *sleep_obj = NULL;
|
||||
int sleep_ms = 250;
|
||||
int sleep_ms = sleep * 1000.0;
|
||||
sqlite3 *bck_conn;
|
||||
sqlite3_backup *bck_handle;
|
||||
static char *keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|$iOsO:backup", keywords,
|
||||
pysqlite_ConnectionType, &target,
|
||||
&pages, &progress, &name, &sleep_obj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sleep_obj != NULL) {
|
||||
_PyTime_t sleep_secs;
|
||||
if (_PyTime_FromSecondsObject(&sleep_secs, sleep_obj,
|
||||
_PyTime_ROUND_TIMEOUT)) {
|
||||
return NULL;
|
||||
}
|
||||
_PyTime_t ms = _PyTime_AsMilliseconds(sleep_secs,
|
||||
_PyTime_ROUND_TIMEOUT);
|
||||
if (ms < INT_MIN || ms > INT_MAX) {
|
||||
PyErr_SetString(PyExc_OverflowError, "sleep is too large");
|
||||
return NULL;
|
||||
}
|
||||
sleep_ms = (int)ms;
|
||||
}
|
||||
|
||||
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!pysqlite_check_connection((pysqlite_Connection *)target)) {
|
||||
if (!pysqlite_check_connection(target)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((pysqlite_Connection *)target == self) {
|
||||
if (target == self) {
|
||||
PyErr_SetString(PyExc_ValueError, "target cannot be the same connection instance");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1610,7 +1622,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
|
|||
#if SQLITE_VERSION_NUMBER < 3008008
|
||||
/* Since 3.8.8 this is already done, per commit
|
||||
https://www.sqlite.org/src/info/169b5505498c0a7e */
|
||||
if (!sqlite3_get_autocommit(((pysqlite_Connection *)target)->db)) {
|
||||
if (!sqlite3_get_autocommit(target->db)) {
|
||||
PyErr_SetString(pysqlite_OperationalError, "target is in transaction");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1625,7 +1637,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
|
|||
pages = -1;
|
||||
}
|
||||
|
||||
bck_conn = ((pysqlite_Connection *)target)->db;
|
||||
bck_conn = target->db;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
bck_handle = sqlite3_backup_init(bck_conn, "main", self->db, name);
|
||||
|
@ -1729,7 +1741,6 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
|
|||
/*[clinic end generated code: output=0f63b8995565ae22 input=5c3898813a776cf2]*/
|
||||
{
|
||||
PyObject* uppercase_name = 0;
|
||||
PyObject* retval;
|
||||
Py_ssize_t i, len;
|
||||
_Py_IDENTIFIER(upper);
|
||||
const char *uppercase_name_str;
|
||||
|
@ -1797,13 +1808,9 @@ finally:
|
|||
Py_XDECREF(uppercase_name);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
retval = NULL;
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
retval = Py_None;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
return Py_NewRef(Py_None);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -1818,8 +1825,7 @@ static PyObject *
|
|||
pysqlite_connection_enter_impl(pysqlite_Connection *self)
|
||||
/*[clinic end generated code: output=457b09726d3e9dcd input=127d7a4f17e86d8f]*/
|
||||
{
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
return Py_NewRef((PyObject *)self);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -1869,13 +1875,18 @@ static PyGetSetDef connection_getset[] = {
|
|||
};
|
||||
|
||||
static PyMethodDef connection_methods[] = {
|
||||
PYSQLITE_CONNECTION_BACKUP_METHODDEF
|
||||
PYSQLITE_CONNECTION_CLOSE_METHODDEF
|
||||
PYSQLITE_CONNECTION_COMMIT_METHODDEF
|
||||
PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF
|
||||
PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF
|
||||
PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF
|
||||
PYSQLITE_CONNECTION_CURSOR_METHODDEF
|
||||
PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
|
||||
PYSQLITE_CONNECTION_ENTER_METHODDEF
|
||||
PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF
|
||||
PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF
|
||||
PYSQLITE_CONNECTION_EXECUTE_METHODDEF
|
||||
PYSQLITE_CONNECTION_EXIT_METHODDEF
|
||||
PYSQLITE_CONNECTION_INTERRUPT_METHODDEF
|
||||
PYSQLITE_CONNECTION_ITERDUMP_METHODDEF
|
||||
|
@ -1884,16 +1895,6 @@ static PyMethodDef connection_methods[] = {
|
|||
PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF
|
||||
PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF
|
||||
PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF
|
||||
{"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS,
|
||||
PyDoc_STR("Commit the current transaction.")},
|
||||
{"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS,
|
||||
PyDoc_STR("Executes a SQL statement. Non-standard.")},
|
||||
{"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS,
|
||||
PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")},
|
||||
{"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS,
|
||||
PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
|
||||
{"backup", (PyCFunction)(void(*)(void))pysqlite_connection_backup, METH_VARARGS | METH_KEYWORDS,
|
||||
PyDoc_STR("Makes a backup of the database. Non-standard.")},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -111,7 +111,6 @@ extern PyTypeObject *pysqlite_ConnectionType;
|
|||
PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware);
|
||||
void pysqlite_connection_dealloc(pysqlite_Connection* self);
|
||||
PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
|
||||
PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args);
|
||||
PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
|
||||
int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
|
||||
|
||||
|
|
|
@ -271,8 +271,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||
val_str = (const char*)sqlite3_column_blob(self->statement->st, i);
|
||||
if (!val_str) {
|
||||
Py_INCREF(Py_None);
|
||||
converted = Py_None;
|
||||
converted = Py_NewRef(Py_None);
|
||||
} else {
|
||||
item = PyBytes_FromStringAndSize(val_str, nbytes);
|
||||
if (!item)
|
||||
|
@ -285,8 +284,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
coltype = sqlite3_column_type(self->statement->st, i);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (coltype == SQLITE_NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
converted = Py_None;
|
||||
converted = Py_NewRef(Py_None);
|
||||
} else if (coltype == SQLITE_INTEGER) {
|
||||
converted = PyLong_FromLongLong(sqlite3_column_int64(self->statement->st, i));
|
||||
} else if (coltype == SQLITE_FLOAT) {
|
||||
|
@ -402,8 +400,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
|
|||
|
||||
if (PyIter_Check(second_argument)) {
|
||||
/* iterator */
|
||||
Py_INCREF(second_argument);
|
||||
parameters_iter = second_argument;
|
||||
parameters_iter = Py_NewRef(second_argument);
|
||||
} else {
|
||||
/* sequence */
|
||||
parameters_iter = PyObject_GetIter(second_argument);
|
||||
|
@ -456,8 +453,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
|
|||
if (!func_args) {
|
||||
goto error;
|
||||
}
|
||||
Py_INCREF(operation);
|
||||
if (PyTuple_SetItem(func_args, 0, operation) != 0) {
|
||||
if (PyTuple_SetItem(func_args, 0, Py_NewRef(operation)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -555,12 +551,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
|
|||
goto error;
|
||||
}
|
||||
PyTuple_SetItem(descriptor, 0, column_name);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None);
|
||||
Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None);
|
||||
PyTuple_SetItem(descriptor, 1, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(descriptor, 2, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(descriptor, 3, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(descriptor, 4, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(descriptor, 5, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(descriptor, 6, Py_NewRef(Py_None));
|
||||
PyTuple_SetItem(self->description, i, descriptor);
|
||||
}
|
||||
}
|
||||
|
@ -610,8 +606,7 @@ error:
|
|||
self->rowcount = -1L;
|
||||
return NULL;
|
||||
} else {
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
return Py_NewRef((PyObject *)self);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -628,6 +623,7 @@ PyObject* pysqlite_cursor_executemany(pysqlite_Cursor* self, PyObject* args)
|
|||
static PyObject *
|
||||
pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
|
||||
{
|
||||
_Py_IDENTIFIER(commit);
|
||||
PyObject* script_obj;
|
||||
const char* script_cstr;
|
||||
sqlite3_stmt* statement;
|
||||
|
@ -655,7 +651,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
|
|||
}
|
||||
|
||||
/* commit first */
|
||||
result = pysqlite_connection_commit(self->connection, NULL);
|
||||
result = _PyObject_CallMethodIdNoArgs((PyObject *)self->connection, &PyId_commit);
|
||||
if (!result) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -705,8 +701,7 @@ error:
|
|||
if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
} else {
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
return Py_NewRef((PyObject *)self);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,8 +140,7 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
|
|||
}
|
||||
|
||||
if (alt) {
|
||||
Py_INCREF(alt);
|
||||
return alt;
|
||||
return Py_NewRef(alt);
|
||||
}
|
||||
/* else set the right exception and return NULL */
|
||||
PyErr_SetString(pysqlite_ProgrammingError, "can't adapt");
|
||||
|
|
|
@ -120,17 +120,11 @@ static PyObject *
|
|||
pysqlite_complete_statement_impl(PyObject *module, const char *statement)
|
||||
/*[clinic end generated code: output=e55f1ff1952df558 input=f6b24996b31c5c33]*/
|
||||
{
|
||||
PyObject* result;
|
||||
|
||||
if (sqlite3_complete(statement)) {
|
||||
result = Py_True;
|
||||
return Py_NewRef(Py_True);
|
||||
} else {
|
||||
result = Py_False;
|
||||
return Py_NewRef(Py_False);
|
||||
}
|
||||
|
||||
Py_INCREF(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -219,8 +213,7 @@ pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
|
|||
goto error;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
retval = Py_None;
|
||||
retval = Py_NewRef(Py_None);
|
||||
error:
|
||||
Py_XDECREF(name);
|
||||
return retval;
|
||||
|
|
|
@ -63,20 +63,16 @@ pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
if (self == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(data);
|
||||
self->data = data;
|
||||
|
||||
Py_INCREF(cursor->description);
|
||||
self->description = cursor->description;
|
||||
self->data = Py_NewRef(data);
|
||||
self->description = Py_NewRef(cursor->description);
|
||||
|
||||
return (PyObject *) self;
|
||||
}
|
||||
|
||||
PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx)
|
||||
{
|
||||
PyObject* item = PyTuple_GetItem(self->data, idx);
|
||||
Py_XINCREF(item);
|
||||
return item;
|
||||
PyObject *item = PyTuple_GetItem(self->data, idx);
|
||||
return Py_XNewRef(item);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -111,7 +107,6 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
|
|||
{
|
||||
Py_ssize_t _idx;
|
||||
Py_ssize_t nitems, i;
|
||||
PyObject* item;
|
||||
|
||||
if (PyLong_Check(idx)) {
|
||||
_idx = PyNumber_AsSsize_t(idx, PyExc_IndexError);
|
||||
|
@ -119,9 +114,9 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
|
|||
return NULL;
|
||||
if (_idx < 0)
|
||||
_idx += PyTuple_GET_SIZE(self->data);
|
||||
item = PyTuple_GetItem(self->data, _idx);
|
||||
Py_XINCREF(item);
|
||||
return item;
|
||||
|
||||
PyObject *item = PyTuple_GetItem(self->data, _idx);
|
||||
return Py_XNewRef(item);
|
||||
} else if (PyUnicode_Check(idx)) {
|
||||
nitems = PyTuple_Size(self->description);
|
||||
|
||||
|
@ -135,9 +130,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
|
|||
}
|
||||
if (eq) {
|
||||
/* found item */
|
||||
item = PyTuple_GetItem(self->data, i);
|
||||
Py_INCREF(item);
|
||||
return item;
|
||||
PyObject *item = PyTuple_GetItem(self->data, i);
|
||||
return Py_XNewRef(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
|
|||
}
|
||||
|
||||
self->in_weakreflist = NULL;
|
||||
Py_INCREF(sql);
|
||||
self->sql = sql;
|
||||
self->sql = Py_NewRef(sql);
|
||||
|
||||
/* Determine if the statement is a DML statement.
|
||||
SELECT is the only exception. See #9924. */
|
||||
|
@ -240,11 +239,11 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
|
|||
}
|
||||
for (i = 0; i < num_params; i++) {
|
||||
if (PyTuple_CheckExact(parameters)) {
|
||||
current_param = PyTuple_GET_ITEM(parameters, i);
|
||||
Py_INCREF(current_param);
|
||||
PyObject *item = PyTuple_GET_ITEM(parameters, i);
|
||||
current_param = Py_NewRef(item);
|
||||
} else if (PyList_CheckExact(parameters)) {
|
||||
current_param = PyList_GetItem(parameters, i);
|
||||
Py_XINCREF(current_param);
|
||||
PyObject *item = PyList_GetItem(parameters, i);
|
||||
current_param = Py_XNewRef(item);
|
||||
} else {
|
||||
current_param = PySequence_GetItem(parameters, i);
|
||||
}
|
||||
|
@ -290,8 +289,8 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
|
|||
return;
|
||||
}
|
||||
if (PyDict_CheckExact(parameters)) {
|
||||
current_param = PyDict_GetItemWithError(parameters, binding_name_obj);
|
||||
Py_XINCREF(current_param);
|
||||
PyObject *item = PyDict_GetItemWithError(parameters, binding_name_obj);
|
||||
current_param = Py_XNewRef(item);
|
||||
} else {
|
||||
current_param = PyObject_GetItem(parameters, binding_name_obj);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue