D
D
dasehak2020-09-26 18:13:18
Python
dasehak, 2020-09-26 18:13:18

How to extract a variable from a SQLite database?

How can I pull in a variable from a SQLite database?
Code example:

import sqlite3 as sql

conn = sql.connect('database.db')
cur = conn.cursor()

cur.execute("""CREATE TABLE IF NOT EXISTS test(test_int INT)""")
conn.commit()

print(test_int) #Нужно вывести переменную test_int из базы данных

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dr. Bacon, 2020-09-26
@bacon

open SQL textbook and learn

P
Peter Pitaev, 2020-09-26
@XXocTT

import sqlite3
db = sqlite3.connect('database.db')
cur = db.cursor()
a = str(cur.execute('SELECT column_name FROM table_name WHERE id = row_id').fetchone()[0])
print( a)

P
PavelMos, 2020-09-26
@PavelMos

test_int INT is not a variable here, but the name of a column in the test table, where records of the int type are stored. So far it hasn't written anything.

H
HemulGM, 2020-09-27
@HemulGM

The database has no variables. There are tables. These are rows and columns. Insert lines, read lines. Then think for yourself.
Read books, study.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question