Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75907
| References | <CANhUTb9tEnT=uTMhdA+Fd2zJTMauo1BWkX2dgcE0dG_H5arx9Q@mail.gmail.com> |
|---|---|
| Date | 2014-08-08 17:43 -0400 |
| Subject | Re: Newbie needing some help |
| From | Larry Martell <larry.martell@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12763.1407534242.18130.python-list@python.org> (permalink) |
On Fri, Aug 8, 2014 at 3:07 PM, Matt Smith <smithmm@tblc.org> wrote:
> I am trying to write a program that will loop through a text file and delete
> rows in a mysql database.
>
> It seemingly runs but I don't see anything getting deleted in the db.
> Is there anything apparent that I am missing?
>
> This is the code:
> #!/usr/bin/python
> import mysql.connector
> #
> f=open('/home/smithm/email-list.txt', 'r')
> for line in f:
> #<do something with line>
> # Open database connection
> db = mysql.connector.connect(user="xx", password="xx",
> host="localhost", database="xx")
>
> # prepare a cursor object using cursor() method
> cursor = db.cursor()
>
> # Prepare SQL query to DELETE required records
> sql = "DELETE FROM tblc_users WHERE user_email=%s, % (line)"
> try:
> # Execute the SQL command
> cursor.execute(sql)
> # Commit your changes in the database
> db.commit()
> except:
> # Rollback in case there is any error
> db.rollback()
>
> # disconnect from server
> db.close()
Run it in the debugger, set a BP after you create the sql, print it
out, and cut and paste it into an interactive sql session and you'll
see what the issues are.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Newbie needing some help Larry Martell <larry.martell@gmail.com> - 2014-08-08 17:43 -0400
csiph-web