jpahullo / moodle-tool_mergeusers

Merge users script for Moodle

Home Page:https://moodle.org/plugins/view.php?plugin=tool_mergeusers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search users by id Postgres error

bwml opened this issue · comments

commented

Maybe this has been fixed in later versions. If so, sorry.
Plugin version: 2018030900
Moodle: Moodle 3.2.2+ (Build: 20170418)
PostgreSQL: 9.1 and 9.6
PHP 5.6.30

I get the following error when searching users by id:

Debug info: ERROR: operator does not exist: bigint ~~ unknown
LINE 1: SELECT * FROM mdl_user WHERE id LIKE $1 ORDER BY lastname, f...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit > type casts.
SELECT * FROM mdl_user WHERE id LIKE $1 ORDER BY lastname, firstname
[array (
0 => '%2676%',
)]
Error code: dmlreadexception

I was able to fix this with the following change.

diff -r 1417dacf533b src/admin/tool/mergeusers/lib/mergeusersearch.php
--- a/src/admin/tool/mergeusers/lib/mergeusersearch.php Mon Sep 10 09:50:28 2018 -0400
+++ b/src/admin/tool/mergeusers/lib/mergeusersearch.php Wed Sep 12 15:40:17 2018 -0400
@@ -63,7 +63,7 @@
$params = array(
'userid' => '%' . $input . '%',
);

  •            $sql = 'SELECT * FROM {user} WHERE id LIKE :userid';
    
  •            $sql = 'SELECT * FROM {user} WHERE id::text LIKE :userid';
    
               break;
           case 'username': // search on username
    

Sorry about the formatting.
Thanks.

Hi!

Thank you so much. It seems like postgresql is more type-checking than other DB systems.

This is an option. Maybe another approach is to have the equal operator for number-based columns, and like operator for string-based columns.

Thanks a lot for reporting and giving a solution.

Regards,

Jordi

Hi,

Third possibility: would it be better to use Moodle's DML here instead of raw SQL?

Actually, revisiting the user search, it does not make sense to look for a pattern %{value}% on user.id, since it has to be the exact number id.

Actually, it does not make sense compare user.id LIKE '%10%', if in fact you know the exact user.id.

Therefore, the proposal here is to remove the LIKE %% comparizon and use = '{value}' instead.

this is solved by PR #157