T
T
Timur Chernyaev2020-02-19 13:18:54
Python
Timur Chernyaev, 2020-02-19 13:18:54

How to display a specific row from a sqlite3 database?

Good day! The question is that I need to display a certain row from the entire database, and not through WHERE. How to make it so that, for example, the line that he just filled out is returned to the user? Or, at least, only id? Code snippet:

def registration():
    NAME = input('Как тебя зовут?(Например, Иван): ')
    SURNAME = input('Введи фамилию (Например, Иванов): ')
    PATRONYMIC = input('Введи отчество (Например, Иванович: ')
    CLASS = input('В каком классе ты учишься? (Например, 6А) : ')
    cursor.execute('INSERT INTO ids (name, surname, patronymic, class) VALUES (NAME, SURNAME, PATRONYMIC, CLASS)')

def take(cursor):
    book = input('Какую книгу ты хочешь взять? (введи только название): ')
    user_id = ('Пожалуйста, введи свой id: ')
    cursor.execute('')


Код, конечно, условный, но работать должно вот с таким фрагментом)
В последнем cursor.execute, как я думаю, и должен быть вывод)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Сергей Водаков, 2020-02-19
@WaterSmith

при этом не через WHERE

Why limit yourself? Just through WHERE this should be done. Judging by your code, your problem is that you don't know what to write in WHERE. Because you do not write down id in the table.
You need to do the following. At the beginning of the registration session, generate another unique id (methods may be different). When writing registration data, save this id along with the data.
And if necessary, get the data - extract it from the database using the conditionWHERE id = currentId

S
sotanodroid, 2020-02-19
@sotanodroid

Actually only through WHERE.

cursor.execute("SELECT * FROM table WHERE name = %s AND surname = %s", (var1, var2))

Here %s act as placeholders for input values ​​and also protect against SQL injections.
It will be useful to read this article: https://habr.com/en/post/321510/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question