Answer the question
In order to leave comments, you need to log in
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)
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question