N
N
NOblo2020-06-15 18:28:17
Python
NOblo, 2020-06-15 18:28:17

Problems with for and sqlite3, what to do?

Here is a piece, there is a for loop, and it is simply ignored :/

global db 
global sql 
db = sqlite3.connect("lffdkldf.db", check_same_thread=False) 
sql = db.cursor() 
 
sql.execute("""CREATE TABLE IF NOT EXISTS _bot_ ( 
 teleid BIGINT, 
 NeftCash BIGINT, 
 reginfo INT 
)""") 
db.commit() 
 
#command 
@bot.message_handler(commands=["start"]) 
def one(message): 
 bot.send_message(message.chat.id, "yes", reply_markup = klava1) 
#ЭТОТ ЦИКЛ ФОР ПРОСТО НЕ ВЫПОЛНЯТСЯ!
 for i in sql.execute("SELECT reginfo FROM _bot_"): 
    if i[0] == 1: 
        pass 
     else: 
     sql.execute("INSERT INTO _bot_ VALUES(?, ?, ?)", 
    (message.chat.id, 0, 1)) 
db.commit()

This handicap doesn't work either:
for i in sql.execute("SELECT teleid FROM _bot_"): 
 bot.send_message(message.chat.id, i + "all")

there is not even an error, he ignores why ?? What is the error due to which it ignores the for array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-06-15
@hottabxp

You would at least read a little bit about working with databases. Or at least look at some examples.
After sql.execute() call sql.fetchall()

S
Sergey Taranenko, 2020-06-16
@Shachi

I don't have much experience, but I would pass your code like this:

sql.execute("SELECT reginfo FROM _bot_")
data = sql.fetchall()

for i, row in enumerate(data): 
    # Тут ваш код.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question