From 05ae05165aae38047b56000ce3bf1d2f1d785621 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 10 May 2014 19:16:19 +0200 Subject: Fix timestamp type Without this cast, setTimestamp would complain that a timestamp is expected, but a text type is given. --- src/database/QueryUtils.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/database/QueryUtils.java') diff --git a/src/database/QueryUtils.java b/src/database/QueryUtils.java index ff26ec4..eaf6a2d 100644 --- a/src/database/QueryUtils.java +++ b/src/database/QueryUtils.java @@ -14,12 +14,13 @@ public class QueryUtils { public final static String insertProfile = buildQuery("twitteruser", new String[]{"userid"}, "userid", "displayname", "timezone", "tweetcount", "followercount", - "followedcount", "location", "tweetname", "createdat", "language"); + "followedcount", "location", "tweetname", "createdat::timestamptz", + "language"); public final static String insertTweet = buildQuery("tweet", new String[]{"tweetid"}, - "tweetid", "createdat", "favcount", "retweetcount", "text", - "coordinates", "language", "retweetid", "replyid", "place", + "tweetid", "createdat::timestamptz", "favcount", "retweetcount", + "text", "coordinates", "language", "retweetid", "replyid", "place", "userid"); public final static String insertHash @@ -53,9 +54,10 @@ public class QueryUtils { String values = ""; // :a, :b, :c String set_values = ""; // a = nv.a, b = nv.b, c = nv.c String pkey_matches = ""; - for (String key : keys) { + for (String field : keys) { + String key = field.replaceFirst("::\\w+", ""); fields += sep + key; - values += sep + ":" + key; + values += sep + ":" + field; // "u" is "table that gets updated", "nv" is "new values" set_values += sep + key + " = nv." + key; sep = ", "; @@ -66,6 +68,7 @@ public class QueryUtils { primaryKeys = keys; } for (String pkey : primaryKeys) { + assert !pkey.contains("::") : "Specify primary keys when type cast is given"; pkey_matches += sep + "u." + pkey + " = nv." + pkey; sep = " AND "; } -- cgit v1.2.1