F
F
fokioff2022-03-13 13:37:27
Python
fokioff, 2022-03-13 13:37:27

Why is data entered into the database with a comma at the beginning?

I need to enter the userid value into the database, but under certain conditions the entry will be different:

cur.execute(
      f'''SELECT pasw FROM users WHERE user_id LIKE "{useridlike}"'''
)
pasw = cur.fetchone()[0]
    
if pasw is None:
     cur.execute(
           f'''UPDATE users SET pasw = {message.from_user.id} WHERE user_id = "{useridlike}"'''
     )  # Сохраняем ему в pasw наш userid, при условии, что до этого строка была пустой.
    
else:
     cur.execute(
           f'''UPDATE users SET pasw = "{pasw}, {message.from_user.id}" WHERE user_id = "{useridlike}"'''
     )  # Сохраняем ему в pasw наш userid, при условии, что до этого строка была не пустой.


However, if before that the line was empty, then the value is entered with a comma at the beginning of the line:

622dc9362e64b793273269.png

Tell me, what can be done with this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nesterov, 2022-03-13
@fokioff

Well, at least because of the comma - "{pasw} , {message.from_user.id}".
And, I apologize for the question, but where do you dig up such guides?
At the very least, it's not pretty. As a maximum - problems with sql-injections
How correctly? Like this

D
Dr. Bacon, 2022-03-13
@bacon

Because you explicitly specified that it is necessary to write down this comma. And also read the documentation to no longer use f-strings to form queries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question