// 获取升级前表中的字段 protected String getColumnNames(SQLiteDatabase db, String tableName) { StringBuffer sbSelect = null; Cursor c = null; try { c = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (null != c) { int columnIndex = c.getColumnIndex("name"); if (-1 == columnIndex) { return null; } int index = 0; int pos = c.getCount() + 1; // 并标记最后一个不加逗号, // 由于index从0开始,所有这里不用加2,只加1 sbSelect = new StringBuffer(c.getCount() + 2); // //字段总列数,增加2列需要加2 for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { sbSelect.append(c.getString(columnIndex)); index++; if (index < pos) { sbSelect.append(","); } } } } catch (Exception e) { logger.e(e.getMessage()); } finally { if (null != c) { c.close(); } } return sbSelect.toString(); }
/** * 查询DB中某表的最后一条ID * * @return msgId */ public int queryLastInsertId(String tableName) { int lastMsgId = 0; Cursor c = null; SQLiteDatabase dbSlaver = null; try { dbSlaver = getReadableDatabase(); c = dbSlaver.rawQuery("select last_insert_rowid() from " + tableName, null); if (c.moveToFirst()) { lastMsgId = c.getInt(0); } } catch (SQLException e) { logger.e(e.toString()); } finally { if (null != c) { c.close(); } // dbSlaver.close(); //这里不能关闭哦,因为是在其它DB语句中间操作的,由其它DB操作部分关闭即可 } return lastMsgId; }
@Override public void decode(DataBuffer buffer) { if (null == buffer) return; try { FriendStatusNotifyResponse res = new FriendStatusNotifyResponse(); Header ResponseFriendStatusNotifyHeader = new Header(); ResponseFriendStatusNotifyHeader.decode(buffer); res.setHeader(ResponseFriendStatusNotifyHeader); if (ResponseFriendStatusNotifyHeader.getServiceId() != ProtocolConstant.SID_BUDDY_LIST || ResponseFriendStatusNotifyHeader.getCommandId() != ProtocolConstant.CID_CONTACT_FRIEND_STATUS_NOTIYF) return; int len = buffer.readInt(); res.setUser_id(buffer.readString(len)); res.setUser_status(buffer.readInt()); mResponse = res; } catch (Exception e) { logger.e(e.getMessage()); } }