]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Use proper SQL construction in hwsim test reporting
authorJohannes Berg <johannes.berg@intel.com>
Wed, 30 Oct 2013 17:19:07 +0000 (19:19 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 30 Oct 2013 17:19:07 +0000 (19:19 +0200)
Don't construct SQL strings on the fly but instead use the
argument placeholders.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>

tests/hwsim/run-tests.py

index abe26f3593417d4abbab9628c44b78557d1cae0d..d288f9468d22ee8207791ba54af9fa881616ef15 100755 (executable)
@@ -38,13 +38,14 @@ def report(conn, build, commit, run, test, result, diff):
             build = ''
         if not commit:
             commit = ''
-        sql = "INSERT INTO results(test,result,run,time,duration,build,commitid) VALUES('" + test.replace('test_', '', 1) + "', '" + result + "', " + str(run) + ", " + str(time.time()) + ", " + str(diff.total_seconds()) + ", '" + build + "', '" + commit + "')"
+        sql = "INSERT INTO results(test,result,run,time,duration,build,commitid) VALUES(?, ?, ?, ?, ?, ?, ?)"
+        params = (test.replace('test_', '', 1), result, run, time.time(), diff.total_seconds(), build, commit)
         try:
-            conn.execute(sql)
+            conn.execute(sql, params)
             conn.commit()
         except Exception, e:
             print "sqlite: " + str(e)
-            print "sql: " + sql
+            print "sql: %r" % (params, )
 
 def main():
     test_file = None
@@ -117,12 +118,13 @@ def main():
         for t in tests:
             print t.__name__ + " - " + t.__doc__
             if conn:
-                sql = 'INSERT OR REPLACE INTO tests(test,description) VALUES ("' + t.__name__.replace('test_', '', 1) + '", "' + t.__doc__ + '")';
+                sql = 'INSERT OR REPLACE INTO tests(test,description) VALUES (?, ?)'
+                params = (t.__name__.replace('test_', '', 1), t.__doc__)
                 try:
-                    conn.execute(sql)
+                    conn.execute(sql, params)
                 except Exception, e:
                     print "sqlite: " + str(e)
-                    print "sql: " + sql
+                    print "sql: %r" % (params,)
         if conn:
             conn.commit()
             conn.close()