R
R
RockyMotion2019-04-09 20:58:50
Python
RockyMotion, 2019-04-09 20:58:50

How to get all parameters from sqlite database?

I need to check all values ​​before entering into the database and if there is an exact match, then get the id of this line, if not, then get 0 in response. I
wrote the following script:

def chek_db(a):
    conn = sqlite3.connect('database.sqlite')
    res = conn.execute("SELECT q_id, q_title FROM q_main WHERE q_title LIKE" + '\'' + a + '\'')
    res1 = len(res.fetchall())

    if res1 == 0:
        result = 0
    else: result = 1

    return (result)

I tried to upgrade it so that it gave q_id in response, but nothing happens.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xDimus, 2019-04-09
@xDimus

and how did you try? like it should be

res2 = conn.fetchall()
else:
    result = res2[0][0]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question