aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-07-14 16:50:28 +0500
committerAbyss777 <abyss@fox5.ru>2016-07-14 16:50:28 +0500
commitadd55d83f367c0001deadadac4b83cc6542eb234 (patch)
tree9e14a6b066ed68ad6bfee5b1f4f3848d1b9a2ac3 /src
parent2a13bcccc26cf673bd9cd6be045099018f2f4d55 (diff)
downloadtraccar-server-add55d83f367c0001deadadac4b83cc6542eb234.tar.gz
traccar-server-add55d83f367c0001deadadac4b83cc6542eb234.tar.bz2
traccar-server-add55d83f367c0001deadadac4b83cc6542eb234.zip
Set long as NULL only for *Id fields
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/database/QueryBuilder.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index b91218a13..7d8731933 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -175,7 +175,20 @@ public final class QueryBuilder {
public QueryBuilder setLong(String name, long value) throws SQLException {
for (int i : indexes(name)) {
try {
- if (value == 0) {
+ statement.setLong(i, value);
+ } catch (SQLException error) {
+ statement.close();
+ connection.close();
+ throw error;
+ }
+ }
+ return this;
+ }
+
+ public QueryBuilder setLong(String name, long value, boolean nullIfZero) throws SQLException {
+ for (int i : indexes(name)) {
+ try {
+ if (value == 0 && nullIfZero) {
statement.setNull(i, Types.INTEGER);
} else {
statement.setLong(i, value);
@@ -249,7 +262,11 @@ 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));
+ if (name.endsWith("Id")) {
+ setLong(name, (Long) method.invoke(object), true);
+ } else {
+ setLong(name, (Long) method.invoke(object));
+ }
} else if (method.getReturnType().equals(double.class)) {
setDouble(name, (Double) method.invoke(object));
} else if (method.getReturnType().equals(String.class)) {