public DataBaseAdapter createDatabase() throws SQLException {
   try {
     mDbHelper.createDataBase();
     mDbHelper.openDataBase();
     mDbHelper.close();
   } catch (IOException mIOException) {
     Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase");
     throw new Error("UnableToCreateDatabase");
   }
   return this;
 }
  public void addContact(Contact contact) {
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    if (contact.getID() != -1) values.put(ThreadHelper.DB_ID, contact.getID());
    values.put(ThreadHelper.DB_NAME, contact.getName());
    values.put(ThreadHelper.DB_PASSWORD, contact.getPass());
    values.put(ThreadHelper.DB_PRIVATE, contact.getPriv());
    values.put(ThreadHelper.DB_PUBLIC, contact.getPub());

    db.insert(ThreadHelper.DB_TABLE, null, values);
    db.close();
  }
 public ArrayList<User> getAllContacts() {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   ArrayList<User> contactList = new ArrayList<User>();
   String selectQuery = "SELECT " + ThreadHelper.DB_NAME + " FROM " + ThreadHelper.DB_TABLE;
   try {
     Cursor cursor = db.rawQuery(selectQuery, null);
     if (cursor.moveToPosition(1)) { // set 1 cause 0 is myself
       do {
         contactList.add(new User(cursor.getString(0)));
       } while (cursor.moveToNext());
     }
   } catch (NullPointerException e) {
     // No entry found
   }
   return contactList;
 }
  public void update(Contact contact) {
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(ThreadHelper.DB_NAME, contact.getName());
    values.put(ThreadHelper.DB_PASSWORD, contact.getPass());
    values.put(ThreadHelper.DB_PRIVATE, contact.getPriv());
    values.put(ThreadHelper.DB_PUBLIC, contact.getPub());

    db.update(
        ThreadHelper.DB_TABLE,
        values,
        ThreadHelper.DB_NAME + "=?",
        new String[] {contact.getName()});
    db.close();
  }
 public String getContactName(int id) {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_NAME},
           ThreadHelper.DB_ID + "=?",
           new String[] {String.valueOf(id)},
           null,
           null,
           null,
           null);
   if (cursor != null) cursor.moveToFirst();
   try {
     return cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return null;
 }
 public String getContactPassword() {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PASSWORD},
           ThreadHelper.DB_ID + "=?",
           new String[] {"0"},
           null,
           null,
           null,
           null);
   if (cursor != null) cursor.moveToFirst();
   try {
     return cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return null;
 }
 public String getPrivateKey(int id) {
   String result = null;
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PRIVATE},
           ThreadHelper.DB_ID + "=?",
           new String[] {String.valueOf(id)},
           null,
           null,
           null,
           null);
   try {
     if (cursor != null) cursor.moveToFirst();
     result = cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return result;
 }
 public String getPublicKey(String name) {
   String result = null;
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PUBLIC},
           ThreadHelper.DB_NAME + "=?",
           new String[] {name},
           null,
           null,
           null,
           null);
   try {
     if (cursor != null) cursor.moveToFirst();
     result = cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return result;
 }
 public boolean isset(String name) {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   try {
     Cursor cursor =
         db.query(
             ThreadHelper.DB_TABLE,
             new String[] {ThreadHelper.DB_NAME},
             ThreadHelper.DB_NAME + "=?",
             new String[] {name},
             null,
             null,
             null,
             null);
     if (cursor != null) cursor.moveToFirst();
     cursor.getString(0);
     return true;
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return false;
 }
Beispiel #10
0
 public void close() {
   mDbHelper.close();
 }
Beispiel #11
0
 public void deleteEntry(String jid) {
   SQLiteDatabase db = mDbHelper.getWritableDatabase();
   int result = db.delete(ThreadHelper.DB_TABLE, ThreadHelper.DB_NAME + "=?", new String[] {jid});
   if (th.D) Log.e(TAG, "Deleted user entry: " + result);
   db.close();
 }