Java Code Examples for android.database.sqlite.SQLiteDatabase.isOpen()

The following are Jave code examples for showing how to use isOpen() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 7 votes
/**
 * save a message
 *
 * @param message
 * @return return cursor of the message
 */
public synchronized Integer saveMessage(InviteMessage message) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int id = -1;
    if (db.isOpen()) {
        ContentValues values = new ContentValues();
        values.put(InviteMessgeDao.COLUMN_NAME_FROM, message.getFrom());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUP_ID, message.getGroupId());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUP_Name, message.getGroupName());
        values.put(InviteMessgeDao.COLUMN_NAME_REASON, message.getReason());
        values.put(InviteMessgeDao.COLUMN_NAME_TIME, message.getTime());
        values.put(InviteMessgeDao.COLUMN_NAME_STATUS, message.getStatus().ordinal());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUPINVITER, message.getGroupInviter());
        db.insert(InviteMessgeDao.TABLE_NAME, null, values);

        Cursor cursor = db.rawQuery("select last_insert_rowid() from " + InviteMessgeDao.TABLE_NAME, null);
        if (cursor.moveToFirst()) {
            id = cursor.getInt(0);
        }

        cursor.close();
    }
    return id;
}
 
Example 2
Project: GitHub   File: DBUtils.java   View Source Code Vote up 6 votes
public static boolean isFieldExists(SQLiteDatabase db, String tableName, String fieldName) {
    if (tableName == null || db == null || fieldName == null || !db.isOpen()) return false;

    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " LIMIT 0", null);
        return cursor != null && cursor.getColumnIndex(fieldName) != -1;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 3
Project: prada   File: UploadLogDBHelper.java   View Source Code Vote up 6 votes
public void DisplayUploadFile(){
     SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
  if (db != null && db.isOpen()) {
       Cursor cur = db.rawQuery("select upload_file_name, isForceUpload, isResend from file_info",
               new String[]{});
    if (!cur.isClosed()) {
      try{
          while(cur.moveToNext()){
               Log.i(TAG, "upload_file_name: " + cur.getString(0) + " isForceUpload: " + cur.getInt(1) + " isResend: " + cur.getInt(2));
          }
      } catch(Exception ex){
          Log.i(TAG, ex.toString());
      } finally{
          cur.close();
          db.close();
      }
    }
  }

}
 
Example 4
Project: prada   File: UploadLogDBHelper.java   View Source Code Vote up 6 votes
public String getBindId(File uploadFile){
  SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
  String bindID = null;
    if (db != null && db.isOpen()) {
      Cursor cur = db.rawQuery("select sourceid from uploadlog where uploadfilepath=?",
              new String[]{uploadFile.getAbsolutePath()});
      if (!cur.isClosed()) {
        try{
          if(cur.moveToFirst()){
              bindID = cur.getString(0);
          }
        } catch(Exception ex){
        } finally{
            cur.close();
            db.close();
        }
      }
    }
      return bindID;
}
 
Example 5
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
/**
 * update message
 *
 * @param msgId
 * @param values
 */
synchronized public void updateMessage(int msgId, ContentValues values) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        db.update(InviteMessgeDao.TABLE_NAME, values, InviteMessgeDao.COLUMN_NAME_ID + " = ?", new String[]{String.valueOf(msgId)});
    }
}
 
Example 6
Project: CCDownload   File: DataSet.java   View Source Code Vote up 5 votes
public static void insertVideoPosition(String videoId, int position) {
	
	SQLiteDatabase database = sqLiteOpenHelper.getWritableDatabase();
	if (database.isOpen()) {
		ContentValues values = new ContentValues();
		values.put("videoId", videoId);
		values.put("position", position);
		database.insert(VIDEOPOSITION, null, values);
		database.close();
	}
}
 
Example 7
Project: CCDownload   File: DataSet.java   View Source Code Vote up 5 votes
public static int getVideoPosition(String videoId) {
	int position = 0;
	SQLiteDatabase database = sqLiteOpenHelper.getReadableDatabase();
	if (database.isOpen()) {
		Cursor cursor = database.query(VIDEOPOSITION, new String[]{"position"}, "videoId=?", new String[]{videoId}, null, null, null);
		if (cursor.moveToFirst()) {
			position = cursor.getInt(cursor.getColumnIndex("position"));
		}
		cursor.close();
		database.close();
	}
	return position;
}
 
Example 8
Project: CCDownload   File: DataSet.java   View Source Code Vote up 5 votes
public static void updateVideoPosition(String videoId, int position) {
	SQLiteDatabase database = sqLiteOpenHelper.getWritableDatabase();
	if (database.isOpen()) {
		ContentValues values = new ContentValues();
		values.put("position", position);
		database.update(VIDEOPOSITION, values, "videoId=?", new String[]{videoId});
		database.close();
	}
}
 
Example 9
Project: prada   File: UploadLogDBHelper.java   View Source Code Vote up 5 votes
public FileInfo getFileInfo(String uploadFileName){
    FileInfo fileInfo = new FileInfo();

    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
      if (db != null && db.isOpen()) {
        Cursor cur = db.rawQuery("select upload_file_name, isForceUpload, isResend from file_info where upload_file_name = ?",
                new String[]{uploadFileName});

        if (!cur.isClosed()) {
          try{
              while(cur.moveToNext()){
                if (cur.getInt(1) == 0) {
                    fileInfo.isForceUpload = false;
                } else {
                    fileInfo.isForceUpload = true;
                }
                if (cur.getInt(2) == 0) {
                    fileInfo.isResend = false;
                } else {
                    fileInfo.isResend = true;
                }
              }
          } catch(Exception ex){
          } finally{
              cur.close();
              db.close();
          }
        }
      }
      return fileInfo;
}
 
Example 10
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
synchronized int getUnreadNotifyCount() {
    int count = 0;
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    if (db.isOpen()) {
        Cursor cursor = db.rawQuery("select " + InviteMessgeDao.COLUMN_NAME_UNREAD_MSG_COUNT + " from " + InviteMessgeDao.TABLE_NAME, null);
        if (cursor.moveToFirst()) {
            count = cursor.getInt(0);
        }
        cursor.close();
    }
    return count;
}
 
Example 11
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
synchronized void setUnreadNotifyCount(int count) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        ContentValues values = new ContentValues();
        values.put(InviteMessgeDao.COLUMN_NAME_UNREAD_MSG_COUNT, count);

        db.update(InviteMessgeDao.TABLE_NAME, values, null, null);
    }
}
 
Example 12
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
synchronized private void setList(String column, List<String> strList) {
    StringBuilder strBuilder = new StringBuilder();

    for (String hxid : strList) {
        strBuilder.append(hxid).append("$");
    }

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        ContentValues values = new ContentValues();
        values.put(column, strBuilder.toString());

        db.update(UserDao.PREF_TABLE_NAME, values, null, null);
    }
}
 
Example 13
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
/**
 * get contact list
 *
 * @return
 */
synchronized public Map<String, EaseUser> getContactList() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Map<String, EaseUser> users = new Hashtable<String, EaseUser>();
    if (db.isOpen()) {
        Cursor cursor = db.rawQuery("select * from " + UserDao.TABLE_NAME /* + " desc" */, null);
        while (cursor.moveToNext()) {
            String username = cursor.getString(cursor.getColumnIndex(UserDao.COLUMN_NAME_ID));
            String nick = cursor.getString(cursor.getColumnIndex(UserDao.COLUMN_NAME_NICK));
            String avatar = cursor.getString(cursor.getColumnIndex(UserDao.COLUMN_NAME_AVATAR));
            String phone = cursor.getString(cursor.getColumnIndex(UserDao.COLUMN_NAME_PHONE));
            String postion = cursor.getString(cursor.getColumnIndex(UserDao.ROBOT_COLUMN_NAME_POSITION));
            String company = cursor.getString(cursor.getColumnIndex(UserDao.ROBOT_COLUMN_NAME_COMPANY));
            String nickName = cursor.getString(cursor.getColumnIndex(UserDao.ROBOT_COLUMN_NAME_NICKNAME));
            String memberid = cursor.getString(cursor.getColumnIndex(UserDao.COLUMN_NAME_MEMBER_ID));
            EaseUser user = new EaseUser(username);
            user.setNick(nick);
            user.setNewnickName(nickName);
            user.setAvatar(avatar);
            user.setPhone(phone);
            try {
                user.setMemberId(Integer.valueOf(memberid));
            } catch (Exception e) {

            }
            user.setPosition(postion);
            user.setCompany(company);
            if (username.equals(Constant.NEW_FRIENDS_USERNAME) || username.equals(Constant.GROUP_USERNAME)
                    || username.equals(Constant.CHAT_ROOM) || username.equals(Constant.CHAT_ROBOT)) {
                user.setInitialLetter("");
            } else {
                EaseCommonUtils.setUserInitialLetter(user);
            }
            users.put(username, user);
        }
        cursor.close();
    }
    return users;
}
 
Example 14
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 5 votes
/**
 * delete a contact
 *
 * @param username
 */
synchronized public void deleteContact(String username) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        db.delete(UserDao.TABLE_NAME, UserDao.COLUMN_NAME_ID + " = ?", new String[]{username});
    }
}
 
Example 15
Project: Android-2017   File: DataBaseHelper.java   View Source Code Vote up 4 votes
/**
 * Cierra la base de datos
 * @param db conexión a base de dato a cerrar
 */
public void closeDatabase (SQLiteDatabase db) {
    if (db != null && db.isOpen()) {
        db.close();
    }
}
 
Example 16
Project: Android-2017   File: DataBaseHelper.java   View Source Code Vote up 4 votes
/**
 * Cierra la base de datos
 * @param db conexión a base de dato a cerrar
 */
public void closeDatabase (SQLiteDatabase db) {
    if (db != null && db.isOpen()) {
        db.close();
    }
}
 
Example 17
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 4 votes
/**
 * save a contact
 *
 * @param user
 */
synchronized public void saveContact(EaseUser user) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(UserDao.COLUMN_NAME_ID, user.getUsername());
    if (user.getNick() != null) {
        values.put(UserDao.COLUMN_NAME_NICK, user.getNewnickName());

    } else {
        values.put(UserDao.COLUMN_NAME_NICK, "");

    }
    if (user.getNewnickName() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, user.getNewnickName());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, "");
    }

    if (user.getAvatar() != null) {
        values.put(UserDao.COLUMN_NAME_AVATAR, user.getAvatar());
    } else {
        values.put(UserDao.COLUMN_NAME_AVATAR, "");

    }
    if (user.getPhone() != null) {
        values.put(UserDao.COLUMN_NAME_PHONE, user.getPhone());
    } else {
        values.put(UserDao.COLUMN_NAME_PHONE, "");

    }
    if (user.getPosition() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, user.getPosition());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, "");

    }
    if (user.getCompany() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, user.getCompany());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, "");

    }
    values.put(UserDao.COLUMN_NAME_MEMBER_ID, user.getMemberId());
    if (db.isOpen()) {
        db.replace(UserDao.TABLE_NAME, null, values);
    }
}
 
Example 18
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 4 votes
/**
 * get messges
 *
 * @return
 */
synchronized public List<InviteMessage> getMessagesList() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    List<InviteMessage> msgs = new ArrayList<InviteMessage>();
    if (db.isOpen()) {
        Cursor cursor = db.rawQuery("select * from " + InviteMessgeDao.TABLE_NAME + " desc", null);
        while (cursor.moveToNext()) {
            InviteMessage msg = new InviteMessage();
            int id = cursor.getInt(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_ID));
            String from = cursor.getString(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_FROM));
            String groupid = cursor.getString(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_GROUP_ID));
            String groupname = cursor.getString(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_GROUP_Name));
            String reason = cursor.getString(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_REASON));
            long time = cursor.getLong(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_TIME));
            int status = cursor.getInt(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_STATUS));
            String groupInviter = cursor.getString(cursor.getColumnIndex(InviteMessgeDao.COLUMN_NAME_GROUPINVITER));

            msg.setId(id);
            msg.setFrom(from);
            msg.setGroupId(groupid);
            msg.setGroupName(groupname);
            msg.setReason(reason);
            msg.setTime(time);
            msg.setGroupInviter(groupInviter);

            if (status == InviteMesageStatus.BEINVITEED.ordinal())
                msg.setStatus(InviteMesageStatus.BEINVITEED);
            else if (status == InviteMesageStatus.BEAGREED.ordinal())
                msg.setStatus(InviteMesageStatus.BEAGREED);
            else if (status == InviteMesageStatus.BEREFUSED.ordinal())
                msg.setStatus(InviteMesageStatus.BEREFUSED);
            else if (status == InviteMesageStatus.AGREED.ordinal())
                msg.setStatus(InviteMesageStatus.AGREED);
            else if (status == InviteMesageStatus.REFUSED.ordinal())
                msg.setStatus(InviteMesageStatus.REFUSED);
            else if (status == InviteMesageStatus.BEAPPLYED.ordinal())
                msg.setStatus(InviteMesageStatus.BEAPPLYED);
            else if (status == InviteMesageStatus.GROUPINVITATION.ordinal())
                msg.setStatus(InviteMesageStatus.GROUPINVITATION);
            else if (status == InviteMesageStatus.GROUPINVITATION_ACCEPTED.ordinal())
                msg.setStatus(InviteMesageStatus.GROUPINVITATION_ACCEPTED);
            else if (status == InviteMesageStatus.GROUPINVITATION_DECLINED.ordinal())
                msg.setStatus(InviteMesageStatus.GROUPINVITATION_DECLINED);

            msgs.add(msg);
        }
        cursor.close();
    }
    return msgs;
}
 
Example 19
Project: boohee_v5.6   File: a.java   View Source Code Vote up 4 votes
private List<String> a() {
    SQLiteDatabase readableDatabase;
    Cursor rawQuery;
    SQLiteDatabase sQLiteDatabase;
    Throwable th;
    Cursor cursor = null;
    List<String> arrayList = new ArrayList();
    try {
        readableDatabase = getReadableDatabase();
        try {
            rawQuery = readableDatabase.rawQuery("select tid from tb_tid", null);
            while (rawQuery.moveToNext()) {
                try {
                    Object string = rawQuery.getString(0);
                    if (!TextUtils.isEmpty(string)) {
                        arrayList.add(b.a(2, string, com.alipay.sdk.util.a.c((Context) this.c.get())));
                    }
                } catch (Exception e) {
                    cursor = rawQuery;
                    sQLiteDatabase = readableDatabase;
                } catch (Throwable th2) {
                    th = th2;
                }
            }
            if (rawQuery != null) {
                rawQuery.close();
            }
            if (readableDatabase != null && readableDatabase.isOpen()) {
                readableDatabase.close();
            }
        } catch (Exception e2) {
            sQLiteDatabase = readableDatabase;
            if (cursor != null) {
                cursor.close();
            }
            if (sQLiteDatabase != null && sQLiteDatabase.isOpen()) {
                sQLiteDatabase.close();
            }
            return arrayList;
        } catch (Throwable th3) {
            Throwable th4 = th3;
            rawQuery = null;
            th = th4;
            if (rawQuery != null) {
                rawQuery.close();
            }
            if (readableDatabase != null && readableDatabase.isOpen()) {
                readableDatabase.close();
            }
            throw th;
        }
    } catch (Exception e3) {
        sQLiteDatabase = null;
        if (cursor != null) {
            cursor.close();
        }
        sQLiteDatabase.close();
        return arrayList;
    } catch (Throwable th32) {
        readableDatabase = null;
        th = th32;
        rawQuery = null;
        if (rawQuery != null) {
            rawQuery.close();
        }
        readableDatabase.close();
        throw th;
    }
    return arrayList;
}
 
Example 20
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 4 votes
/**
     * save contact list
     *
     * @param contactList
     */
    synchronized public void saveContactList(List<EaseUser> contactList) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        if (db.isOpen()) {
            db.delete(UserDao.TABLE_NAME, null, null);
            for (EaseUser user : contactList) {
                ContentValues values = new ContentValues();
                values.put(UserDao.COLUMN_NAME_ID, user.getUsername());
                if (user.getNick() != null) {
                    values.put(UserDao.COLUMN_NAME_NICK, user.getNick());
                } else {
                    values.put(UserDao.COLUMN_NAME_NICK, "");
                }
                if (user.getPhone() != null) {

                    values.put(UserDao.COLUMN_NAME_PHONE, user.getPhone());
                } else {
                    values.put(UserDao.COLUMN_NAME_PHONE, "");

                }
                if (user.getAvatar() != null) {
                    values.put(UserDao.COLUMN_NAME_AVATAR, user.getAvatar());
                } else {
                    values.put(UserDao.COLUMN_NAME_AVATAR, "");

                }

//                if (user.getNickName() != null) {
//                    values.put(UserDao.COLUMN_NAME_NICK, user.getNickName());
//                } else {
//                    values.put(UserDao.COLUMN_NAME_NICK, "");
//
//                }
                if (user.getNewnickName() != null) {
                    values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, user.getNewnickName());
                } else {
                    values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, "");
                }
                if (user.getPosition() != null) {
                    values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, user.getPosition());
                } else {
                    values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, "");

                }
                if (user.getCompany() != null) {
                    values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, user.getCompany());
                } else {
                    values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, "");

                }

                values.put(UserDao.COLUMN_NAME_MEMBER_ID, user.getMemberId());

                db.replace(UserDao.TABLE_NAME, null, values);
            }
        }
    }