summaryrefslogtreecommitdiff
path: root/src/database/QueryUtils.java
blob: a120d1c1e6df9cf9a94f5d9549f5e3c9dc7f7a28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package database;

import org.json.JSONObject;

/**
 * Utilities to create queries.
 *
 * @author Maurice Laveaux
 */
public class QueryUtils {

    /**
     * Create an insert tweet.
     *
     * @return A valid database query.
     */
    public static DBQuery insertProfile() {
        String query = "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount,"
                + "followercount,followedcount,location) "
                + "SELECT  ?, ?, ?, ?, ?, ?, ? "
                + "WHERE NOT EXISTS "
                + "(SELECT * FROM twitteruser WHERE userid= ? )";
        return new DBQuery(query);
    }

    public static DBQuery insertTweet() {
        String query = "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) "
                + "SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT * FROM tweet WHERE tweetid= ? )";
        return new DBQuery(query);
    }

    public static void setInsertParams(DBQuery query, JSONObject tweet) {
        /*query.getPrepared().setLong(1, tweet.getLong("id"));
            pst.setString(2, tweet.getString("created_at"));
            pst.setLong(3, tweet.getLong("favorite_count"));
            pst.setLong(4, tweet.getLong("retweet_count"));
            pst.setString(5, tweet.getString("text"));
            pst.setLong(6, tweet.getLong("id"));*/
    }
}