Lines Matching refs:self
37 #define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
89 pysqlite_cursor_init_impl(pysqlite_Cursor *self,
93 if (!check_cursor_locked(self)) {
98 Py_XSETREF(self->connection, connection);
99 Py_CLEAR(self->statement);
100 Py_CLEAR(self->row_cast_map);
103 Py_XSETREF(self->description, Py_None);
106 Py_XSETREF(self->lastrowid, Py_None);
108 self->arraysize = 1;
109 self->closed = 0;
110 self->rowcount = -1L;
113 Py_XSETREF(self->row_factory, Py_None);
115 if (!pysqlite_check_thread(self->connection)) {
119 if (!register_cursor(connection, (PyObject *)self)) {
123 self->initialized = 1;
129 stmt_reset(pysqlite_Statement *self)
133 if (self->in_use && self->st) {
135 rc = sqlite3_reset(self->st);
139 self->in_use = 0;
147 cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
149 Py_VISIT(Py_TYPE(self));
150 Py_VISIT(self->connection);
151 Py_VISIT(self->description);
152 Py_VISIT(self->row_cast_map);
153 Py_VISIT(self->lastrowid);
154 Py_VISIT(self->row_factory);
155 Py_VISIT(self->statement);
160 cursor_clear(pysqlite_Cursor *self)
162 Py_CLEAR(self->connection);
163 Py_CLEAR(self->description);
164 Py_CLEAR(self->row_cast_map);
165 Py_CLEAR(self->lastrowid);
166 Py_CLEAR(self->row_factory);
167 if (self->statement) {
169 stmt_reset(self->statement);
170 Py_CLEAR(self->statement);
177 cursor_dealloc(pysqlite_Cursor *self)
179 PyTypeObject *tp = Py_TYPE(self);
180 PyObject_GC_UnTrack(self);
181 if (self->in_weakreflist != NULL) {
182 PyObject_ClearWeakRefs((PyObject*)self);
184 tp->tp_clear((PyObject *)self);
185 tp->tp_free(self);
214 pysqlite_build_row_cast_map(pysqlite_Cursor* self)
221 if (!self->connection->detect_types) {
225 Py_XSETREF(self->row_cast_map, PyList_New(0));
226 if (!self->row_cast_map) {
230 for (i = 0; i < sqlite3_column_count(self->statement->st); i++) {
233 if (self->connection->detect_types & PARSE_COLNAMES) {
234 const char *colname = sqlite3_column_name(self->statement->st, i);
237 Py_CLEAR(self->row_cast_map);
246 pysqlite_state *state = self->connection->state;
250 Py_CLEAR(self->row_cast_map);
258 if (!converter && self->connection->detect_types & PARSE_DECLTYPES) {
259 decltype = sqlite3_column_decltype(self->statement->st, i);
267 pysqlite_state *state = self->connection->state;
271 Py_CLEAR(self->row_cast_map);
284 if (PyList_Append(self->row_cast_map, converter) != 0) {
285 Py_CLEAR(self->row_cast_map);
294 _pysqlite_build_column_name(pysqlite_Cursor *self, const char *colname)
299 if (self->connection->detect_types & PARSE_COLNAMES) {
323 _pysqlite_fetch_one_row(pysqlite_Cursor* self)
336 numcols = sqlite3_data_count(self->statement->st);
343 sqlite3 *db = self->connection->db;
345 if (self->connection->detect_types
346 && self->row_cast_map != NULL
347 && i < PyList_GET_SIZE(self->row_cast_map))
349 converter = PyList_GET_ITEM(self->row_cast_map, i);
362 const void *blob = sqlite3_column_blob(self->statement->st, i);
371 nbytes = sqlite3_column_bytes(self->statement->st, i);
381 coltype = sqlite3_column_type(self->statement->st, i);
386 converted = PyLong_FromLongLong(sqlite3_column_int64(self->statement->st, i));
388 converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
390 const char *text = (const char*)sqlite3_column_text(self->statement->st, i);
396 nbytes = sqlite3_column_bytes(self->statement->st, i);
397 if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) {
401 colname = sqlite3_column_name(self->statement->st, i);
410 PyObject *exc = self->connection->OperationalError;
418 } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
420 } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
423 converted = PyObject_CallFunction(self->connection->text_factory, "y#", text, nbytes);
427 const void *blob = sqlite3_column_blob(self->statement->st, i);
433 nbytes = sqlite3_column_bytes(self->statement->st, i);
480 begin_transaction(pysqlite_Connection *self)
482 assert(self->isolation_level != NULL);
489 size_t len = strlen(self->isolation_level);
492 (void)strcat(begin_stmt, self->isolation_level);
493 rc = sqlite3_prepare_v2(self->db, begin_stmt, -1, &statement, NULL);
501 (void)_pysqlite_seterror(self->state, self->db);
509 get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
512 PyObject *cache = self->connection->statement_cache;
530 bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
539 rc = sqlite3_bind_null(self->st, pos);
567 rc = sqlite3_bind_int64(self->st, pos, value);
576 rc = sqlite3_bind_double(self->st, pos, value);
589 rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
602 rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
634 bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
646 num_params_needed = sqlite3_bind_parameter_count(self->st);
695 rc = bind_param(state, self, i + 1, adapted);
701 sqlite3 *db = sqlite3_db_handle(self->st);
712 binding_name = sqlite3_bind_parameter_name(self->st, i);
755 rc = bind_param(state, self, i, adapted);
761 sqlite3 *db = sqlite3_db_handle(self->st);
774 stmt_mark_dirty(pysqlite_Statement *self)
776 self->in_use = 1;
780 _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
790 if (!check_cursor(self)) {
794 self->locked = 1;
833 if (self->statement != NULL) {
835 stmt_reset(self->statement);
840 Py_SETREF(self->description, Py_None);
842 if (self->statement) {
843 (void)stmt_reset(self->statement);
846 PyObject *stmt = get_statement_from_cache(self, operation);
847 Py_XSETREF(self->statement, (pysqlite_Statement *)stmt);
848 if (!self->statement) {
852 pysqlite_state *state = self->connection->state;
853 if (multiple && sqlite3_stmt_readonly(self->statement->st)) {
859 if (self->statement->in_use) {
860 Py_SETREF(self->statement,
861 pysqlite_statement_create(self->connection, operation));
862 if (self->statement == NULL) {
867 stmt_reset(self->statement);
868 stmt_mark_dirty(self->statement);
869 self->rowcount = self->statement->is_dml ? 0L : -1L;
873 if (self->connection->isolation_level
874 && self->statement->is_dml
875 && sqlite3_get_autocommit(self->connection->db))
877 if (begin_transaction(self->connection) < 0) {
888 stmt_mark_dirty(self->statement);
890 bind_parameters(state, self->statement, parameters);
895 rc = stmt_step(self->statement->st);
905 (void)stmt_reset(self->statement);
906 _pysqlite_seterror(state, self->connection->db);
910 if (pysqlite_build_row_cast_map(self) != 0) {
918 numcols = sqlite3_column_count(self->statement->st);
920 if (self->description == Py_None && numcols > 0) {
921 Py_SETREF(self->description, PyTuple_New(numcols));
922 if (!self->description) {
927 colname = sqlite3_column_name(self->statement->st, i);
932 column_name = _pysqlite_build_column_name(self, colname);
943 PyTuple_SET_ITEM(self->description, i, descriptor);
948 if (self->statement->is_dml) {
949 self->rowcount = (long)sqlite3_changes(self->connection->db);
951 stmt_reset(self->statement);
952 Py_CLEAR(self->statement);
956 if (self->statement->is_dml && rc == SQLITE_DONE) {
957 self->rowcount += (long)sqlite3_changes(self->connection->db);
959 stmt_reset(self->statement);
968 lastrowid = sqlite3_last_insert_rowid(self->connection->db);
971 Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid));
980 self->locked = 0;
983 self->rowcount = -1L;
986 return Py_NewRef((PyObject *)self);
1001 pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
1005 return _pysqlite_query_execute(self, 0, sql, parameters);
1019 pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
1023 return _pysqlite_query_execute(self, 1, sql, seq_of_parameters);
1036 pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
1040 if (!check_cursor(self)) {
1045 int max_length = sqlite3_limit(self->connection->db,
1048 PyErr_SetString(self->connection->DataError,
1054 sqlite3 *db = self->connection->db;
1094 return Py_NewRef((PyObject *)self);
1097 _pysqlite_seterror(self->connection->state, db);
1102 pysqlite_cursor_iternext(pysqlite_Cursor *self)
1104 if (!check_cursor(self)) {
1108 if (self->statement == NULL) {
1112 sqlite3_stmt *stmt = self->statement->st;
1115 (void)stmt_reset(self->statement);
1116 Py_CLEAR(self->statement);
1120 self->locked = 1; // GH-80254: Prevent recursive use of cursors.
1121 PyObject *row = _pysqlite_fetch_one_row(self);
1122 self->locked = 0;
1128 if (self->statement->is_dml) {
1129 self->rowcount = (long)sqlite3_changes(self->connection->db);
1131 (void)stmt_reset(self->statement);
1132 Py_CLEAR(self->statement);
1135 (void)_pysqlite_seterror(self->connection->state,
1136 self->connection->db);
1137 (void)stmt_reset(self->statement);
1138 Py_CLEAR(self->statement);
1142 if (!Py_IsNone(self->row_factory)) {
1143 PyObject *factory = self->row_factory;
1144 PyObject *args[] = { (PyObject *)self, row, };
1159 pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
1164 row = pysqlite_cursor_iternext(self);
1175 size as maxrows: int(c_default='self->arraysize') = 1
1182 pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
1194 while ((row = pysqlite_cursor_iternext(self))) {
1221 pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self)
1232 while ((row = pysqlite_cursor_iternext(self))) {
1258 pysqlite_cursor_setinputsizes(pysqlite_Cursor *self, PyObject *sizes)
1275 pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
1289 pysqlite_cursor_close_impl(pysqlite_Cursor *self)
1292 if (!check_cursor_locked(self)) {
1296 if (!self->connection) {
1297 PyTypeObject *tp = Py_TYPE(self);
1303 if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
1307 if (self->statement) {
1308 (void)stmt_reset(self->statement);
1309 Py_CLEAR(self->statement);
1312 self->closed = 1;