Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sqllite column insert
#1
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()
Reply
#2
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/
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
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
[Image: LEHoEPo.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb Insert a new column for Key Value brunolelli 0 1,510 Mar-20-2021, 03:27 PM
Last Post: brunolelli
  Insert list in particular column! Help! vndywarhol 0 2,503 Sep-17-2018, 11:14 PM
Last Post: vndywarhol
  Insert using psycopg giving syntax error near "INSERT INTO" olgethorpe 4 15,717 Jul-21-2017, 07:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020