question about deleting records from mysql

Discussion in 'Python' started by nephish@xit.net, Jul 27, 2005.

  1. Guest

    Hey there,
    sorry , second question in as many days.
    i am trying to do some stuff with MySQLdb and the thing is, i can
    select records and such, but when i try to delete them, they dont
    really go away.

    like this

    >>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")

    240L
    >>> cursor.execute("SELECT * FROM table WHERE autoinc > 1000")

    0L

    so it looks like it worked, but when i use something else to look at
    the
    table (phpmyadmin, mysql-query-browser, knoda) the records are still
    there!

    what do i do?
     
    , Jul 27, 2005
    #1
    1. Advertising

  2. On 27 Jul 2005 04:29:33 -0700, <> wrote:
    > Hey there,
    > sorry , second question in as many days.
    > i am trying to do some stuff with MySQLdb and the thing is, i can
    > select records and such, but when i try to delete them, they dont
    > really go away.


    A fiver says you need to commit your changes.

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Jul 27, 2005
    #2
    1. Advertising

  3. nephish Guest

    Simon Brunning wrote:

    >On 27 Jul 2005 04:29:33 -0700, <> wrote:
    >
    >
    >>Hey there,
    >>sorry , second question in as many days.
    >>i am trying to do some stuff with MySQLdb and the thing is, i can
    >>select records and such, but when i try to delete them, they dont
    >>really go away.
    >>
    >>

    >
    >A fiver says you need to commit your changes.
    >
    >
    >

    ok, do i do that with cursor.commit() ?
    thanks
     
    nephish, Jul 27, 2005
    #3
  4. Mage Guest

    nephish wrote:

    >Simon Brunning wrote:
    >
    >
    >
    >>On 27 Jul 2005 04:29:33 -0700, <> wrote:
    >>
    >>
    >>
    >>
    >>>Hey there,
    >>>sorry , second question in as many days.
    >>>i am trying to do some stuff with MySQLdb and the thing is, i can
    >>>select records and such, but when i try to delete them, they dont
    >>>really go away.
    >>>
    >>>
    >>>
    >>>

    >>A fiver says you need to commit your changes.
    >>
    >>
    >>
    >>
    >>

    >ok, do i do that with cursor.commit() ?
    >thanks
    >
    >

    Yes, or maybe you should write a lightweight layer between the dbapi and
    your program which can turn on and off the autocommit by calling
    "commit" and "begin" as query. I did this in my pgsql layer. Using
    transactions every time is almost as bad as never using them.

    Mage
     
    Mage, Jul 27, 2005
    #4
  5. Guest

    ok. did this

    >>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")

    245L
    >>> cursor.commit()


    i got an AttributeError 'Cursor' object has no attribute 'commit'

    hmm. what should i do now?
    the stuff about writing a lightweight layer between the dbapi and the
    program shot right over my head. sorry, but thanks
     
    , Jul 27, 2005
    #5
  6. # / 2005-07-27 05:12:46 -0700:
    > ok. did this
    >
    > >>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")

    > 245L
    > >>> cursor.commit()

    >
    > i got an AttributeError 'Cursor' object has no attribute 'commit'
    >
    > hmm. what should i do now?


    RTFM, e. g. here:

    http://cvs.sourceforge.net/viewcvs.py/mysql-python/MySQLdb/doc/MySQLdb.txt?rev=1.1&view=auto

    --
    How many Vietnam vets does it take to screw in a light bulb?
    You don't know, man. You don't KNOW.
    Cause you weren't THERE. http://bash.org/?255991
     
    Roman Neuhauser, Jul 27, 2005
    #6
  7. Rowdy Guest

    wrote:
    > ok. did this
    >
    >
    >>>>cursor.execute("DELETE FROM table WHERE autoinc > 1000")

    >
    > 245L
    >
    >>>>cursor.commit()

    >
    >
    > i got an AttributeError 'Cursor' object has no attribute 'commit'
    >
    > hmm. what should i do now?
    > the stuff about writing a lightweight layer between the dbapi and the
    > program shot right over my head. sorry, but thanks
    >


    IIRC it is the connection that can commit(), not the cursor.

    Rowdy
     
    Rowdy, Jul 27, 2005
    #7
  8. nephish Guest

    Man, thanks for the link. and the tip. i am testing
    the db.commit() and printing the doc right now.
    thanks again.


    On 07/27/2005 07:43:24 AM, Rowdy wrote:
    > wrote:
    >> ok. did this
    >>
    >>
    >>>>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")

    >>
    >> 245L
    >>
    >>>>> cursor.commit()

    >>
    >>
    >> i got an AttributeError 'Cursor' object has no attribute 'commit'
    >>
    >> hmm. what should i do now?
    >> the stuff about writing a lightweight layer between the dbapi and the
    >> program shot right over my head. sorry, but thanks
    >>

    >
    > IIRC it is the connection that can commit(), not the cursor.
    >
    > Rowdy
    >
     
    nephish, Jul 27, 2005
    #8
  9. nephish wrote:
    > Man, thanks for the link. and the tip. i am testing
    > the db.commit() and printing the doc right now.
    > thanks again.


    If it's any help, using

    cursor.execute("set autocommit = 1")

    before doing anything else works nicely unless you actually need
    transactions.

    The Cog
     
    Cantankerous Old Git, Jul 27, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick.O.Ige
    Replies:
    0
    Views:
    690
    Patrick.O.Ige
    Nov 3, 2005
  2. Dan M
    Replies:
    2
    Views:
    258
    Dan M
    Dec 15, 2005
  3. Harry Barker
    Replies:
    2
    Views:
    537
    Alf P. Steinbach
    Apr 19, 2006
  4. Daz01

    Deleting records

    Daz01, Dec 7, 2006, in forum: C++
    Replies:
    3
    Views:
    359
    Salt_Peter
    Dec 7, 2006
  5. crea
    Replies:
    2
    Views:
    427
    Nobody
    Dec 28, 2012
Loading...

Share This Page