T
T
Timtaran2020-08-19 14:17:06
Python
Timtaran, 2020-08-19 14:17:06

Why is sqlite3 not working?

I run the code:

import help_module as hm
import sqlite3
import time
connection = sqlite3.connect('Путь', check_same_thread = False)
cursor = connection.cursor()
while True:
  for i in range(999999):
    timer_status = hm.give_user_information2(i, 'timer', 'users')
    if timer_status == 1:
      neded_time = hm.give_user_information2(i, 'nt', 'users')
      time = hm.give_user_information2(i, 'time', 'users')
      if neded_time <= time:
        vk.messages.send(
          message=hm.give_user_information2(i, 'timer_text', 'users'),
          peer_id=hm.give_user_information2(i, 'id', 'users'),
          random_id=get_random_id()
              )
        cursor.execute("UPDATE users SET timer = 0 WHERE uid = " + str(i))
        connection.commit()
    cursor.execute("UPDATE users SET time = "+str(time.time())+" WHERE uid = " + str(i))

Mistake:
Traceback (most recent call last):
  File "Путь", line 17, in <module>
    timer_status = hm.give_user_information2(i, 'timer', 'users')
  File "Путь\help_module.py", line 11, in give_user_information2
    return str(cursor.execute("SELECT " + info + " FROM " + table + " WHERE uid = " + str(id)).fetchone()[0])
TypeError: 'NoneType' object is not subscriptable

The part of the module where the error occurs:
def give_user_information2(id, info, table):
  connection = sqlite3.connect('Путь')
  cursor = connection.cursor()
  return str(cursor.execute("SELECT " + info + " FROM " + table + " WHERE uid = " + str(id)).fetchone()[0])

Edited:
If output neded_time outputs 0:
timer_status = hm.give_user_information2(i, 'timer', 'users')
    print(timer_status)

0
Traceback (most recent call last):
  File "Путь", line 17, in <module>
    timer_status = hm.give_user_information2(i, 'timer', 'users')
  File "Путь\help_module.py", line 11, in give_user_information2
    return str(cursor.execute("SELECT " + info + " FROM " + table + " WHERE uid = " + str(id)).fetchone()[0])
TypeError: 'NoneType' object is not subscriptable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Ternick, 2020-08-19
@Timtaran

1) sqlite always plows !!!!
2) The error occurs because you are trying to do this:

arr = None
arr[0]

And it turns out that way because someone does not check if there are entries in the database for this request!
You can solve the issue by making a simple check that the response from cursor.execute is not None !

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question