summaryrefslogtreecommitdiffstats
path: root/scripts/uploadresults.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/uploadresults.py')
-rwxr-xr-xscripts/uploadresults.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/scripts/uploadresults.py b/scripts/uploadresults.py
index 460207f..f0d5bb3 100755
--- a/scripts/uploadresults.py
+++ b/scripts/uploadresults.py
@@ -171,7 +171,7 @@ def findOrInsertId(table, value, *args):
#print "value: >" + value + "<, ",
query_result = execQuery(
- "SELECT id FROM " + table + " WHERE value = '" + str(value) + "';")
+ "SELECT id FROM " + table + " WHERE value = %s", (value,))
if len(query_result) == 1:
# Found, so return ID:
#print "returning existing ID: >" + str(query_result[0][0]) + "<"
@@ -180,14 +180,16 @@ def findOrInsertId(table, value, *args):
# Not found, so insert:
query = "INSERT INTO " + table + " (value"
for i in range(0, len(args), 2):
- query += ", " + str(args[i])
- query += ") VALUES ('" + str(value) + "'"
+ query += ", " + args[i]
+ query += ") VALUES (%s"
+ values = [value]
for i in range(0, len(args), 2):
- query += ", " + str(args[i + 1])
+ query += ", %s"
+ values.append(args[i + 1])
# ... and retrieve ID:
- query += ") RETURNING id;"
- query_result = execQuery(query)
+ query += ") RETURNING id"
+ query_result = execQuery(query, values)
assert len(query_result) == 1
#print "returning new ID: >" + str(query_result[0][0]) + "<"
@@ -198,10 +200,10 @@ def findOrInsertId(table, value, *args):
def uploadToDatabase(host, platform, branch, sha1, results):
# Append a row to the 'upload' table (to record this upload event) ...
- execQuery("INSERT INTO upload DEFAULT VALUES;", False)
+ execQuery("INSERT INTO upload DEFAULT VALUES", (), False)
# Retrieve the ID of the row we just inserted ...
- uploadId = execQuery("SELECT currval('upload_id_seq');")[0][0]
+ uploadId = execQuery("SELECT currval('upload_id_seq')", ())[0][0]
hostId = findOrInsertId("host", host)
platformId = findOrInsertId("platform", platform)
@@ -213,9 +215,9 @@ def uploadToDatabase(host, platform, branch, sha1, results):
contextId = execQuery(
"INSERT INTO context"
" (hostId, platformId, branchId, sha1Id)"
- " VALUES (%d, %d, %d, %d)"
- " RETURNING id;"
- % (hostId, platformId, branchId, sha1Id))[0][0]
+ " VALUES (%s, %s, %s, %s)"
+ " RETURNING id",
+ (hostId, platformId, branchId, sha1Id))[0][0]
# Append rows to the 'result' table ...
for result in results:
@@ -228,14 +230,12 @@ def uploadToDatabase(host, platform, branch, sha1, results):
"metric", result['metric'], "lowerIsBetter",
result['lowerIsBetter'])
- query = (
+ execQuery(
"INSERT INTO result"
" (contextId, benchmarkId, value, valid, metricId, uploadId)"
- " VALUES (%d, %d, %f, %s, %d, %d);"
- % (contextId, benchmarkId, result['value'], result['valid'],
- metricId, uploadId))
-
- execQuery(query, False)
+ " VALUES (%s, %s, %s, %s, %s, %s)",
+ (contextId, benchmarkId, result['value'], result['valid'],
+ metricId, uploadId), False)
# Write to database:
commit()
@@ -250,7 +250,7 @@ def rankingsExist(options):
textToId('sha1', options["sha1"]))
matches = execQuery(
- "SELECT id FROM ranking WHERE context2Id = %d LIMIT 1;" % context_id)
+ "SELECT id FROM ranking WHERE context2Id = %s LIMIT 1", (context_id,))
return len(matches) > 0
@@ -278,8 +278,8 @@ def contextComplete(options):
context_id = getContextIdFromNames(options)
sample_size = execQuery(
"SELECT count(*) FROM"
- " (SELECT DISTINCT uploadId from result where contextId=%d) AS foo;"
- % context_id)[0][0]
+ " (SELECT DISTINCT uploadId from result where contextId = %s) AS foo",
+ (context_id,))[0][0]
return sample_size >= max_sample_size
@@ -321,7 +321,7 @@ def execComputeRankings(options, new_context):
p = Popen(cmd, stdout = PIPE, stderr = PIPE)
stdout, stderr = p.communicate()
if (p.returncode != 0):
- print "failed to execute command '" + cmd + "':"
+ print "failed to execute command '" + str(cmd) + "':"
print " return code:", p.returncode
print " stdout: >%s<" % stdout.strip()
print " stderr: >%s<" % stderr.strip()