Android Open Source - passby Database Manager






From Project

Back to project page passby.

License

The source code is released under:

Copyright 2014 Firebase, https://www.firebase.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ?Software??...

If you think the Android project passby 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

//#CSIT6000B#  Rio He       20227977 yheas@connect.ust.hk
//#CSIT6000B#  Cedric Liang 20220395 zliangag@connect.ust.hk
//#CSIT6000B#  Kevin Wang   20225577 zwangbo@connect.ust.hk 
package com.firebase.database;
/* w w w  .  j av a  2s .com*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DatabaseManager {
  private DatabaseHelper dbHelper;
  private SQLiteDatabase db;
  private User user = User.getInstance();
  
  public DatabaseManager() {
    // TODO Auto-generated constructor stub
  }
  public DatabaseManager(Context context){
    dbHelper = new DatabaseHelper(context);
    // to ensure mContext.openOrCreateDatabase() is called in db.getWritableDatabase()
    // context should be inited,
    // new DatabaseManager(Context context) will be called in Activity's onCreate()
    db = dbHelper.getWritableDatabase();
  }

  // create a new user
  public void createUser(User user){
    db.execSQL("INSERT INTO " + DatabaseHelper.TABLE_NAME
        + " VALUES(null, ?, ?)", new Object[] { user.getNickname(),
        user.getGender()});
  }
  
  // update the user's info
  public void uptUser(String prevName){
    ContentValues cv = new ContentValues();
    cv.put("nickname", user.getNickname());
    cv.put("gender", user.getGender());
    
    db.update(DatabaseHelper.TABLE_NAME, cv, "nickname = ?",
        new String[] { prevName });
  }
  
  // query
  public Cursor queryTheCursor(){
    Cursor c = db.rawQuery("SELECT * FROM " + DatabaseHelper.TABLE_NAME, null);
    //Log.i("nickname", c.getString(c.getColumnIndex("nickname")));
    return c;
  }
  
  public ContentValues query(){
    ContentValues cv = new ContentValues();
    Cursor c = queryTheCursor();
    while(c.moveToNext()){
      Log.i("in query!!", "in query");
      
      cv.put("nickname", c.getString(c.getColumnIndex("nickname")));
      cv.put("gender", c.getInt(c.getColumnIndex("gender")));
    }
    
    Log.i("cv nickname", "!!!");
    c.close();
    return cv;
  }
  
  
  // close database to release memory
  public void closeDB(){
      db.close();
  }
}




Java Source Code List

com.firebase.androidchat.ChatListAdapter.java
com.firebase.androidchat.Chat.java
com.firebase.androidchat.FirebaseListAdapter.java
com.firebase.androidchat.MainActivity.java
com.firebase.client.LaunchActivity.java
com.firebase.client.LocateActivity.java
com.firebase.client.SearchResultActivity.java
com.firebase.client.SettingActivity.java
com.firebase.database.DatabaseHelper.java
com.firebase.database.DatabaseManager.java
com.firebase.database.DatabaseTask.java
com.firebase.database.User.java