Code example for SQLiteStatement

Methods: bindLong, bindNull, bindString, close, execute

0
 
                stmt = dataBase.compileStatement(sql);
                setBindValue(stmt, 1, phone);
                setBindLongValue(stmt, 2, time);
                setBindValue(stmt, 3, time + "|" + list);
                stmt.execute();
            } 
        } catch (Exception seq) {
            sLogger.e(CLASS_NAME + ".saveAppcontent.e:" + seq.getMessage());
        } finally { 
            if (stmt != null) {
                stmt.close();
            } 
            closeDB(dataBase);
        } 
    } 
 
    /** 
     * ���ݵ绰������ѯ��¼ 
     */ 
    public static String getCountbyId(String phone) {
        SQLiteDatabase dataBase = null;
        dataBase = openDatabase();
        String id = null;
        if (dataBase != null) {
            String sql = "SELECT _id ,phone , time , driverInfo FROM " + TABLE_MY_DRIVER_LIST + " WHERE phone ='"
                    + phone + "'";
            Cursor cursor = dataBase.rawQuery(sql, null);
            while (cursor.moveToNext()) {
                id = cursor.getString(cursor.getColumnIndex("_id"));
            } 
        } 
        closeDB(dataBase);
        return id;
    } 
 
    /** 
     * ����_idɾ����ѯ��¼ 
     */ 
    public static void deleteCount(String id) {
        SQLiteDatabase dataBase = null;
        dataBase = openDatabase();
        if (dataBase != null) {
            String sql = "DELETE FROM " + TABLE_MY_DRIVER_LIST + " WHERE _id = '" + id + "'";
            dataBase.execSQL(sql);
        } 
        closeDB(dataBase);
    } 
 
    /** 
     * ��ѯ�绰��¼���� 
     */ 
    public static ArrayList<String> getCountDriverList() {
        SQLiteDatabase dataBase = null;
        dataBase = openDatabase();
        ArrayList<String> list = null;
        if (dataBase != null) {
            String sql = "SELECT phone ,time , driverInfo FROM " + TABLE_MY_DRIVER_LIST + " ORDER BY time DESC limit 10 ";
            Cursor cursor = dataBase.rawQuery(sql, null);
            if (cursor.getCount() != 0) {
                list = new ArrayList<String>();
                while (cursor.moveToNext()) {
                    list.add(cursor.getString(cursor
                            .getColumnIndex("driverInfo")));
                } 
            } 
 
            cursor.close();
        } 
        closeDB(dataBase);
        return list;
    } 
 
    /** 
     * ��ѯapp���� 
     */ 
    public static AppContentInfo getAppContent() { 
        SQLiteDatabase dataBase = null;
        dataBase = openDatabase();
        AppContentInfo info = null;
        if (dataBase != null) {
            String sql = "SELECT expire_at , cont FROM " + TABLE_APP_CONTENT + " WHERE _id = 1 ";
            Cursor cursor = dataBase.rawQuery(sql, null);
            while (cursor.moveToNext()) {
                info = new AppContentInfo(cursor.getString(cursor
                        .getColumnIndex("cont")));
            } 
            cursor.close();
        } 
        closeDB(dataBase);
        return info;
    } 
 
    /** 
     * ����app_content 
     *  
     */ 
    public static void updateAppContent(String expire_at, String content) {
        SQLiteDatabase dataBase = null;
        dataBase = openDatabase();
        if (dataBase != null) {
            sLogger.d("------------->update"); 
            String sql = "UPDATE " + TABLE_APP_CONTENT + " SET expire_at='" + expire_at
                    + "', cont= '" + content + "' WHERE _id = 1 ";
            dataBase.execSQL(sql);
        } 
        closeDB(dataBase);
    } 
 
    /** 
     * ��������<BR> 
     * �洢ֵΪ""ʱ����Ϊnull 
     *  
     * @param statement 
     *            SQLiteStatement <BR> 
     * @param index 
     *            index<BR> 
     * @param value 
     *            ֵ<BR> 
     */ 
    private static void setBindValue(SQLiteStatement statement, int index,
            String value) {
        if (value == null || value.length() == 0) {
            statement.bindNull(index);
        } else { 
            statement.bindString(index, value);
        } 
    } 
 
    /** 
     * �������� 
     *  
     * @param statement 
     *            SQLiteStatement<BR> 
     * @param index 
     *            index<BR> 
     * @param value 
     *            ֵ<BR> 
     */ 
    private static void setBindLongValue(SQLiteStatement statement, int index,
            long value) {
        statement.bindLong(index, value);
    } 
}