Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

In this page you can find the example usage for android.content ContentValues put.

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void banThread(String group, String clean_subject, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    // First, check if it already is on the banned_threads table (it could be with unbanned=1)
    Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_threads " + " WHERE subscribed_group_id=" + groupid
            + " AND clean_subject=" + esc(clean_subject), null);

    if (c.getCount() > 0) { // Existed
        c.moveToFirst();//from   www.j a va  2 s .com
        dbwrite.execSQL("UPDATE banned_threads SET bandisabled=0 WHERE _id=" + c.getInt(0));

    } else {
        // New troll goes down to the pit
        ContentValues cv = new ContentValues();
        cv.put("subscribed_group_id", groupid);
        cv.put("bandisabled", 0);
        cv.put("clean_subject", clean_subject);
        dbwrite.insert("banned_threads", null, cv);
    }

    // Mark all the messages from the thread as read so they get cleaned later
    dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis()
            + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject));

    c.close();
    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void updateStarredThread(boolean starred, String clean_subject, int groupid, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbWrite = db.getWritableDatabase();

    clean_subject = clean_subject.replace("'", "''");

    String query;/*from   w  w  w .j a  v  a  2  s . c o  m*/

    if (starred == false) {
        query = "DELETE FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        dbWrite.execSQL(query);
    } else {
        // Check that it's not already on the table
        query = "SELECT _ID FROM starred_threads WHERE subscribed_group_id=" + groupid + " AND clean_subject="
                + esc(clean_subject);
        Cursor c = dbWrite.rawQuery(query, null);

        if (c.getCount() == 0) {
            ContentValues cv = new ContentValues();
            cv.put("subscribed_group_id", groupid);
            cv.put("clean_subject", clean_subject);
            dbWrite.insert("starred_threads", null, cv);
        }
        c.close();
    }
    dbWrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void logSentMessage(String msgId, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    /* Check first that the number of logged messages for this group is not greater than the 
    * limit impossed per group, because if it's greater we must delete number-limit older logs
    * until the table only has the limit. This is done this way because on the MessageList a set
    * is built with the post messages from that group, and then every loaded message's msgId is checked 
    * to see if it's in the set (to check for replies to our messages), so allowing it to grow too much
    * could make the MessageView slow//from  w  w  w .  jav  a 2s .  c  om
    */

    Cursor c = dbwrite.rawQuery(
            "SELECT _id FROM sent_posts_log WHERE subscribed_group_id=" + groupid + " ORDER BY _id", null);
    int count = c.getCount();
    int toKill = count - UsenetConstants.SENT_POSTS_LOG_LIMIT_PER_GROUP;
    int kennyId;

    if (toKill > 0) {
        // Delete some more than needed so we don't have to do this on every post sent
        toKill += UsenetConstants.SENT_POST_KILL_ADITIONAL;
        c.moveToFirst();

        for (int i = 0; i < toKill; i++) {
            kennyId = c.getInt(0);
            dbwrite.execSQL("DELETE FROM sent_posts_log WHERE _id=" + kennyId);
            c.moveToNext();
        }
    }
    c.close();

    // Now we have room for sure, insert the log
    ContentValues cv = new ContentValues(2);
    cv.put("server_article_id", msgId);
    cv.put("subscribed_group_id", groupid);
    dbwrite.insert("sent_posts_log", null, cv);

    dbwrite.close();
    db.close();
}

From source file:com.github.longkai.zhihu.util.Utils.java

/**
 * ???ContentValues?/*  w w w.  j ava2s. co  m*/
 * @param jsonArray data
 * @return itemstopicscontent values map
 */
public static Map<String, ContentValues[]> process(JSONArray jsonArray) {
    ContentValues[] items = new ContentValues[jsonArray.length()];
    List<ContentValues> topics = new ArrayList<ContentValues>();
    ContentValues item;
    ContentValues topic;
    // ??
    JSONArray array;
    JSONArray user;
    JSONArray question;
    JSONArray _topics;
    JSONArray _topic;
    // ??id??(?
    // ??= =)123,321,456,
    StringBuilder topicIds = new StringBuilder();
    // ??item???
    long millis = System.currentTimeMillis();

    for (int i = 0; i < items.length; i++) {
        array = jsonArray.optJSONArray(i);
        item = new ContentValues();

        item.put(BaseColumns._ID, millis--);

        // 
        item.put(STATUS, array.optString(1));
        item.put(ANSWER, array.optString(2));
        item.put(VOTE, array.optInt(3));
        item.put(LAST_ALTER_DATE, array.optLong(4) * 1000);
        item.put(ANSWER_ID, array.optLong(5));

        // 
        user = array.optJSONArray(6);
        if (user != null) {
            item.put(NICK, user.optString(0));
            item.put(UID, user.optString(1));
            item.put(AVATAR, user.optString(2));
        }

        // 
        question = array.optJSONArray(7);
        if (question != null) {
            item.put(TITLE, question.optString(1, null));
            item.put(DESCRIPTION, question.optString(2));
            item.put(QUESTION_ID, question.optLong(3));
            item.put(STARRED, question.optLong(5));
            item.put(VIEWED, question.optLong(6));
        }

        // ?
        topicIds.setLength(0);
        if (!question.isNull(7)) {
            _topics = question.optJSONArray(7);
            for (int j = 0; j < _topics.length(); j++) {
                _topic = _topics.optJSONArray(j);
                topic = new ContentValues(4);
                topic.put(TOPIC_NAME, _topic.optString(1, null));
                topic.put(TOPIC_DESCRIPTION, _topic.optString(2));
                topic.put(TOPIC_AVATAR, _topic.optString(3));
                topic.put(TOPIC_ID, _topic.optLong(4));
                // todo ?????replace?
                // ?????????
                topics.add(topic);

                // ?item?
                topicIds.append(_topic.optLong(4)).append(",");
            }
        }
        item.put(TOPICS, topicIds.toString());

        // ?json
        item.put(VOTERS, array.isNull(8) ? null : array.optJSONArray(8).toString());

        items[i] = item;
    }

    Map<String, ContentValues[]> map = new HashMap<String, ContentValues[]>(2);
    map.put(ITEMS, items);
    map.put(TOPICS, topics.toArray(new ContentValues[0]));
    return map;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public static ContentValues createIngredientsCV(long rowid, String ing) {
    ContentValues cvi = new ContentValues();
    cvi.put(IT_NAME, ing);
    cvi.put(IT_RECIPE_ID, rowid);//from  ww  w  . j a  v  a  2 s.co  m
    return cvi;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public static ContentValues createTagsCV(long rowid, String tag) {
    ContentValues ctags = new ContentValues();
    ctags.put(TT_TAG, tag);
    ctags.put(TT_RECIPE_ID, rowid);/*w  w w.  j a v  a 2s  . c o m*/
    return ctags;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public static ContentValues createDirectionsCV(long rowid, int step, String dir, String photo) {
    ContentValues cdirs = new ContentValues();
    cdirs.put(DT_STEP, dir);
    cdirs.put(DT_SEQUENCE, step);//from   ww w .j a  v a  2  s  .  c o  m
    cdirs.put(DT_PHOTO, photo);
    cdirs.put(DT_RECIPE_ID, rowid);
    return cdirs;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public static ContentValues createRecipeForInsert(Recipe r) {
    ContentValues values = new ContentValues();
    values.put(RT_NAME, r.name);
    values.put(RT_DESCRIPTION, r.description);
    values.put(RT_RATING, r.rating);// ww w  . j  a v a 2  s  . c om
    values.put(RT_CREATOR, r.creator);
    values.put(RT_DATE, r.date);
    values.put(RT_SERVING, r.serving);
    values.put(RT_TIME, r.time);
    values.put(RT_PHOTO, r.photo);
    return values;
}

From source file:com.orm.androrm.field.CharField.java

@Override
public void putData(String key, ContentValues values) {
    values.put(key, get());
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Helper method to parse and then insert the GENRE within the MovieEntry,
 * after parse then insert into GenreEntry.
 *
 * @throws JSONException//www  .j av a  2  s  .  com
 */
private static void parseGenre(Context context, String id, JSONArray genre, long currentTime, String sortGroup)
        throws JSONException {

    // Containers
    ContentValues lContentValuesGenre = new ContentValues();

    // iterate for each element in genre
    final int genreSize = genre.length();
    for (int j = 0; j < genreSize; j++) {

        // Genre list.
        String tempGenreList = genreList((Integer) genre.get(j));

        // Packing to ContentValues object
        lContentValuesGenre.put(ContractMovies.GenreEntry.COLUMN_MOVIE_ID, id);
        lContentValuesGenre.put(ContractMovies.GenreEntry.COLUMN_GENRE, tempGenreList);
        lContentValuesGenre.put(ContractMovies.GenreEntry.COLUMN_POSTING_TIME, currentTime);
        lContentValuesGenre.put(ContractMovies.GenreEntry.COLUMN_SORT_GROUP, sortGroup);

        try {
            context.getContentResolver().insert(ContractMovies.GenreEntry.CONTENT_URI, lContentValuesGenre);
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
}