how to return correct value of update stmt

Discussion in 'Python' started by eight02645999@yahoo.com, Oct 19, 2005.

  1. Guest

    hi
    i use odbc to update a table in a database but i always get return
    value of -1
    even though i tried to return an integer. the table is updated though
    ....
    sql = """
    update table
    set column = 0
    where col = "%s"
    select @@rowcount

    """ % (var1)
    .....
    try:
    s = odbc.odbc(connectstring)
    cur = s.cursor()
    res = cur.execute(sql)
    s.commit()
    s.close()
    cur.close()
    s = None
    cur = None
    print res
    return res
    except:
    print 'error while processing ', sys.exc_type,sys.exc_value


    how to properly get a positive return ?
    thanks
    , Oct 19, 2005
    #1
    1. Advertising

  2. Steve Holden Guest

    wrote:
    > hi
    > i use odbc to update a table in a database but i always get return
    > value of -1
    > even though i tried to return an integer. the table is updated though
    > ...
    > sql = """
    > update table
    > set column = 0
    > where col = "%s"
    > select @@rowcount
    >
    > """ % (var1)
    > ....
    > try:
    > s = odbc.odbc(connectstring)
    > cur = s.cursor()
    > res = cur.execute(sql)
    > s.commit()
    > s.close()
    > cur.close()
    > s = None
    > cur = None
    > print res
    > return res
    > except:
    > print 'error while processing ', sys.exc_type,sys.exc_value
    >
    >
    > how to properly get a positive return ?
    > thanks
    >

    Is the table actually being updated?

    The definition of the cursor.execute() method in

    http://www.python.org/peps/pep-0249.html

    specifically says "Return values are not defined". So if you are seeing
    the database do the right thing I'd stop worrying about the return
    value. If exceptions aren't being raised and the database is doing what
    you want, what's the problem?

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
    Steve Holden, Oct 19, 2005
    #2
    1. Advertising

  3. Guest

    hi
    yes , the table is updated. Just feels "uncomfortable" with the return
    of -1.
    was also concerned that what if the actual table doesn't exist, will it
    return -1?
    anyway, i will go check it out ..
    thanks
    , Oct 19, 2005
    #3
    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. Eric DELAGE
    Replies:
    2
    Views:
    704
  2. Jay
    Replies:
    3
    Views:
    4,599
    William Ryan
    Oct 31, 2003
  3. Art

    eval with print stmt

    Art, Jul 29, 2004, in forum: Python
    Replies:
    1
    Views:
    284
    Mel Wilson
    Jul 29, 2004
  4. David

    Changing drop down select stmt

    David, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    276
    David
    Oct 20, 2006
  5. bigden007

    if..else stmt

    bigden007, Oct 22, 2007, in forum: Python
    Replies:
    5
    Views:
    388
    Bruno Desthuilliers
    Oct 22, 2007
Loading...

Share This Page