From b432223b8823107e116b3352b3e410369f4b845f Mon Sep 17 00:00:00 2001 From: ljacqu Date: Tue, 19 Jan 2016 17:15:49 +0100 Subject: [PATCH] #437 Avoid LOWER() for SQLite - Implement review comment by DNx5 - avoid use of LOWER() - Close PreparedStatement/ResultSet in call --- .../java/fr/xephi/authme/datasource/SQLite.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 6ef8a406e..7e17de907 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -170,8 +170,7 @@ public class SQLite implements DataSource { !columnSalt.isEmpty() ? rs.getString(columnSalt) : null); } } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + logSqlException(ex); } finally { close(rs); close(pst); @@ -462,7 +461,7 @@ public class SQLite implements DataSource { } return countIp; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); + logSqlException(ex); return new ArrayList<>(); } catch (NullPointerException npe) { return new ArrayList<>(); @@ -530,7 +529,7 @@ public class SQLite implements DataSource { pst.executeUpdate(); } } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); + logSqlException(ex); } finally { close(pst); } @@ -686,14 +685,16 @@ public class SQLite implements DataSource { @Override public synchronized boolean isEmailStored(String email) { - try { - PreparedStatement ps = con.prepareStatement( - "SELECT 1 FROM " + tableName + " WHERE LOWER(" + columnEmail + ") = LOWER(?)"); + String sql = "SELECT 1 FROM " + tableName + " WHERE " + columnEmail + " = ? COLLATE NOCASE;"; + ResultSet rs = null; + try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setString(1, email); - ResultSet rs = ps.executeQuery(); + rs = ps.executeQuery(); return rs.next(); } catch (SQLException e) { logSqlException(e); + } finally { + close(rs); } return false; }