mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
fix query syntax: % operator bad
This commit is contained in:
parent
c661c8a74e
commit
6c8b9d5277
1 changed files with 19 additions and 20 deletions
|
@ -17,13 +17,11 @@ def join(req, devID, room, lang = 1, nInGame = 2, nHere = 1, inviteID = None):
|
||||||
connname = None
|
connname = None
|
||||||
con = psycopg2.connect(database='xwgames')
|
con = psycopg2.connect(database='xwgames')
|
||||||
|
|
||||||
query = """UPDATE games SET njoined = njoined + %d
|
query = """UPDATE games SET njoined = njoined + %s
|
||||||
WHERE lang = %d AND nTotal = %d AND room = '%s' AND njoined + %d <= ntotal
|
WHERE lang = %s AND nTotal = %s AND room = %s AND njoined + %s <= ntotal
|
||||||
RETURNING connname"""
|
RETURNING connname"""
|
||||||
query = query % (nHere, lang, nInGame, room, nHere)
|
|
||||||
print(query)
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute(query)
|
cur.execute(query, (nHere, lang, nInGame, room, nHere))
|
||||||
for row in cur:
|
for row in cur:
|
||||||
connname = row[0]
|
connname = row[0]
|
||||||
print 'got:', connname
|
print 'got:', connname
|
||||||
|
@ -31,10 +29,8 @@ def join(req, devID, room, lang = 1, nInGame = 2, nHere = 1, inviteID = None):
|
||||||
if not connname:
|
if not connname:
|
||||||
connname = str(random.randint(0, 10000000000))
|
connname = str(random.randint(0, 10000000000))
|
||||||
query = """INSERT INTO games (connname, room, lang, ntotal, njoined)
|
query = """INSERT INTO games (connname, room, lang, ntotal, njoined)
|
||||||
values ('%s', '%s', %d, %d, %d) RETURNING connname; """
|
values (%s, %s, %s, %s, %s) RETURNING connname; """
|
||||||
query %= (connname, room, lang, nInGame, nHere)
|
cur.execute(query, (connname, room, lang, nInGame, nHere))
|
||||||
print(query)
|
|
||||||
cur.execute(query)
|
|
||||||
for row in cur:
|
for row in cur:
|
||||||
print row
|
print row
|
||||||
else:
|
else:
|
||||||
|
@ -149,17 +145,19 @@ def main():
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
args = sys.argv[2:]
|
args = sys.argv[2:]
|
||||||
if cmd == 'query':
|
try :
|
||||||
result = query(None, json.dumps(args))
|
if cmd == 'query':
|
||||||
elif cmd == 'post':
|
result = query(None, json.dumps(args))
|
||||||
# Params = { 'data' : 'V2VkIE9jdCAxOCAwNjowNDo0OCBQRFQgMjAxNwo=' }
|
elif cmd == 'post':
|
||||||
# params = json.dumps(params)
|
# Params = { 'data' : 'V2VkIE9jdCAxOCAwNjowNDo0OCBQRFQgMjAxNwo=' }
|
||||||
# print(post(None, params))
|
# params = json.dumps(params)
|
||||||
None
|
# print(post(None, params))
|
||||||
elif cmd == 'join':
|
pass
|
||||||
result = join(None, 1, args[0])
|
elif cmd == 'join':
|
||||||
elif cmd == 'kill':
|
result = join(None, 1, args[0], int(args[1]), int(args[2]))
|
||||||
result = kill( None, json.dumps([{'relayID': args[0], 'seed':int(args[1])}]) )
|
elif cmd == 'kill':
|
||||||
|
result = kill( None, json.dumps([{'relayID': args[0], 'seed':int(args[1])}]) )
|
||||||
|
except : pass
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
print '->', result
|
print '->', result
|
||||||
|
@ -167,6 +165,7 @@ def main():
|
||||||
print 'USAGE: query [connname/hid]*'
|
print 'USAGE: query [connname/hid]*'
|
||||||
# print ' post '
|
# print ' post '
|
||||||
print ' kill <relayID> <seed>'
|
print ' kill <relayID> <seed>'
|
||||||
|
print ' join <roomName> <lang> <nTotal>'
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue