Python Forum
Deleting from a database...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting from a database...
#1
Hi Guys,

I am just starting with Python and am making a small "app" for my first project.

One of the problems I am having is that when I run this it does exactly what i need it to do BUT when I shut it down and then re-run it it adds the data to the file again rather than over writing it, which makes it tricky to then use the data for the next part of my cunning plan.

I realise this is probably pretty easy but all the examples I have seen are just over my head as of yet, can anyone shed some light on this for me please?




import sqlite3, csv

conn = sqlite3.connect("LE2.db")
c = conn.cursor()

sql = """
        CREATE TABLE IF NOT EXISTS TokenTable (
            
    ad1 TEXT,
    ad2 TEXT,
    ad3 TEXT


        )"""

c.execute(sql)

with open("LE.csv", "r") as file:    
    no_records = 0
    for row in file:

        c.execute("INSERT INTO TokenTable VALUES (?,?,?)", row.split(","))
        conn.commit()
        no_records += 1


Thanks,

Mort
Reply


Messages In This Thread
Deleting from a database... - by Mort101 - Aug-20-2020, 06:27 PM
RE: Deleting from a database... - by ndc85430 - Aug-20-2020, 07:46 PM
RE: Deleting from a database... - by Mort101 - Aug-20-2020, 11:12 PM
RE: Deleting from a database... - by jefsummers - Aug-22-2020, 06:52 PM
RE: Deleting from a database... - by ibreeden - Aug-23-2020, 08:14 PM

Forum Jump:

User Panel Messages

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