How to check existing data in comics?

Asked

Viewed 737 times

0

I need to check if a data already exists in the BD before registering it in python, where the bd has the Videocapture table and its attributes are id, name, value.... need to verify the name before registering in the python comic...

  • You’d better set the column of the bank as Unic and try to insert straight, without checking by select. If the column already exists in the bank, an exception will be triggered; you just capture it and treat it.

  • You can use the operator EXISTS, see only: https://www.w3schools.com/sql/sql_exists.asp

1 answer

0


Just do a SELECT with the data you need to check if it exists in this table. If SELECT does not return data it is because the record does not exist otherwise the record exists.

  • I’m a beginner, you can quote an example?

  • I found a way

  • 1

    import sqlite3 import os.path Connection = sqlite3.connect('config.db') c = Connection.cursor() def create_table(): c.execute('CREATE TABLE IF NOT EXISTS Videocapture (id INTEGER PRIMARY KEY AUTOINCREMENT, name value, text)') sql = 'SELECT * FROM Videocapture WHERE name = ? ' search = 'Numcam' status = 0 for Row in c.execute(sql, (search,): status = 1 Else: if status == 1: print('Cadja strado') Else: c.run("INSERT INTO Videocapture(name, value) VALUES('Numcam', 4)")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.