[英]Sqlite3 adding ID
class Personel():
def __init__(self, adsoyad, birim, telefon, cinsiyet):
self.adsoyad = adsoyad
self.birim = birim
self.telefon = telefon
self.cinsiyet = cinsiyet
class PersonelEnvanteri():
def __init__(self):
self.baglanti_olustur()
def baglanti_olustur(self):
self.baglanti = sqlite3.connect("personelenvanteri.db")
self.cursor = self.baglanti.cursor()
sorgu = "CREATE TABLE IF NOT EXISTS personeller (adsoyad TEXT, birim TEXT, telefon TEXT, cinsiyet TEXT)"
self.cursor.execute(sorgu)
self.baglanti.commit()
def baglantiyi_kes(self):
self.baglanti.close()
def personelEkle(self, personel):
sorgu = "INSERT INTO personeller VALUES (?, ?, ?, ?)"
self.cursor.execute(sorgu,(personel.adsoyad, personel.birim, personel.telefon, personel.cinsiyet))
self.baglanti.commit()
personelenvanteri = PersonelEnvanteri()
class App (tkinter)...
.
.
.
def personelEkleButon(self):
adsoyad = self.personelAdGiris.get()
birim = self.personelBirimGiris.get()
telefon = self.personelTelGiris.get()
if self.radiosecim == 1:
cinsiyet = "Erkek"
else:
cinsiyet = "Kadın"
yeniPersonel = Personel(adsoyad, birim, telefon, cinsiyet)
personelenvanteri.personelEkle(yeniPersonel)
print("Hello")
I need to use ID INTEGER PRIMARY KEY AUTOINCREMENT above, but I'm making a mistake somewhere, I couldn't run it.我需要使用上面的 ID INTEGER PRIMARY KEY AUTOINCREMENT,但我在某处犯了一个错误,我无法运行它。 What exactly do I need to do in these codes, where and what should I put?我到底需要在这些代码中做什么,我应该放在哪里以及放什么?
I'm getting a value missing error我收到一个值缺失错误
Add the ID
column when you create the table.创建表时添加ID
列。 But leave it out when you're inserting, and the ID will be assigned automatically.但在插入时将其保留,ID 将自动分配。
def baglanti_olustur(self):
self.baglanti = sqlite3.connect("personelenvanteri.db")
self.cursor = self.baglanti.cursor()
sorgu = """CREATE TABLE IF NOT EXISTS personeller (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
adsoyad TEXT,
birim TEXT,
telefon TEXT,
cinsiyet TEXT)"""
self.cursor.execute(sorgu)
self.baglanti.commit()
def baglantiyi_kes(self):
self.baglanti.close()
def personelEkle(self, personel):
sorgu = """INSERT INTO personeller (adsoyad, birim, telefon, cinsiyet)
VALUES (?, ?, ?, ?)"""
self.cursor.execute(sorgu,(personel.adsoyad, personel.birim, personel.telefon, personel.cinsiyet))
self.baglanti.commit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.