odbc script

Chris splungent at aol.com
Sun Dec 19 00:11:20 EST 2004


Hello,
          I posted a while back about a newbie database question and got a 
lot of great help here.  My script that I am creating has come a long way 
(For me!) and almost does what I need it too.  I am basicly using a 
dictionary to update a access database using an odbc connector.  I am able 
to connect and it seems that I am able to loop through the code to update 
all the rows I need to.  The one weird bug I seem to get is what ever is the 
last loop through doesn't seem to update the database?
Here is my code:
**********************************************************************************
import dbi
import odbc
invdictionary = {1112:0 ,1111:0 ,1129:0 ,1139:1 ,1149:1 ,1159:0 ,1169:0 
,1179:0 ,1189:1 ,1199:0} # ( key : value )
invd = invdictionary.items()                     # convert to a list to loop 
through
myconn = odbc.odbc('testpy')                # connect to database
mycursor = myconn.cursor()
for x in invd:
    mycursor.execute('Update Categories Set StockStatus=? Where ProductID=? 
;',(x[1], x[0]))    # run my sql update
    print x[0], x[1]                                   # Just to help me 
debug
mycursor.close()
myconn.close()
print invdictionary                                  # Just to help me debug
print invd                                               # Just to help me 
debug

Here is the output:
*********************************************************************************
1189 1
1159 0
1129 0
1199 0
1169 0
1139 1
1111 0
1112 0
1179 0
1149 1
{1189: 1, 1159: 0, 1129: 0, 1199: 0, 1169: 0, 1139: 1, 1111: 0, 1112: 0, 
1179: 0, 1149: 1}
[(1189, 1), (1159, 0), (1129, 0), (1199, 0), (1169, 0), (1139, 1), (1111, 
0), (1112, 0), (1179, 0), (1149, 1)]
************************************************************************************
After I run this script All the values update correctly except the 1149 
value which never changes in the database.
I messed with this for a while and found by adding items to the dictionary 
that it never seems to update whatever is the last item to go through the 
loop.
I thought I would float it on here and see if this isn't an obvious mistake 
that I just can't see.  Any help is appreciated.





More information about the Python-list mailing list