Lines Matching refs:self

109 #define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
119 static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
123 static void connection_close(pysqlite_Connection *self);
127 new_statement_cache(pysqlite_Connection *self, pysqlite_state *state,
142 args[1] = (PyObject *)self; // Borrowed ref.
176 pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
192 if (self->initialized) {
193 PyTypeObject *tp = Py_TYPE(self);
194 tp->tp_clear((PyObject *)self);
195 connection_close(self);
196 self->initialized = 0;
217 pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(self));
224 PyObject *statement_cache = new_statement_cache(self, state, cache_size);
244 self->db = db;
245 self->state = state;
246 self->detect_types = detect_types;
247 self->isolation_level = isolation_level;
248 self->check_same_thread = check_same_thread;
249 self->thread_ident = PyThread_get_thread_ident();
250 self->statement_cache = statement_cache;
251 self->cursors = cursors;
252 self->blobs = blobs;
253 self->created_cursors = 0;
254 self->row_factory = Py_NewRef(Py_None);
255 self->text_factory = Py_NewRef(&PyUnicode_Type);
256 self->trace_ctx = NULL;
257 self->progress_ctx = NULL;
258 self->authorizer_ctx = NULL;
261 self->Warning = state->Warning;
262 self->Error = state->Error;
263 self->InterfaceError = state->InterfaceError;
264 self->DatabaseError = state->DatabaseError;
265 self->DataError = state->DataError;
266 self->OperationalError = state->OperationalError;
267 self->IntegrityError = state->IntegrityError;
268 self->InternalError = state->InternalError;
269 self->ProgrammingError = state->ProgrammingError;
270 self->NotSupportedError = state->NotSupportedError;
272 if (PySys_Audit("sqlite3.connect/handle", "O", self) < 0) {
276 self->initialized = 1;
296 connection_traverse(pysqlite_Connection *self, visitproc visit, void *arg)
298 Py_VISIT(Py_TYPE(self));
299 Py_VISIT(self->statement_cache);
300 Py_VISIT(self->cursors);
301 Py_VISIT(self->blobs);
302 Py_VISIT(self->row_factory);
303 Py_VISIT(self->text_factory);
304 VISIT_CALLBACK_CONTEXT(self->trace_ctx);
305 VISIT_CALLBACK_CONTEXT(self->progress_ctx);
306 VISIT_CALLBACK_CONTEXT(self->authorizer_ctx);
321 connection_clear(pysqlite_Connection *self)
323 Py_CLEAR(self->statement_cache);
324 Py_CLEAR(self->cursors);
325 Py_CLEAR(self->blobs);
326 Py_CLEAR(self->row_factory);
327 Py_CLEAR(self->text_factory);
328 clear_callback_context(self->trace_ctx);
329 clear_callback_context(self->progress_ctx);
330 clear_callback_context(self->authorizer_ctx);
335 free_callback_contexts(pysqlite_Connection *self)
337 set_callback_context(&self->trace_ctx, NULL);
338 set_callback_context(&self->progress_ctx, NULL);
339 set_callback_context(&self->authorizer_ctx, NULL);
343 connection_close(pysqlite_Connection *self)
345 if (self->db) {
346 free_callback_contexts(self);
348 sqlite3 *db = self->db;
349 self->db = NULL;
359 connection_dealloc(pysqlite_Connection *self)
361 PyTypeObject *tp = Py_TYPE(self);
362 PyObject_GC_UnTrack(self);
363 tp->tp_clear((PyObject *)self);
366 connection_close(self);
368 tp->tp_free(self);
381 pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
386 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
391 factory = (PyObject *)self->state->CursorType;
394 cursor = PyObject_CallOneArg(factory, (PyObject *)self);
397 if (!PyObject_TypeCheck(cursor, self->state->CursorType)) {
405 _pysqlite_drop_unused_cursor_references(self);
407 if (cursor && self->row_factory != Py_None) {
408 Py_INCREF(self->row_factory);
409 Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory);
435 blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
439 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
447 rc = sqlite3_blob_open(self->db, name, table, col, row, !readonly, &blob);
451 PyErr_Format(self->state->InterfaceError, sqlite3_errstr(rc));
455 _pysqlite_seterror(self->state, self->db);
459 pysqlite_Blob *obj = PyObject_GC_New(pysqlite_Blob, self->state->BlobType);
464 obj->connection = (pysqlite_Connection *)Py_NewRef(self);
476 rc = PyList_Append(self->blobs, weakref);
498 pysqlite_connection_close_impl(pysqlite_Connection *self)
501 if (!pysqlite_check_thread(self)) {
505 if (!self->initialized) {
506 PyTypeObject *tp = Py_TYPE(self);
513 pysqlite_close_all_blobs(self);
514 Py_CLEAR(self->statement_cache);
515 connection_close(self);
552 pysqlite_connection_commit_impl(pysqlite_Connection *self)
555 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
559 if (!sqlite3_get_autocommit(self->db)) {
564 rc = sqlite3_prepare_v2(self->db, "COMMIT", 7, &statement, NULL);
572 (void)_pysqlite_seterror(self->state, self->db);
589 pysqlite_connection_rollback_impl(pysqlite_Connection *self)
592 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
596 if (!sqlite3_get_autocommit(self->db)) {
601 rc = sqlite3_prepare_v2(self->db, "ROLLBACK", 9, &statement, NULL);
609 (void)_pysqlite_seterror(self->state, self->db);
904 static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
911 if (self->created_cursors++ < 200) {
915 self->created_cursors = 0;
922 for (i = 0; i < PyList_Size(self->cursors); i++) {
923 weakref = PyList_GetItem(self->cursors, i);
932 Py_SETREF(self->cursors, new_list);
1001 pysqlite_connection_create_function_impl(pysqlite_Connection *self,
1010 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1016 PyErr_SetString(self->NotSupportedError,
1021 PyErr_SetString(self->NotSupportedError,
1032 rc = sqlite3_create_function_v2(self->db, name, narg, flags, ctx,
1040 PyErr_SetString(self->OperationalError, "Error creating function");
1153 create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
1159 PyErr_SetString(self->NotSupportedError,
1165 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1172 rc = sqlite3_create_window_function(self->db, name, num_params, flags,
1180 rc = sqlite3_create_window_function(self->db, name, num_params, flags,
1192 PyErr_SetString(self->ProgrammingError, sqlite3_errstr(rc));
1212 pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
1220 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1228 rc = sqlite3_create_function_v2(self->db, name, n_arg, SQLITE_UTF8, ctx,
1235 PyErr_SetString(self->OperationalError, "Error creating aggregate");
1389 pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
1394 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1400 rc = sqlite3_set_authorizer(self->db, NULL, NULL);
1401 set_callback_context(&self->authorizer_ctx, NULL);
1408 rc = sqlite3_set_authorizer(self->db, authorizer_callback, ctx);
1409 set_callback_context(&self->authorizer_ctx, ctx);
1412 PyErr_SetString(self->OperationalError,
1414 set_callback_context(&self->authorizer_ctx, NULL);
1432 pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
1437 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1443 sqlite3_progress_handler(self->db, 0, 0, (void*)0);
1444 set_callback_context(&self->progress_ctx, NULL);
1451 sqlite3_progress_handler(self->db, n, progress_callback, ctx);
1452 set_callback_context(&self->progress_ctx, ctx);
1468 pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
1473 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1486 sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, 0, 0);
1488 sqlite3_trace(self->db, 0, (void*)0);
1490 set_callback_context(&self->trace_ctx, NULL);
1498 sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, trace_callback, ctx);
1500 sqlite3_trace(self->db, trace_callback, ctx);
1502 set_callback_context(&self->trace_ctx, ctx);
1519 pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
1526 "OO", self, onoff ? Py_True : Py_False) < 0) {
1530 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1534 rc = sqlite3_enable_load_extension(self->db, onoff);
1537 PyErr_SetString(self->OperationalError,
1555 pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
1562 if (PySys_Audit("sqlite3.load_extension", "Os", self, extension_name) < 0) {
1566 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1570 rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);
1572 PyErr_SetString(self->OperationalError, errmsg);
1580 int pysqlite_check_thread(pysqlite_Connection* self)
1582 if (self->check_same_thread) {
1583 if (PyThread_get_thread_ident() != self->thread_ident) {
1584 PyErr_Format(self->ProgrammingError,
1587 self->thread_ident, PyThread_get_thread_ident());
1595 static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
1597 if (!pysqlite_check_connection(self)) {
1600 if (self->isolation_level != NULL) {
1601 return PyUnicode_FromString(self->isolation_level);
1606 static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused)
1608 if (!pysqlite_check_connection(self)) {
1611 return Py_BuildValue("i", sqlite3_total_changes(self->db));
1615 static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)
1617 if (!pysqlite_check_connection(self)) {
1620 if (!sqlite3_get_autocommit(self->db)) {
1627 pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored))
1634 self->isolation_level = NULL;
1637 PyObject *res = pysqlite_connection_commit_impl(self);
1644 if (!isolation_level_converter(isolation_level, &self->isolation_level)) {
1651 pysqlite_connection_call(pysqlite_Connection *self, PyObject *args,
1657 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1667 statement = pysqlite_statement_create(self, sql);
1686 pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
1692 PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
1719 pysqlite_connection_executemany_impl(pysqlite_Connection *self,
1725 PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
1751 pysqlite_connection_executescript(pysqlite_Connection *self,
1757 PyObject *cursor = pysqlite_connection_cursor_impl(self, NULL);
1762 PyObject *meth = self->state->str_executescript; // borrowed ref.
1838 pysqlite_connection_interrupt_impl(pysqlite_Connection *self)
1843 if (!pysqlite_check_connection(self)) {
1847 sqlite3_interrupt(self->db);
1866 pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
1874 if (!pysqlite_check_connection(self)) {
1896 PyErr_SetString(self->OperationalError,
1902 retval = PyObject_CallOneArg(pyfn_iterdump, (PyObject *)self);
1923 pysqlite_connection_backup_impl(pysqlite_Connection *self,
1934 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
1942 if (target == self) {
1951 PyErr_SetString(self->OperationalError, "target is in transaction");
1968 bck_handle = sqlite3_backup_init(bck_conn, "main", self->db, name);
1972 _pysqlite_seterror(self->state, bck_conn);
2010 _pysqlite_seterror(self->state, bck_conn);
2029 pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
2035 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
2043 rc = sqlite3_create_collation_v2(self->db, name, flags,
2055 rc = sqlite3_create_collation_v2(self->db, name, flags, ctx,
2068 _pysqlite_seterror(self->state, self->db);
2092 serialize_impl(pysqlite_Connection *self, const char *name)
2095 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
2107 data = (const char *)sqlite3_serialize(self->db, name, &size, flags);
2110 data = (const char *)sqlite3_serialize(self->db, name, &size, flags);
2115 PyErr_Format(self->OperationalError, "unable to serialize '%s'",
2147 deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
2151 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
2182 rc = sqlite3_deserialize(self->db, name, buf, size, size, flags);
2186 (void)_pysqlite_seterror(self->state, self->db);
2203 pysqlite_connection_enter_impl(pysqlite_Connection *self)
2206 if (!pysqlite_check_connection(self)) {
2209 return Py_NewRef((PyObject *)self);
2226 pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
2235 result = pysqlite_connection_commit_impl(self);
2238 result = pysqlite_connection_rollback_impl(self);
2247 result = pysqlite_connection_rollback_impl(self);
2281 setlimit_impl(pysqlite_Connection *self, int category, int limit)
2284 if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
2288 int old_limit = sqlite3_limit(self->db, category, limit);
2290 PyErr_SetString(self->ProgrammingError, "'category' is out of bounds");
2307 getlimit_impl(pysqlite_Connection *self, int category)
2310 return setlimit_impl(self, category, -1);