A
A
Alexey Mikhalev2020-07-19 18:14:18
Python
Alexey Mikhalev, 2020-07-19 18:14:18

Why is it not connecting to the SQLightStudio database?

I am writing a bot. The task is to connect to the database and assign the data to a variable, which the bot will then display. Why is there an error in the console:

File "bot.py", line 13, in product
    with connect('database.db') as connection:
NameError: name 'connect' is not defined

The code:
def product(name ):
    with connect('database.db') as connection:
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM catalog WHERE name = ? ", (name,))
        result = cursor.fetchone()
        return result

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-07-19
@mikkhalev

Something like this should be:

import sqlite3

def product(name):
    with sqlite3.connect('database.db') as connection:
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM catalog WHERE name = ? ", (name,))
        return cursor.fetchone()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question