V
V
vanoi2020-11-01 14:50:51
Arduino
vanoi, 2020-11-01 14:50:51

Why does sqlite3 output r[]?

I have been struggling with this question for a long time, they tell me that I am asking incorrectly

db = sqlite3.connect('a.db', check_same_thread=False)
sql = db.cursor()


# Create table
sql.execute('''CREATE TABLE IF NOT EXISTS name(
    id TEXT,
    call_data TEXT
) ''')
db.commit()


i = [('AgACAgIAAxkBAAMoX52AILubJTBkHIWQDBZNRbu9PRoAAnOuMRslGPBIqyRYTDLP-zP8r2yWLgADAQADAgADeQAD7lMDAAEbBA', 'biology1'), # 1
     ('AgACAgIAAxkBAAMTX51vtvhTqKaKrMoQe0r7l93jKdgAAi-uMRslGPBIzdcC4cmshh64HMqXLgADAQADAgADeQAD9kwCAAEbBA', 'biology2'), # 2
     ('AgACAgIAAxkBAAMUX51v5aoa9qRAx8o8Ub1devWWlFsAAjCuMRslGPBIzCn_lCvoFQABdfbVli4AAwEAAwIAA3kAA-MWAwABGwQ', 'biology3'), # 3
     ('AgACAgIAAxkBAAMVX51wAfEiXLTsO1lb_JlD15nIbF8AAjGuMRslGPBIksT_5qzkdh9TvtGXLgADAQADAgADeQADA0kCAAEbBA', 'biology4',), # 4
     ('AgACAgIAAxkBAAMWX51wKPwPL6BtFk2d90-UfM2liQADM64xGyUY8Ejvts84eaMBI1UHbZcuAAMBAAMCAAN5AAPBhwIAARsE', 'biology5'),# 5
     ('AgACAgIAAxkBAAMXX51wRT5hl_i5izo1xkiJezgdELkAAjSuMRslGPBIZZ9G0nGii0VUidqWLgADAQADAgADeQADbhYDAAEbBA', 'biology6'), # 6
     ('AgACAgIAAxkBAAMYX51wZv_o26Ohj8ia7mfhGARFtTwAAjWuMRslGPBIIuQNlERX9q77QfCXLgADAQADAgADeQAD-F8CAAEbBA', 'biology7'), # 7
     ('AgACAgIAAxkBAAMZX51weLPHXSMNVEc1JJZmepYRCroAAjauMRslGPBI1lggOS2VoWYzThKVLgADAQADAgADeQADbPwFAAEbBA', 'biology8'),# 8
     ('AgACAgIAAxkBAAMaX51wrTasDFXGR_U3SG8X_uhIXZsAAjiuMRslGPBIII74ck-HyhldQfCXLgADAQADAgADeQADeF4CAAEbBA',  'biology9'),# 9
     ('AgACAgIAAxkBAAMbX51w1pVNOPuGQXXZdf1_KRkIs_oAAjmuMRslGPBIHNpb2rJgdCPicGaaLgADAQADAgADeQAD3jwAAhsE',  'biology10'),# 10
     ('AgACAgIAAxkBAAMcX51w9ZbT62kpsxxfbLF2V_cadmMAAjquMRslGPBICyax5fqh6QmIyNSXLgADAQADAgADeQAD2kUCAAEbBA', 'biology11'),# 11
     ('AgACAgIAAxkBAAMdX51yk_DOGnce-q8BMQ9p8QMisrsAAj2uMRslGPBIh5e5PZKTBFrsidqWLgADAQADAgADeQAD7BwDAAEbBA', 'biology12'),# 12
     ('AgACAgIAAxkBAAMfX51yuXJ3RiEpNcjw9jWYKmBiBRgAAj-uMRslGPBI1mkAAfyT81nOW_fVli4AAwEAAwIAA3kAA3oTAwABGwQ', 'biology13'), # 13
     ('AgACAgIAAxkBAAMeX51ypQUIyrj8dOnnoR1Bsi-7o18AAj6uMRslGPBI5BxfiHfa7bomy9SXLgADAQADAgADeQAESgIAARsE', 'biology14'),# 14
     ('AgACAgIAAxkBAAMgX51y3GZNrQOq8zvc3_EOVgjMYlMAAkCuMRslGPBI3viUpRuceGITYmOaLgADAQADAgADeQADbjwAAhsE', 'biology15'), # 15
     ('AgACAgIAAxkBAAMhX51y9Kn5RcheSLLZRkqqPUmqWrwAAkGuMRslGPBI_6RgySb6r0iwTRKVLgADAQADAgADeQADOQEGAAEbBA', 'biology16'), # 16
     ('AgACAgIAAxkBAAMiX51zBqSw6KE9149bZfWOT-l3uDsAAkKuMRslGPBIUd6qdzTMtwiJRAWXLgADAQADAgADeQAD5GYCAAEbBA', 'biology17'),# 17
     ('AgACAgIAAxkBAAMjX51zFtQQg0PX5Q34fZkM-HyCaiMAAkOuMRslGPBIcRFhXI7x6jG6FKKWLgADAQADAgADeQADVVQDAAEbBA', 'biology18'), # 18
     ('AgACAgIAAxkBAAMkX51zJHHtkFwyC2Ikd59BXKxib0kAAkSuMRslGPBIgAGrOO9maN5KZRaYLgADAQADAgADeQADpHYCAAEbBA', 'biology19'),# 19
     ('AgACAgIAAxkBAAMlX51zN1UpWOVa6GyJS1Fz-rDhm-AAAkWuMRslGPBI4s5xGhHJNIVH4haVLgADAQADAgADeQADhvwFAAEbBA', 'biology20'),# 20
     ('AgACAgIAAxkBAAMmX51zQ8zG3istpVZ7tiwswoeqSjQAAkauMRslGPBI5O2JGT8lYKZPcmiXLgADAQADAgADeQADroYCAAEbBA', 'biology21'), # 21
     ('AgACAgIAAxkBAAMnX51zU4-vxT3GFklSZaKkdr8S8jIAAkeuMRslGPBIjfZu55KrEViR5T6WLgADAQADAgADeQADTbwDAAEbBA', 'biology22') # 22
     ]
for ii in i:
    sql.execute("SELECT id FROM name WHERE call_data  = (?)", (ii[1],))
    if sql.fetchone() is None:
        sql.execute(f'INSERT INTO name VALUES (?, ?)', ({ii[0]}, {ii[1]}))
        db.commit()
    else:
        pass
@dp.callback_query_handler(lambda call: True)
async def keyboard(call: CallbackQuery):
    if call.data == 'biology':
        sql.execute(f"SELECT id FROM name WHERE call_data = '{call.data}'")
        rows = sql.fetchall()
        r = []
        for row in rows:
            r.append(row)
        print(r)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2016-05-30
@gbg

For starters, your tar variable doesn't reset to 0 after you type six characters. And it should.

I
Ivan Yakushenko, 2020-11-01
@vanoi

sql.execute('SELECT id FROM name WHERE call_data  = (?)', (ii[1],))

sql.execute('INSERT INTO name VALUES (?, ?)', (ii[0], ii[1]))

sql.execute('SELECT id FROM name WHERE call_data = (?)', (call.data,))

S
soremix, 2020-11-01
@SoreMix

{ii[0]}, {ii[1]}

What for { } ?
sql.execute(f"SELECT id FROM name WHERE call_data = '{call.data}'")

You do not have a single biology value in the table, and he has nothing to give

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question