Sep-29-2017, 11:03 PM
I want to make a function that will search all tables of a sqlite database for a string, if it does not find that striing, then it will write it into one of the tables , i was going this way i don't know if it is a good direction:
import sqlite3 import random conn = sqlite3.connect('listatest.db') c = conn.cursor() tablelist = ('unu', 'doi', 'trei','patru') echipa1= "test3" echipa2 = "test2" scor1="testsc1" scor2 ="testsc2" cota =5 miza = 3 stare = 2 def creat_tables(): for tablename in tablelist: create = 'CREATE TABLE IF NOT EXISTS ' + tablename + ' (numar_par INTEGER PRIMARY KEY, echipa1 TEXT, scor1 TEXT, scor2 TEXT, echipa2 TEXT,cota INT, miza INT, stare INT)' c.execute(create) def incarca(): for tablename in tablelist: c.execute('SELECT * FROM ' + tablename + ' WHERE echipa1 = ?', (echipa1,)) xx = c.fetchone() if xx is None: z = 1 if z == 1: c.execute( "INSERT INTO " + tablename + "( echipa1,scor1, scor2, echipa2, cota, miza, stare ) VALUES (?,?,?,?,?,?,?)", (echipa1, scor1, scor2, echipa2, cota, miza, stare)) conn.commit() c.execute('SELECT * FROM ' + tablename + ' WHERE echipa1 = ?', (echipa1,)) xx = c.fetchone() if xx is None: z = 1 else: z=0Right now my code will write the values in all tables, but i want to write it only in one table