]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
fixed SQL queries
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 30 Oct 2011 18:13:56 +0000 (19:13 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 28 Nov 2011 13:39:53 +0000 (14:39 +0100)
src/libimcv/plugins/imv_attestation/attest.c

index 5210cd632f5f4527834da6d4f08fa7fc2a006b65..8fbfb200bc3b6358b235f75810a0aa9f43d6762d 100644 (file)
@@ -190,8 +190,10 @@ static void list_hashes(pts_meas_algorithms_t algo)
 
        e = db->query(db,
                        "SELECT f.id, f.path, p.name, fh.hash, fh.directory "
-                       "FROM files AS f, products AS p, file_hashes AS fh "
-                       "WHERE fh.algo = ? AND f.id = fh.file AND p.id = fh.product "
+                       "FROM file_hashes AS fh "
+                       "JOIN files AS f ON f.id = fh.file "
+                       "JOIN products AS p ON p.id = fh.product "
+                       "WHERE fh.algo = ? "
                        "ORDER BY fh.directory, f.path, p.name",
                        DB_INT, algo, DB_INT, DB_TEXT, DB_TEXT, DB_BLOB, DB_INT);
        if (e)
@@ -203,11 +205,11 @@ static void list_hashes(pts_meas_algorithms_t algo)
                                if (did != did_old)
                                {
                                        get_directory(did, &dir);
+                                       did_old = did;
                                }
                                printf("%3d: %s%s%s\n", fid,
                                           dir, slash(dir, file) ? "/" : "", file);
                                fid_old = fid;
-                               did_old = did;
                        }
                        printf("     %#B '%s'\n", &hash, product);
                        count++;
@@ -236,9 +238,10 @@ static void list_hashes_for_file(pts_meas_algorithms_t algo, char *file, int fid
        {
                e = db->query(db,
                                "SELECT p.name, fh.hash, fh.directory "
-                               "FROM products AS p, file_hashes AS fh "
+                               "FROM file_hashes AS fh "
                                "JOIN files AS f ON f.id = fh.file "
-                               "WHERE fh.algo = ? AND f.id = ? AND p.id = fh.product "
+                               "JOIN products AS p ON p.id = fh.product "
+                               "WHERE fh.algo = ? AND f.id = ? "
                                "ORDER BY p.name",
                                DB_INT, algo, DB_INT, fid, DB_TEXT, DB_BLOB, DB_INT);
        }
@@ -246,9 +249,10 @@ static void list_hashes_for_file(pts_meas_algorithms_t algo, char *file, int fid
        {
                e = db->query(db,
                                "SELECT p.name, fh.hash, fh.directory "
-                               "FROM products AS p, file_hashes AS fh "
+                               "FROM file_hashes AS fh "
                                "JOIN files AS f ON f.id = fh.file "
-                               "WHERE fh.algo = ? AND f.path = ? AND p.id = fh.product "
+                               "JOIN products AS p ON p.id = fh.product "
+                               "WHERE fh.algo = ? AND f.path = ? "
                                "ORDER BY p.name",
                                DB_INT, algo, DB_TEXT, file, DB_TEXT, DB_BLOB, DB_INT);
        }
@@ -287,9 +291,10 @@ static void list_hashes_for_product(pts_meas_algorithms_t algo,
        {
                e = db->query(db,
                                "SELECT f.id, f. f.path, fh.hash, fh.directory "
-                               "FROM files AS f, file_hashes AS fh "
+                               "FROM file_hashes AS fh "
+                               "JOIN files AS f ON f.id = fh.file "
                                "JOIN products AS p ON p.id = fh.product "
-                               "WHERE fh.algo = ? AND p.id = ? AND f.id = fh.file "
+                               "WHERE fh.algo = ? AND p.id = ? "
                                "ORDER BY fh.directory, f.path",
                                DB_INT, algo, DB_INT, pid, DB_INT, DB_TEXT, DB_BLOB, DB_INT);
        }
@@ -297,9 +302,10 @@ static void list_hashes_for_product(pts_meas_algorithms_t algo,
        {
                e = db->query(db,
                                "SELECT f.id, f.path, fh.hash, fh.directory "
-                               "FROM files AS f, file_hashes AS fh "
+                               "FROM file_hashes AS fh "
+                               "JOIN files AS f ON f.id = fh.file "
                                "JOIN products AS p ON p.id = fh.product "
-                               "WHERE fh.algo = ? AND p.name = ? AND f.id = fh.file "
+                               "WHERE fh.algo = ? AND p.name = ? "
                                "ORDER BY fh.directory, f.path",
                                DB_INT, algo, DB_TEXT, product, DB_INT, DB_TEXT, DB_BLOB, DB_INT);
        }