In my web app, user can write any SQL SELECT statement into a code editor. Then I am checking if his solution is correct by comparing his result set with my own correct result set.
I have 2 results from those queries:
// user SQL, for example "SELECT col_1, col_2 FROM table ORDER BY col_1";
$query1 = $con->prepare($userSql);"
$query1->execute();
// correct SQL
$query2 = $con->prepare("SELECT col_1, col_2 FROM table;");
$query2->execute();
I need to compare results from those objects - more specifically, I need to know, whether those 2 result sets are identical.
Is there any other way of comparing result sets?
My solution is that I am comparing fetched rows. BUT: If the first query e.g. doesn't contain an ORDER BY clause, I still get the same result set as the second query. However, I don't want to depend on DBMS hence the result set is not deterministic.