From ed4bf033616c90e09972ee6d44677fbce4cc8dc1 Mon Sep 17 00:00:00 2001
From: William Enright <william.enright@savoirfairelinux.com>
Date: Wed, 16 Sep 2020 15:22:11 -0400
Subject: [PATCH] Fixed search on local users being case sensitive

Change-Id: I6086e7a3472e4d168cb6395ecf46ada571818cad
---
 .../common/dao/SelectStatementBuilder.java    | 68 +++++++++----------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/jams-common/src/main/java/net/jami/jams/common/dao/SelectStatementBuilder.java b/jams-common/src/main/java/net/jami/jams/common/dao/SelectStatementBuilder.java
index c22c370e..ca0b3ffb 100644
--- a/jams-common/src/main/java/net/jami/jams/common/dao/SelectStatementBuilder.java
+++ b/jams-common/src/main/java/net/jami/jams/common/dao/SelectStatementBuilder.java
@@ -1,25 +1,25 @@
 /*
-* Copyright (C) 2020 by Savoir-faire Linux
-* Authors: William Enright <william.enright@savoirfairelinux.com>
-*          Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com>
-*          Johnny Flores <johnny.flores@savoirfairelinux.com>
-*          Mohammed Raza <mohammed.raza@savoirfairelinux.com>
-*          Felix Sidokhine <felix.sidokhine@savoirfairelinux.com>
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program.  If not, see <https://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2020 by Savoir-faire Linux
+ * Authors: William Enright <william.enright@savoirfairelinux.com>
+ *          Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com>
+ *          Johnny Flores <johnny.flores@savoirfairelinux.com>
+ *          Mohammed Raza <mohammed.raza@savoirfairelinux.com>
+ *          Felix Sidokhine <felix.sidokhine@savoirfairelinux.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
 package net.jami.jams.common.dao;
 
 import net.jami.jams.common.dao.connectivity.SQLConnection;
@@ -29,8 +29,8 @@ import java.sql.PreparedStatement;
 public class SelectStatementBuilder {
 
     public static PreparedStatement buildStatement(String table, StatementList statementElements,
-                                        StatementConstraints statementConstraints,
-                                        SQLConnection connection) throws Exception
+                                                   StatementConstraints statementConstraints,
+                                                   SQLConnection connection) throws Exception
     {
         PreparedStatement ps = null;
         StringBuilder stringBuilder = new StringBuilder();
@@ -38,27 +38,27 @@ public class SelectStatementBuilder {
         if(statementElements != null) {
             stringBuilder.append(" WHERE ");
             for (StatementElement statementElement : statementElements.getStatements()) {
-                stringBuilder
-                        .append(statementElement.getColumn())
-                        .append(" ")
-                        .append(statementElement.getOperator())
-                        .append(" ")
-                        .append("?")
-                        .append(" ")
-                        .append(statementElement.getNextStatementRelation())
-                        .append(" ");
+
+                stringBuilder.append("lower(" + statementElement.getColumn() + ")")
+                             .append(" ")
+                             .append(statementElement.getOperator())
+                             .append(" ")
+                             .append("?")
+                             .append(" ")
+                             .append(statementElement.getNextStatementRelation())
+                             .append(" ");
             }
             ps = connection.getConnection().prepareStatement(stringBuilder.toString());
             int i = 1;
             for (StatementElement statementElement : statementElements.getStatements()) {
-                ps.setString(i, statementElement.getValue());
+                ps.setString(i, (statementElement.getValue()).toLowerCase());
                 i++;
             }
         }
         else{
             if(statementConstraints != null){
                 stringBuilder.append(" LIMIT ").append(statementConstraints.getRowCount())
-                    .append(" OFFSET ").append(statementConstraints.getOffset());
+                        .append(" OFFSET ").append(statementConstraints.getOffset());
             }
             ps = connection.getConnection().prepareStatement(stringBuilder.toString());
         }
-- 
GitLab