Browse Source

Python/api-hour update fix (#2541)

Nate 8 years ago
parent
commit
5f2262de17

+ 2 - 1
frameworks/Python/api_hour/aiohttp.web/hello/services/mysql.py

@@ -36,8 +36,9 @@ def update_random_records(container, limit):
             yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1',
             yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1',
                                    {'idx': randint(1, 10000)})
                                    {'idx': randint(1, 10000)})
             world = yield from cur.fetchone()
             world = yield from cur.fetchone()
+            world['RandomNumber'] = randint(1, 10000)
             yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s',
             yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s',
-                                   {'random_number': randint(1, 10000), 'idx': world['Id']})
+                                   {'random_number': world['RandomNumber'], 'idx': world['Id']})
             results.append(world)
             results.append(world)
     return results
     return results
 
 

+ 3 - 2
frameworks/Python/api_hour/aiohttp.web/hello/services/world.py

@@ -34,8 +34,9 @@ def update_random_records(container, limit):
             yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1',
             yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1',
                                    {'idx': randint(1, 10000)})
                                    {'idx': randint(1, 10000)})
             world = yield from cur.fetchone()
             world = yield from cur.fetchone()
+            world['RandomNumber'] = randint(1, 10000)
             yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s',
             yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s',
-                                   {'random_number': randint(1, 10000), 'idx': world['Id']})
+                                   {'random_number': world['RandomNumber'], 'idx': world['Id']})
             results.append(world)
             results.append(world)
     return results
     return results
 
 
@@ -51,4 +52,4 @@ def get_fortunes(container):
 
 
     fortunes.sort(key=itemgetter('message'))
     fortunes.sort(key=itemgetter('message'))
 
 
-    return fortunes
+    return fortunes