#437 Avoid LOWER() for SQLite

- Implement review comment by DNx5 - avoid use of LOWER()
- Close PreparedStatement/ResultSet in call
This commit is contained in:
ljacqu 2016-01-19 17:15:49 +01:00
parent 125c45d715
commit b432223b88

View File

@ -170,8 +170,7 @@ public class SQLite implements DataSource {
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null); !columnSalt.isEmpty() ? rs.getString(columnSalt) : null);
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); logSqlException(ex);
ConsoleLogger.writeStackTrace(ex);
} finally { } finally {
close(rs); close(rs);
close(pst); close(pst);
@ -462,7 +461,7 @@ public class SQLite implements DataSource {
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); logSqlException(ex);
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
@ -530,7 +529,7 @@ public class SQLite implements DataSource {
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); logSqlException(ex);
} finally { } finally {
close(pst); close(pst);
} }
@ -686,14 +685,16 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean isEmailStored(String email) { public synchronized boolean isEmailStored(String email) {
try { String sql = "SELECT 1 FROM " + tableName + " WHERE " + columnEmail + " = ? COLLATE NOCASE;";
PreparedStatement ps = con.prepareStatement( ResultSet rs = null;
"SELECT 1 FROM " + tableName + " WHERE LOWER(" + columnEmail + ") = LOWER(?)"); try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.setString(1, email); ps.setString(1, email);
ResultSet rs = ps.executeQuery(); rs = ps.executeQuery();
return rs.next(); return rs.next();
} catch (SQLException e) { } catch (SQLException e) {
logSqlException(e); logSqlException(e);
} finally {
close(rs);
} }
return false; return false;
} }