Android Open Source - proximo Database

From Project

Back to project page proximo.


The source code is released under:

Copyright (c) 2010 Evan Martin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...

If you think the Android project proximo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// Copyright (c) 2010 Evan Martin.  All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
//  w ww .  j a  v a 2  s . c om
package org.neugierig.proximo;

import android.content.*;
import android.database.*;
import android.database.sqlite.*;
import android.util.Log;

public class Database {
  private static final String TAG = "proxmio Database";
  private static final String FILE = "queries.db";
  private static final String TABLE = "queries";
  private static final int VERSION = 1;

  private static class Helper extends SQLiteOpenHelper {
    Helper(Context context) {
      super(context, FILE, null, VERSION);

    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE " + TABLE
               + "( query STRING PRIMARY KEY"
               + ", json STRING"
            // + ", lastfetch INTEGER"
               + ")");

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
      db.execSQL("DROP TABLE IF EXISTS " + TABLE);

  Database(Context context) {
    mHelper = new Helper(context);

  String get(String query) {
    SQLiteDatabase db = mHelper.getReadableDatabase();
    Cursor cur = db.query(TABLE, new String[] {"json"},
                          "query = ?", new String[] { query },
                          null, null, null);
    if (!cur.moveToFirst())
      return null;
    return cur.getString(0);

  void put(String query, String json) {
    SQLiteDatabase db = mHelper.getWritableDatabase();
    ContentValues args = new ContentValues();
    args.put("query", query);
    args.put("json", json);
    db.replace(TABLE, "query", args);

  private Helper mHelper;

Java Source Code List