Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: [2] pg_query(): Query failed: ERROR: operator does not exist: boolean #391

Open
lionee opened this issue May 24, 2021 · 1 comment
Labels

Comments

@lionee
Copy link

lionee commented May 24, 2021

Hello,

Tcexam is running on Postgres 11.12 (raspbian)
Tcexam is throwing error if you try to show test result as normal user (index tab -> column "status"):

ERROR: [2] pg_query(): Query failed: ERROR: operator does not exist: boolean = integer LINE 1: ...user_id=3 AND testuser_status>3) AND test_results_to_users=1 ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. | LINE: 83 | FILE: /var/www/html/tcexam/shared/code/tce_db_dal_postgresql.php
ERROR: ERROR: operator does not exist: boolean = integer LINE 1: ...user_id=3 AND testuser_status>3) AND test_results_to_users=1 ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

Is this caused by some wrong configuration? This can be fixed by applying following patch to /tcexam/shared/code/tce_functions_test_stats.php file:

--- tce_functions_test_stats.php        2021-05-24 13:36:00.743252741 +0200
+++ tce_functions_test_stats.php.notpatched     2021-05-24 13:40:04.180108677 +0200
@@ -1282,7 +1282,7 @@
     $str = '0'; // string to return
     $test_id = intval($test_id);
     $user_id = intval($user_id);
-    $sql = 'SELECT test_id FROM '.K_TABLE_TESTS.' WHERE test_id IN (SELECT DISTINCT testuser_test_id FROM '.K_TABLE_TEST_USER.' WHERE testuser_user_id='.intval($user_id).' AND testuser_status>3) AND '.$filter.'=1::BOOLEAN';
+    $sql = 'SELECT test_id FROM '.K_TABLE_TESTS.' WHERE test_id IN (SELECT DISTINCT testuser_test_id FROM '.K_TABLE_TEST_USER.' WHERE testuser_user_id='.intval($user_id).' AND testuser_status>3) AND '.$filter.'=1';
     if ($r = F_db_query($sql, $db)) {
         while ($m = F_db_fetch_assoc($r)) {
             $str .= ','.$m['test_id'];
@nicolaasuni
Copy link
Member

It looks like those cases are not properly handled when using Postgres.
I will need to investigate how to make those queries working with all supported DBs, as your suggested change only works for Postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants