diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-29 09:41:29 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-29 09:41:29 +1200 |
commit | 88b3f00f3855aa408c7859051efdcb5b37fe559f (patch) | |
tree | 7cb87b275298c7b15679fe07c19bf0ca1dd6dda8 /src/org/traccar/database/QueryBuilder.java | |
parent | cc893062eb540a198dc8c20c1379e94b5719fd5c (diff) | |
download | trackermap-server-88b3f00f3855aa408c7859051efdcb5b37fe559f.tar.gz trackermap-server-88b3f00f3855aa408c7859051efdcb5b37fe559f.tar.bz2 trackermap-server-88b3f00f3855aa408c7859051efdcb5b37fe559f.zip |
Fix postgres generated keys problem (fix #480)
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 23d8c6bfa..5e5c163a3 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -41,14 +41,18 @@ public class QueryBuilder { private PreparedStatement statement; private final String query; - private QueryBuilder(DataSource dataSource, String query) throws SQLException { + private QueryBuilder(DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException { indexMap = new HashMap<String, List<Integer>>(); connection = dataSource.getConnection(); this.query = query; if (query != null) { - String parsedQuery = parse(query, indexMap); + String parsedQuery = parse(query.trim(), indexMap); try { - statement = connection.prepareStatement(parsedQuery, Statement.RETURN_GENERATED_KEYS); + if (returnGeneratedKeys) { + statement = connection.prepareStatement(parsedQuery, Statement.RETURN_GENERATED_KEYS); + } else { + statement = connection.prepareStatement(parsedQuery); + } } catch (SQLException error) { connection.close(); throw error; @@ -115,9 +119,13 @@ public class QueryBuilder { return parsedQuery.toString(); } - + public static QueryBuilder create(DataSource dataSource, String query) throws SQLException { - return new QueryBuilder(dataSource, query); + return new QueryBuilder(dataSource, query, false); + } + + public static QueryBuilder create(DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException { + return new QueryBuilder(dataSource, query, returnGeneratedKeys); } private List<Integer> indexes(String name) { |