Python Forum

Full Version: Sqllite column insert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I want to add the data from the text file to the column named "firma" in sqlite. What should I do?


import sqlite3

vt = sqlite3.connect("AyGrupDatabase.sqlite")
im = vt.cursor()
im.execute("CREATE TABLE IF NOT EXISTS firma_giris (firma,kullanici,kod,sistem,isveren,araci)")

dosya = open("sirket.txt","r",encoding="utf-8")
for i in dosya:
    i=i[:-1]
    im.execute("INSERT INTO firma_giris(firma) values(?) ",(i))

vt.commit()
Your query structure is wrong when creating the table.
Have a look at these links
https://www.tutorialspoint.com/sqlite/sq..._table.htm
https://www.sqlitetutorial.net/sqlite-create-table/
To create a table you need to use this syntax:

im.execute('CREATE TABLE IF NOT EXISTS firma_giris (firma INTEGER, kullanici TEXT, kod TEXT, sistem TEXT, isveren TEXT, araci TEXT)')
And on for you can do this:

for i in dosya:
    i=i[:-1]
    im.execute(f"INSERT INTO firma_giris(firma) values({i})")
Hope that helps Big Grin