R
R
Ruslan Mordovanech2021-12-23 15:27:49
Python
Ruslan Mordovanech, 2021-12-23 15:27:49

Why doesn't it write adjacent sqlite columns in the table?

mport sqlite3
import json



def read_sqlite_table():
    base = sqlite3.connect('database.db')
    cur = base.cursor()
    cur.execute('SELECT name FROM list')
    reader = cur.fetchmany()
    for row in reader:
        with open('new_data.json', 'r', encoding='utf-8') as f:
            file_content = f.read()
            data1 = json.loads(file_content)
            d = row[0]
            for i in data1:
                if d.upper() in i['case_involved'].upper().replace("\"", " ").replace("\'", " "):
                    news = f"номер:{i['case']}, " \
                           f"дата:{i['date']}"
                    cur.execute("INSERT INTO list(description, result) VALUES(?, ?)", (news, 'yes'))
                    base.commit()
            else:
                cur.execute("INSERT INTO list(description, result) VALUES(?, ?)", (' ', ' '))
                base.commit()
                base.close()

    
if __name__ == '__main__':
    read_sqlite_table()

The essence of the design is that we read the table and check if there are names in the list and if we write a mark to the table.
But I thought that the record of the adjacent column could be added, but he continues it
. And I noticed that it does not skip the place where the names do not match. I set what gave out one term, but now it does not give out more than one.
61c46b205509d280467143.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Gordinskiy, 2021-12-23
@Hery1

INSERT - creates a new entry in the database.
Update needs UPDATE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question