D
D
Durilka962021-03-21 00:30:21
Python
Durilka96, 2021-03-21 00:30:21

How to correctly form a sql query for the correct output of id?

there is a table in which I create just such a query

sqlite_create_table_query = '''CREATE TABLE session (
                                id INTEGER PRIMARY KEY,
                                ip_src TEXT ,
                                ip_dst TEXT ,
                                sport TEXT ,
                                dport TEXT ,
                                request TEXT ,
                                response TEXT );'''
cursor.execute(sqlite_create_table_query)

then I try to enter at least only 1 field is id, for this I make the following request
user_id=tuple([counter_for_id])
                                            print(user_id) #вывожу для удостоверения что переменная изменяется
                                            cursor.execute("INSERT INTO session VALUES (?,NULL,NULL,NULL,NULL,NULL,NULL);",user_id)
                                            sqlite_connection.commit();
                                            cursor.execute("SELECT * FROM session;")
                                            one_result = cursor.fetchone()
                                            print(one_result) #вывожу для проверки результата
#ниже записано
counter_for_id=counter_for_id+1

but the program writes only the first value and skips the rest, how to adapt everything correctly?605669477db7c497431004.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-03-21
@Durilka96

So you always choose only the first line and choose your fetchone.
one_result = cursor.fetchone()
Therefore, there is only id 1.
And in general, you don’t need to manually put down the id field, if it is declared INTEGER PRIMARY KEY, it will increase automatically.
https://sqlite.org/autoinc.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question