From e910d9337a35fad663c978ff9121ed64ca28af91 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 14 Jul 2016 15:21:43 +0500 Subject: - Fixed saving parent group when creating new group. - Fixed storing device and group if parent group is not defined. - Fixed Warning in browser console about missed requirements. --- src/org/traccar/database/QueryBuilder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 73569ac2a..477434fb5 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -175,7 +175,11 @@ public final class QueryBuilder { public QueryBuilder setLong(String name, long value) throws SQLException { for (int i : indexes(name)) { try { - statement.setLong(i, value); + if (value == 0) { + statement.setNull(i, Types.INTEGER); + } else { + statement.setLong(i, value); + } } catch (SQLException error) { statement.close(); connection.close(); -- cgit v1.2.3 From 2a13bcccc26cf673bd9cd6be045099018f2f4d55 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 14 Jul 2016 15:49:05 +0500 Subject: Indentation --- src/org/traccar/database/QueryBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 477434fb5..b91218a13 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -178,7 +178,7 @@ public final class QueryBuilder { if (value == 0) { statement.setNull(i, Types.INTEGER); } else { - statement.setLong(i, value); + statement.setLong(i, value); } } catch (SQLException error) { statement.close(); -- cgit v1.2.3 From add55d83f367c0001deadadac4b83cc6542eb234 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 14 Jul 2016 16:50:28 +0500 Subject: Set long as NULL only for *Id fields --- src/org/traccar/database/QueryBuilder.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/org/traccar') 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)) { -- cgit v1.2.3 From a8c7b44d06fd6112568c6ad0ed57c5af9db00ded Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 14 Jul 2016 17:53:54 +0500 Subject: Remove duplicating code --- src/org/traccar/database/QueryBuilder.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 7d8731933..1a83daab9 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -173,16 +173,7 @@ public final class QueryBuilder { } public QueryBuilder setLong(String name, long value) throws SQLException { - for (int i : indexes(name)) { - try { - statement.setLong(i, value); - } catch (SQLException error) { - statement.close(); - connection.close(); - throw error; - } - } - return this; + return setLong(name, value, false); } public QueryBuilder setLong(String name, long value, boolean nullIfZero) throws SQLException { @@ -262,11 +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)) { - if (name.endsWith("Id")) { - setLong(name, (Long) method.invoke(object), true); - } else { - 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)) { -- cgit v1.2.3