diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-15 01:02:37 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-15 01:02:37 +1200 |
commit | 2db5a3df91a76776cc214eca1e1fda6aecd0f36d (patch) | |
tree | 60934fa5dc97ed172a92a7773af2af0cf15c5eb7 /src/org/traccar/database/QueryBuilder.java | |
parent | 6dfd599ef69fac9ea0851e3c07873c6368231610 (diff) | |
parent | a8c7b44d06fd6112568c6ad0ed57c5af9db00ded (diff) | |
download | traccar-server-2db5a3df91a76776cc214eca1e1fda6aecd0f36d.tar.gz traccar-server-2db5a3df91a76776cc214eca1e1fda6aecd0f36d.tar.bz2 traccar-server-2db5a3df91a76776cc214eca1e1fda6aecd0f36d.zip |
Merge pull request #2113 from Abyss777/master
Fixes for new foreign key constraints
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 73569ac2a..1a83daab9 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -173,9 +173,17 @@ public final class QueryBuilder { } public QueryBuilder setLong(String name, long value) throws SQLException { + return setLong(name, value, false); + } + + public QueryBuilder setLong(String name, long value, boolean nullIfZero) throws SQLException { for (int i : indexes(name)) { try { - statement.setLong(i, value); + if (value == 0 && nullIfZero) { + statement.setNull(i, Types.INTEGER); + } else { + statement.setLong(i, value); + } } catch (SQLException error) { statement.close(); connection.close(); @@ -245,7 +253,7 @@ public final class QueryBuilder { } else if (method.getReturnType().equals(int.class)) { setInteger(name, (Integer) method.invoke(object)); } else if (method.getReturnType().equals(long.class)) { - setLong(name, (Long) method.invoke(object)); + setLong(name, (Long) method.invoke(object), name.endsWith("Id")); } else if (method.getReturnType().equals(double.class)) { setDouble(name, (Double) method.invoke(object)); } else if (method.getReturnType().equals(String.class)) { |