Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:51 PM, John Gordon wrote: > You probably meant something like this instead: > > sql = "DELETE FROM tblc_users WHERE user_email=%s" % line > > This will substitute the value of line for the %s. > > However, most (all?) SQL databases require string values to be enclosed

Re: Newbie needing some help

2014-08-08 Thread John Gordon
In Matt Smith writes: > 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 > im

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor > wrote: > > However, I'd recommend re-raising the exception after rolling back the > > transaction with a bare "raise" statement right after the db.rollback() > - at > > the absolute minimum, yo

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 5:13 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor > wrote: > > try: > > action > > commit > > finally: > > rollback > > If commit/rollback automatically opens a new transaction, this would > just roll back an empty transaction - not

Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 10:32 AM, Chris Kaynor wrote: > The main issue I can see with that idea is that the exception will keep a > reference to the database connection (as with all locals), so unless you > explicitly close it within a finally clause, the database connection could > still be left h

Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor wrote: > try: > action > commit > finally: > rollback If commit/rollback automatically opens a new transaction, this would just roll back an empty transaction - not a big deal. But yes, I do see what you're looking at here. However, struct

Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor wrote: > However, I'd recommend re-raising the exception after rolling back the > transaction with a bare "raise" statement right after the db.rollback() - at > the absolute minimum, you should log the error. This will likely let you see > what your pro

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 12:07 PM, Matt Smith 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

Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 5:07 AM, Matt Smith wrote: > # 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 i

Re: Newbie needing some help

2014-08-08 Thread Mark Lawrence
On 08/08/2014 20:07, Matt Smith 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 i

Re: Newbie needing some help

2014-08-08 Thread Larry Martell
On Fri, Aug 8, 2014 at 3:07 PM, Matt Smith 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 cod

Newbie needing some help

2014-08-08 Thread Matt Smith
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/smi