mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-03 23:58:19 +00:00
optimize data insertion issues
This commit is contained in:
parent
922f23abe2
commit
6d92c7865b
@ -46,7 +46,10 @@ public class ChannelDBManager {
|
||||
}
|
||||
stringBuffer.append("'").append(channelIDs.get(i)).append("'");
|
||||
}
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_id + " in (" + stringBuffer + ") and " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType;
|
||||
Object[] args = new Object[2];
|
||||
args[0] = stringBuffer.toString();
|
||||
args[1] = channelType;
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_id + " in (?) and " + WKDBColumns.WKChannelColumns.channel_type + "=?";
|
||||
List<WKChannel> list = new ArrayList<>();
|
||||
if (WKIMApplication
|
||||
.getInstance()
|
||||
@ -56,7 +59,7 @@ public class ChannelDBManager {
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -138,7 +141,7 @@ public class ChannelDBManager {
|
||||
else newCVList.add(cv);
|
||||
}
|
||||
try {
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null) {
|
||||
return;
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper().getDb()
|
||||
@ -183,7 +186,7 @@ public class ChannelDBManager {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null) {
|
||||
return;
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper()
|
||||
@ -200,7 +203,7 @@ public class ChannelDBManager {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null) {
|
||||
return;
|
||||
}
|
||||
WKIMApplication.getInstance().getDbHelper()
|
||||
@ -217,14 +220,18 @@ public class ChannelDBManager {
|
||||
* @return List<WKChannel>
|
||||
*/
|
||||
public synchronized List<WKChannel> queryWithFollowAndStatus(byte channelType, int follow, int status) {
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.follow + "=" + follow + " and " + WKDBColumns.WKChannelColumns.status + "=" + status + " and is_deleted=0";
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelType;
|
||||
args[1] = follow;
|
||||
args[2] = status;
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=? and " + WKDBColumns.WKChannelColumns.follow + "=? and " + WKDBColumns.WKChannelColumns.status + "=? and is_deleted=0";
|
||||
List<WKChannel> channels = new ArrayList<>();
|
||||
if (WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper() != null) {
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return channels;
|
||||
}
|
||||
@ -245,14 +252,17 @@ public class ChannelDBManager {
|
||||
* @return List<WKChannel>
|
||||
*/
|
||||
public synchronized List<WKChannel> queryWithStatus(byte channelType, int status) {
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.status + "=" + status;
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelType;
|
||||
args[1] = status;
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=? and " + WKDBColumns.WKChannelColumns.status + "=?";
|
||||
List<WKChannel> channels = new ArrayList<>();
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null){
|
||||
return channels;
|
||||
if (WKIMApplication.getInstance().getDbHelper() == null) {
|
||||
return channels;
|
||||
}
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return channels;
|
||||
}
|
||||
@ -265,14 +275,19 @@ public class ChannelDBManager {
|
||||
|
||||
public synchronized List<WKChannelSearchResult> search(String searchKey) {
|
||||
List<WKChannelSearchResult> list = new ArrayList<>();
|
||||
Object[] args = new Object[4];
|
||||
args[0] = "%" + searchKey + "%";
|
||||
args[1] = "%" + searchKey + "%";
|
||||
args[2] = "%" + searchKey + "%";
|
||||
args[3] = "%" + searchKey + "%";
|
||||
String sql = " select t.*,cm.member_name,cm.member_remark from (\n" +
|
||||
" select " + channel + ".*,max(" + channelMembers + ".id) mid from " + channel + "," + channelMembers + " " +
|
||||
"where " + channel + ".channel_id=" + channelMembers + ".channel_id and " + channel + ".channel_type=" + channelMembers + ".channel_type" +
|
||||
" and (" + channel + ".channel_name like '%" + searchKey + "%' or " + channel + ".channel_remark" +
|
||||
" like '%" + searchKey + "%' or " + channelMembers + ".member_name like '%" + searchKey + "%' or " + channelMembers + ".member_remark like '%" + searchKey + "%')\n" +
|
||||
" and (" + channel + ".channel_name like ? or " + channel + ".channel_remark" +
|
||||
" like ? or " + channelMembers + ".member_name like ? or " + channelMembers + ".member_remark like ?)\n" +
|
||||
" group by " + channel + ".channel_id," + channel + ".channel_type\n" +
|
||||
" ) t," + channelMembers + " cm where t.channel_id=cm.channel_id and t.channel_type=cm.channel_type and t.mid=cm.id";
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql);
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args);
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -303,9 +318,12 @@ public class ChannelDBManager {
|
||||
|
||||
public synchronized List<WKChannel> searchWithChannelType(String searchKey, byte channelType) {
|
||||
List<WKChannel> list = new ArrayList<>();
|
||||
|
||||
String sql = "select * from " + channel + " where (" + WKDBColumns.WKChannelColumns.channel_name + " LIKE '%" + searchKey + "%' or " + WKDBColumns.WKChannelColumns.channel_remark + " LIKE '%" + searchKey + "%') and " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType;
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
Object[] args = new Object[3];
|
||||
args[0] = "%" + searchKey + "%";
|
||||
args[1] = "%" + searchKey + "%";
|
||||
args[2] = channelType;
|
||||
String sql = "select * from " + channel + " where (" + WKDBColumns.WKChannelColumns.channel_name + " LIKE ? or " + WKDBColumns.WKChannelColumns.channel_remark + " LIKE ?) and " + WKDBColumns.WKChannelColumns.channel_type + "=?";
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -318,9 +336,13 @@ public class ChannelDBManager {
|
||||
|
||||
public synchronized List<WKChannel> searchWithChannelTypeAndFollow(String searchKey, byte channelType, int follow) {
|
||||
List<WKChannel> list = new ArrayList<>();
|
||||
|
||||
String sql = "select * from " + channel + " where (" + WKDBColumns.WKChannelColumns.channel_name + " LIKE '%" + searchKey + "%' or " + WKDBColumns.WKChannelColumns.channel_remark + " LIKE '%" + searchKey + "%') and " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.follow + "=" + follow;
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
Object[] args = new Object[4];
|
||||
args[0] = "%" + searchKey + "%";
|
||||
args[1] = "%" + searchKey + "%";
|
||||
args[2] = channelType;
|
||||
args[3] = follow;
|
||||
String sql = "select * from " + channel + " where (" + WKDBColumns.WKChannelColumns.channel_name + " LIKE ? or " + WKDBColumns.WKChannelColumns.channel_remark + " LIKE ?) and " + WKDBColumns.WKChannelColumns.channel_type + "=? and " + WKDBColumns.WKChannelColumns.follow + "=?";
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -332,11 +354,14 @@ public class ChannelDBManager {
|
||||
}
|
||||
|
||||
public synchronized List<WKChannel> queryWithChannelTypeAndFollow(byte channelType, int follow) {
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelColumns.follow + "=" + follow;
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelType;
|
||||
args[1] = follow;
|
||||
String sql = "select * from " + channel + " where " + WKDBColumns.WKChannelColumns.channel_type + "=? and " + WKDBColumns.WKChannelColumns.follow + "=?";
|
||||
List<WKChannel> channels = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return channels;
|
||||
}
|
||||
|
@ -39,10 +39,17 @@ public class ChannelMembersDbManager {
|
||||
|
||||
public synchronized List<WKChannelMember> search(String channelId, byte channelType, String keyword, int page, int size) {
|
||||
int queryPage = (page - 1) * size;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id='" + channelId + "' and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 and (member_name like '%" + keyword + "%' or member_remark like '%" + keyword + "%' or channel_name like '%" + keyword + "%' or channel_remark like '%" + keyword + "%') order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||
Object[] args = new Object[6];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = "%" + keyword + "%";
|
||||
args[3] = "%" + keyword + "%";
|
||||
args[4] = "%" + keyword + "%";
|
||||
args[5] = "%" + keyword + "%";
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=? and " + channelMembers + ".channel_type=? and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 and (member_name like ? or member_remark like ? or channel_name like ? or channel_remark like ?) order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -56,10 +63,13 @@ public class ChannelMembersDbManager {
|
||||
|
||||
public synchronized List<WKChannelMember> queryWithPage(String channelId, byte channelType, int page, int size) {
|
||||
int queryPage = (page - 1) * size;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id='" + channelId + "' and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=? and " + channelMembers + ".channel_type=? and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc limit " + queryPage + "," + size + "";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -78,10 +88,13 @@ public class ChannelMembersDbManager {
|
||||
* @return List<WKChannelMember>
|
||||
*/
|
||||
public synchronized List<WKChannelMember> query(String channelId, byte channelType) {
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id='" + channelId + "' and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=? and " + channelMembers + ".channel_type=? and " + channelMembers + ".is_deleted=0 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -94,10 +107,13 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public synchronized List<WKChannelMember> queryDeleted(String channelId, byte channelType) {
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id='" + channelId + "' and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".is_deleted=1 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " LEFT JOIN " + channel + " on " + channelMembers + ".member_uid=" + channel + ".channel_id and " + channel + ".channel_type=1 where " + channelMembers + ".channel_id=? and " + channelMembers + ".channel_type=? and " + channelMembers + ".is_deleted=1 and " + channelMembers + ".status=1 order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -111,10 +127,14 @@ public class ChannelMembersDbManager {
|
||||
|
||||
public synchronized boolean isExist(String channelId, byte channelType, String uid) {
|
||||
boolean isExist = false;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "='" + channelId + "' and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "='" + uid + "')";
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = uid;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=?)";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
|
||||
if (cursor != null && cursor.moveToLast()) {
|
||||
isExist = true;
|
||||
@ -125,19 +145,20 @@ public class ChannelMembersDbManager {
|
||||
|
||||
public List<WKChannelMember> queryWithUIDs(String channelID, byte channelType, List<String> uidList) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from " + channelMembers + " where channel_id ='").append(channelID).append("' and channel_type=").append(channelType).append(" and member_uid in (");
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
String sql = "select * from " + channelMembers + " where channel_id =? and channel_type=? and member_uid in (?)";
|
||||
for (int i = 0, size = uidList.size(); i < size; i++) {
|
||||
if (i != 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
sb.append("'").append(uidList.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
String sql = sb.toString();
|
||||
args[2] = sb.toString();
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -157,10 +178,14 @@ public class ChannelMembersDbManager {
|
||||
*/
|
||||
public synchronized WKChannelMember query(String channelId, byte channelType, String uid) {
|
||||
WKChannelMember wkChannelMember = null;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "='" + channelId + "' and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "='" + uid + "')";
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = uid;
|
||||
String sql = "select " + channelMembers + ".*," + channelCols + " from " + channelMembers + " left join " + channel + " on " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 where (" + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.member_uid + "=?)";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -366,14 +391,17 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public long queryMaxVersion(String channelID, byte channelType) {
|
||||
String sql = "select max(version) version from " + channelMembers + " where channel_id ='" + channelID + "' and channel_type=" + channelType + " limit 0, 1";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
String sql = "select max(version) version from " + channelMembers + " where channel_id =? and channel_type=? limit 0, 1";
|
||||
long version = 0;
|
||||
try {
|
||||
if (WKIMApplication.getInstance().getDbHelper() != null) {
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql);
|
||||
.rawQuery(sql, args);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
version = WKCursor.readLong(cursor, "version");
|
||||
@ -389,10 +417,13 @@ public class ChannelMembersDbManager {
|
||||
@Deprecated
|
||||
public synchronized WKChannelMember queryMaxVersionMember(String channelID, byte channelType) {
|
||||
WKChannelMember channelMember = null;
|
||||
String sql = "select * from " + channelMembers + " where " + WKDBColumns.WKChannelMembersColumns.channel_id + "='" + channelID + "' and " + WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " order by " + WKDBColumns.WKChannelMembersColumns.version + " desc limit 0,1";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
String sql = "select * from " + channelMembers + " where " + WKDBColumns.WKChannelMembersColumns.channel_id + "=? and " + WKDBColumns.WKChannelMembersColumns.channel_type + "=? order by " + WKDBColumns.WKChannelMembersColumns.version + " desc limit 0,1";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -404,10 +435,13 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public synchronized List<WKChannelMember> queryRobotMembers(String channelId, byte channelType) {
|
||||
String sql = "select * from " + channelMembers + " where channel_id='" + channelId + "' and channel_type=" + channelType + " and robot=1 and is_deleted=0";
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
String sql = "select * from " + channelMembers + " where channel_id=? and channel_type=? and robot=1 and is_deleted=0";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -420,10 +454,14 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public List<WKChannelMember> queryWithRole(String channelId, byte channelType, int role) {
|
||||
String sql = "SELECT * FROM " + channelMembers + " WHERE channel_id='" + channelId + "' AND channel_type=" + channelType + " AND role=" + role + " AND is_deleted=0";
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = role;
|
||||
String sql = "SELECT * FROM " + channelMembers + " WHERE channel_id=? AND channel_type=? AND role=? AND is_deleted=0";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -436,10 +474,14 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public synchronized List<WKChannelMember> queryWithStatus(String channelId, byte channelType, int status) {
|
||||
String sql = "select " + channelMembers + ".*," + channel + ".channel_name," + channel + ".channel_remark," + channel + ".avatar from " + channelMembers + " left Join " + channel + " where " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 AND " + channelMembers + ".channel_id='" + channelId + "' and " + channelMembers + ".channel_type=" + channelType + " and " + channelMembers + ".status=" + status + " order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Object[] args = new Object[3];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = status;
|
||||
String sql = "select " + channelMembers + ".*," + channel + ".channel_name," + channel + ".channel_remark," + channel + ".avatar from " + channelMembers + " left Join " + channel + " where " + channelMembers + ".member_uid = " + channel + ".channel_id AND " + channel + ".channel_type=1 AND " + channelMembers + ".channel_id=? and " + channelMembers + ".channel_type=? and " + channelMembers + ".status=? order by " + channelMembers + ".role=1 desc," + channelMembers + ".role=2 desc," + channelMembers + "." + WKDBColumns.WKChannelMembersColumns.created_at + " asc";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, args);
|
||||
List<WKChannelMember> list = new ArrayList<>();
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
@ -452,10 +494,13 @@ public class ChannelMembersDbManager {
|
||||
}
|
||||
|
||||
public synchronized int queryCount(String channelID, byte channelType) {
|
||||
Object[] args = new Object[2];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
String sql = "select count(*) from " + channelMembers
|
||||
+ " where (" + WKDBColumns.WKChannelMembersColumns.channel_id + "='" + channelID + "' and "
|
||||
+ WKDBColumns.WKChannelMembersColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKChannelMembersColumns.is_deleted + "=0 and " + WKDBColumns.WKChannelMembersColumns.status + "=1)";
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql);
|
||||
+ " where (" + WKDBColumns.WKChannelMembersColumns.channel_id + "=? and "
|
||||
+ WKDBColumns.WKChannelMembersColumns.channel_type + "=? and " + WKDBColumns.WKChannelMembersColumns.is_deleted + "=0 and " + WKDBColumns.WKChannelMembersColumns.status + "=1)";
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args);
|
||||
cursor.moveToFirst();
|
||||
int count = cursor.getInt(0);
|
||||
cursor.close();
|
||||
|
@ -96,18 +96,16 @@ public class ConversationDbManager {
|
||||
|
||||
public List<WKUIConversationMsg> queryWithChannelIds(List<String> channelIds) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0, size = channelIds.size(); i < size; i++) {
|
||||
if (i != 0) sb.append(",");
|
||||
sb.append("'").append(channelIds.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".is_deleted=0 and " + conversation + ".channel_id in " + sb;
|
||||
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".is_deleted=0 and " + conversation + ".channel_id in (?)";
|
||||
List<WKUIConversationMsg> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -123,12 +121,12 @@ public class ConversationDbManager {
|
||||
}
|
||||
|
||||
public List<WKConversationMsg> queryWithChannelType(byte channelType) {
|
||||
String sql = "select * from " + conversation + " where channel_type=" + channelType;
|
||||
String sql = "select * from " + conversation + " where channel_type=?";
|
||||
List<WKConversationMsg> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{channelType})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -223,11 +221,11 @@ public class ConversationDbManager {
|
||||
}
|
||||
|
||||
public WKConversationMsg queryWithChannel(String channelID, byte channelType) {
|
||||
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".channel_id='" + channelID + "' and " + conversation + ".channel_type=" + channelType + " and " + conversation + ".is_deleted=0";
|
||||
String sql = "select " + conversation + ".*," + channelCols + "," + extraCols + " from " + conversation + " left join " + channel + " on " + conversation + ".channel_id=" + channel + ".channel_id and " + conversation + ".channel_type=" + channel + ".channel_type left join " + conversationExtra + " on " + conversation + ".channel_id=" + conversationExtra + ".channel_id and " + conversation + ".channel_type=" + conversationExtra + ".channel_type where " + conversation + ".channel_id=? and " + conversation + ".channel_type=? and " + conversation + ".is_deleted=0";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql);
|
||||
.rawQuery(sql, new Object[]{channelID, channelType});
|
||||
WKConversationMsg conversationMsg = null;
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
@ -356,10 +354,10 @@ public class ConversationDbManager {
|
||||
|
||||
public WKConversationMsgExtra queryMsgExtraWithChannel(String channelID, byte channelType) {
|
||||
WKConversationMsgExtra msgExtra = null;
|
||||
String sql = "select * from " + conversationExtra + " where channel_id='" + channelID + "' and channel_type=" + channelType;
|
||||
String sql = "select * from " + conversationExtra + " where channel_id=? and channel_type=?";
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
msgExtra = serializeMsgExtra(cursor);
|
||||
@ -371,17 +369,15 @@ public class ConversationDbManager {
|
||||
|
||||
private List<WKConversationMsgExtra> queryWithExtraChannelIds(List<String> channelIds) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from " + conversationExtra + " where channel_id in (");
|
||||
|
||||
String sql = "select * from " + conversationExtra + " where channel_id in (?)";
|
||||
for (int i = 0, size = channelIds.size(); i < size; i++) {
|
||||
if (i != 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("'").append(channelIds.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
List<WKConversationMsgExtra> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sb.toString())) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import com.xinbida.wukongim.interfaces.IGetOrSyncHistoryMsgBack;
|
||||
import com.xinbida.wukongim.manager.MsgManager;
|
||||
import com.xinbida.wukongim.message.type.WKSendMsgResult;
|
||||
import com.xinbida.wukongim.msgmodel.WKMessageContent;
|
||||
import com.xinbida.wukongim.utils.WKLoggerUtils;
|
||||
import com.xinbida.wukongim.utils.WKTypeUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -229,13 +228,13 @@ public class MsgDbManager {
|
||||
* @return 删除条数
|
||||
*/
|
||||
private int getDeletedCount(long minMessageSeq, long maxMessageSeq, String channelID, byte channelType) {
|
||||
String sql = "select count(*) num from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "='" + channelID + "' and " + WKDBColumns.WKMessageColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKMessageColumns.message_seq + ">" + minMessageSeq + " and " + WKDBColumns.WKMessageColumns.message_seq + "<" + maxMessageSeq + " and " + WKDBColumns.WKMessageColumns.is_deleted + "=1";
|
||||
String sql = "select count(*) num from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "=? and " + WKDBColumns.WKMessageColumns.channel_type + "=? and " + WKDBColumns.WKMessageColumns.message_seq + ">? and " + WKDBColumns.WKMessageColumns.message_seq + "<? and " + WKDBColumns.WKMessageColumns.is_deleted + "=1";
|
||||
Cursor cursor = null;
|
||||
int num = 0;
|
||||
try {
|
||||
cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, minMessageSeq, maxMessageSeq});
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -252,30 +251,37 @@ public class MsgDbManager {
|
||||
private List<WKMsg> queryMessages(String channelId, byte channelType, long oldestOrderSeq, boolean contain, int pullMode, int limit) {
|
||||
List<WKMsg> msgList = new ArrayList<>();
|
||||
String sql;
|
||||
|
||||
Object[] args;
|
||||
if (oldestOrderSeq <= 0) {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
args = new Object[2];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
} else {
|
||||
if (pullMode == 0) {
|
||||
if (contain) {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<=" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<=?) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
} else {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<?) where is_deleted=0 and is_mutual_deleted=0 order by order_seq desc limit 0," + limit;
|
||||
}
|
||||
} else {
|
||||
if (contain) {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq>=" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq asc limit 0," + limit;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq>=?) where is_deleted=0 and is_mutual_deleted=0 order by order_seq asc limit 0," + limit;
|
||||
} else {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelId + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq>" + oldestOrderSeq + ") where is_deleted=0 and is_mutual_deleted=0 order by order_seq asc limit 0," + limit;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq>?) where is_deleted=0 and is_mutual_deleted=0 order by order_seq asc limit 0," + limit;
|
||||
}
|
||||
}
|
||||
args = new Object[3];
|
||||
args[0] = channelId;
|
||||
args[1] = channelType;
|
||||
args[2] = oldestOrderSeq;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
List<String> messageIds = new ArrayList<>();
|
||||
List<String> replyMsgIds = new ArrayList<>();
|
||||
List<String> fromUIDs = new ArrayList<>();
|
||||
try {
|
||||
cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql);
|
||||
cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args);
|
||||
if (cursor == null) {
|
||||
return msgList;
|
||||
}
|
||||
@ -379,9 +385,9 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public List<WKMsg> queryExpireMessages(long timestamp, int limit) {
|
||||
String sql = "SELECT * from " + message + " where is_deleted=0 and " + WKDBColumns.WKMessageColumns.expire_time + ">0 and " + WKDBColumns.WKMessageColumns.expire_timestamp + "<=" + timestamp + " order by order_seq desc limit 0," + limit;
|
||||
String sql = "SELECT * from " + message + " where is_deleted=0 and " + WKDBColumns.WKMessageColumns.expire_time + ">0 and " + WKDBColumns.WKMessageColumns.expire_timestamp + "<=? order by order_seq desc limit 0," + limit;
|
||||
List<WKMsg> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{timestamp})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -395,14 +401,25 @@ public class MsgDbManager {
|
||||
|
||||
public List<WKMsg> queryWithFromUID(String channelID, byte channelType, String fromUID, long oldestOrderSeq, int limit) {
|
||||
String sql;
|
||||
Object[] args;
|
||||
if (oldestOrderSeq == 0) {
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelID + "' and " + message + ".channel_type=" + channelType + " and from_uid='" + fromUID + "' and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
} else
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id='" + channelID + "' and " + message + ".channel_type=" + channelType + " and from_uid='" + fromUID + "' and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<" + oldestOrderSeq + ") where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
args = new Object[3];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
args[2] = fromUID;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and from_uid=? and " + message + ".type<>0 and " + message + ".type<>99) where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
} else {
|
||||
args = new Object[4];
|
||||
args[0] = channelID;
|
||||
args[1] = channelType;
|
||||
args[2] = fromUID;
|
||||
args[3] = oldestOrderSeq;
|
||||
sql = "SELECT * FROM (SELECT " + messageCols + "," + extraCols + " FROM " + message + " LEFT JOIN " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".channel_id=? and " + message + ".channel_type=? and from_uid=? and " + message + ".type<>0 and " + message + ".type<>99 AND " + message + ".order_seq<?) where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
}
|
||||
List<WKMsg> wkMsgs = new ArrayList<>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql);
|
||||
cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args);
|
||||
if (cursor == null) {
|
||||
return wkMsgs;
|
||||
}
|
||||
@ -425,8 +442,8 @@ public class MsgDbManager {
|
||||
|
||||
public long queryOrderSeq(String channelID, byte channelType, long maxOrderSeq, int limit) {
|
||||
long minOrderSeq = 0;
|
||||
String sql = "select order_seq from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "='" + channelID + "' and " + WKDBColumns.WKMessageColumns.channel_type + "=" + channelType + " and type<>99 and order_seq <= " + maxOrderSeq + " order by " + WKDBColumns.WKMessageColumns.order_seq + " desc limit " + limit;
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
String sql = "select order_seq from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "=? and " + WKDBColumns.WKMessageColumns.channel_type + "=? and type<>99 and order_seq <=? order by " + WKDBColumns.WKMessageColumns.order_seq + " desc limit " + limit;
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, maxOrderSeq})) {
|
||||
if (cursor == null) {
|
||||
return minOrderSeq;
|
||||
}
|
||||
@ -439,13 +456,13 @@ public class MsgDbManager {
|
||||
|
||||
public long queryMaxOrderSeqWithChannel(String channelID, byte channelType) {
|
||||
long maxOrderSeq = 0;
|
||||
String sql = "select max(order_seq) order_seq from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "='" + channelID + "' and " + WKDBColumns.WKMessageColumns.channel_type + "=" + channelType + " and type<>99 and type<>0 and is_deleted=0";
|
||||
String sql = "select max(order_seq) order_seq from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "=? and " + WKDBColumns.WKMessageColumns.channel_type + "=? and type<>99 and type<>0 and is_deleted=0";
|
||||
try {
|
||||
if (WKIMApplication.getInstance().getDbHelper() != null) {
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql);
|
||||
.rawQuery(sql, new Object[]{channelID, channelType});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
maxOrderSeq = WKCursor.readLong(cursor, "order_seq");
|
||||
@ -599,7 +616,6 @@ public class MsgDbManager {
|
||||
// insertMsgList(insertMsgList);
|
||||
List<ContentValues> cvList = new ArrayList<>();
|
||||
for (WKMsg wkMsg : insertMsgList) {
|
||||
WKLoggerUtils.getInstance().e("插入数据" + wkMsg.messageID);
|
||||
ContentValues cv = WKSqlContentValues.getContentValuesWithMsg(wkMsg);
|
||||
cvList.add(cv);
|
||||
}
|
||||
@ -618,13 +634,12 @@ public class MsgDbManager {
|
||||
public List<WKMsg> queryWithClientMsgNos(List<String> clientMsgNos) {
|
||||
List<WKMsg> msgs = new ArrayList<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_msg_no + " in (");
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_msg_no + " in (?)";
|
||||
for (int i = 0, size = clientMsgNos.size(); i < size; i++) {
|
||||
if (i != 0) sb.append(",");
|
||||
sb.append("'").append(clientMsgNos.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sb.toString())) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return msgs;
|
||||
}
|
||||
@ -707,10 +722,10 @@ public class MsgDbManager {
|
||||
|
||||
public boolean isExist(String clientMsgNo) {
|
||||
boolean isExist = false;
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_msg_no + "='" + clientMsgNo + "'";
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_msg_no + "=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{clientMsgNo})) {
|
||||
if (cursor != null && cursor.moveToLast()) {
|
||||
isExist = true;
|
||||
}
|
||||
@ -720,10 +735,10 @@ public class MsgDbManager {
|
||||
|
||||
public WKMsg queryWithClientMsgNo(String clientMsgNo) {
|
||||
WKMsg wkMsg = null;
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " LEFT JOIN " + messageExtra + " ON " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".client_msg_no=" + "'" + clientMsgNo + "'";
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " LEFT JOIN " + messageExtra + " ON " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".client_msg_no=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{clientMsgNo})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -739,10 +754,10 @@ public class MsgDbManager {
|
||||
|
||||
public WKMsg queryWithClientSeq(long clientSeq) {
|
||||
WKMsg msg = null;
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_seq + "=" + clientSeq;
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.client_seq + "=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{clientSeq})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -756,13 +771,13 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public WKMsg queryMaxOrderSeqMsgWithChannel(String channelID, byte channelType) {
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "='" + channelID + "' and " + WKDBColumns.WKMessageColumns.channel_type + "=" + channelType + " and " + WKDBColumns.WKMessageColumns.is_deleted + "=0 and type<>0 and type<>99 order by " + WKDBColumns.WKMessageColumns.order_seq + " desc limit 1";
|
||||
String sql = "select * from " + message + " where " + WKDBColumns.WKMessageColumns.channel_id + "=? and " + WKDBColumns.WKMessageColumns.channel_type + "=? and " + WKDBColumns.WKMessageColumns.is_deleted + "=0 and type<>0 and type<>99 order by " + WKDBColumns.WKMessageColumns.order_seq + " desc limit 1";
|
||||
Cursor cursor = null;
|
||||
WKMsg msg = null;
|
||||
try {
|
||||
cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType});
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -800,14 +815,14 @@ public class MsgDbManager {
|
||||
return row > 0;
|
||||
}
|
||||
|
||||
public int queryRowNoWithOrderSeq(String channelID, byte channelType, long order_seq) {
|
||||
String sql = "select count(*) cn from " + message + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and " + WKDBColumns.WKMessageColumns.type + "<>0 and " + WKDBColumns.WKMessageColumns.type + "<>99 and " + WKDBColumns.WKMessageColumns.order_seq + ">" + order_seq + " and " + WKDBColumns.WKMessageColumns.is_deleted + "=0 order by " + WKDBColumns.WKMessageColumns.order_seq + " desc";
|
||||
public int queryRowNoWithOrderSeq(String channelID, byte channelType, long orderSeq) {
|
||||
String sql = "select count(*) cn from " + message + " where channel_id=? and channel_type=? and " + WKDBColumns.WKMessageColumns.type + "<>0 and " + WKDBColumns.WKMessageColumns.type + "<>99 and " + WKDBColumns.WKMessageColumns.order_seq + ">? and " + WKDBColumns.WKMessageColumns.is_deleted + "=0 order by " + WKDBColumns.WKMessageColumns.order_seq + " desc";
|
||||
Cursor cursor = null;
|
||||
int rowNo = 0;
|
||||
try {
|
||||
cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, orderSeq});
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -842,14 +857,13 @@ public class MsgDbManager {
|
||||
|
||||
private List<WKMsgExtra> queryMsgExtrasWithMsgIds(List<String> msgIds) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from " + messageExtra + " where message_id in (");
|
||||
String sql = "select * from " + messageExtra + " where message_id in (?)";
|
||||
for (int i = 0, size = msgIds.size(); i < size; i++) {
|
||||
if (i != 0) sb.append(",");
|
||||
sb.append("'").append(msgIds.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
List<WKMsgExtra> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sb.toString())) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -921,12 +935,12 @@ public class MsgDbManager {
|
||||
* @return List<WKMessageGroupByDate>
|
||||
*/
|
||||
public List<WKMessageGroupByDate> queryMessageGroupByDateWithChannel(String channelID, byte channelType) {
|
||||
String sql = "SELECT DATE(" + WKDBColumns.WKMessageColumns.timestamp + ", 'unixepoch','localtime') AS days,COUNT(" + WKDBColumns.WKMessageColumns.client_msg_no + ") count,min(" + WKDBColumns.WKMessageColumns.order_seq + ") AS order_seq FROM " + message + " WHERE " + WKDBColumns.WKMessageColumns.channel_type + " = " + channelType + " and " + WKDBColumns.WKMessageColumns.channel_id + "='" + channelID + "' and is_deleted=0" + " GROUP BY " + WKDBColumns.WKMessageColumns.timestamp + "," + WKDBColumns.WKMessageColumns.order_seq + "";
|
||||
String sql = "SELECT DATE(" + WKDBColumns.WKMessageColumns.timestamp + ", 'unixepoch','localtime') AS days,COUNT(" + WKDBColumns.WKMessageColumns.client_msg_no + ") count,min(" + WKDBColumns.WKMessageColumns.order_seq + ") AS order_seq FROM " + message + " WHERE " + WKDBColumns.WKMessageColumns.channel_type + " =? and " + WKDBColumns.WKMessageColumns.channel_id + "=? and is_deleted=0" + " GROUP BY " + WKDBColumns.WKMessageColumns.timestamp + "," + WKDBColumns.WKMessageColumns.order_seq + "";
|
||||
List<WKMessageGroupByDate> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{channelType, channelID})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -959,12 +973,19 @@ public class MsgDbManager {
|
||||
*/
|
||||
public List<WKMsg> queryWithContentType(int type, long oldestClientSeq, int limit) {
|
||||
String sql;
|
||||
Object[] args;
|
||||
if (oldestClientSeq <= 0) {
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".type=" + type + ") where is_deleted=0 and revoke=0 order by " + WKDBColumns.WKMessageColumns.timestamp + " desc limit 0," + limit;
|
||||
} else
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".type=" + type + " and " + WKDBColumns.WKMessageColumns.client_seq + "<" + oldestClientSeq + ") where is_deleted=0 and revoke=0 order by " + WKDBColumns.WKMessageColumns.timestamp + " desc limit 0," + limit;
|
||||
args = new Object[1];
|
||||
args[0] = type;
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".type=?) where is_deleted=0 and revoke=0 order by " + WKDBColumns.WKMessageColumns.timestamp + " desc limit 0," + limit;
|
||||
} else {
|
||||
args = new Object[2];
|
||||
args[0] = type;
|
||||
args[1] = oldestClientSeq;
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".type=? and " + WKDBColumns.WKMessageColumns.client_seq + "<?) where is_deleted=0 and revoke=0 order by " + WKDBColumns.WKMessageColumns.timestamp + " desc limit 0," + limit;
|
||||
}
|
||||
List<WKMsg> msgs = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return msgs;
|
||||
}
|
||||
@ -988,11 +1009,11 @@ public class MsgDbManager {
|
||||
|
||||
public List<WKMsg> searchWithChannel(String searchKey, String channelID, byte channelType) {
|
||||
List<WKMsg> msgs = new ArrayList<>();
|
||||
String sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".searchable_word like '%" + searchKey + "%' and " + message + ".channel_id='" + channelID + "' and " + message + ".channel_type=" + channelType + ") where is_deleted=0 and revoke=0";
|
||||
String sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".searchable_word like ? and " + message + ".channel_id=? and " + message + ".channel_type=?) where is_deleted=0 and revoke=0";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{"%" + searchKey + "%", channelID, channelType})) {
|
||||
if (cursor == null) {
|
||||
return msgs;
|
||||
}
|
||||
@ -1021,9 +1042,9 @@ public class MsgDbManager {
|
||||
String sql = "select distinct c.*, count(*) message_count, case count(*) WHEN 1 then" +
|
||||
" m.client_seq else ''END client_seq, CASE count(*) WHEN 1 THEN m.searchable_word else '' end searchable_word " +
|
||||
"from " + channel + " c LEFT JOIN " + message + " m ON m.channel_id = c.channel_id and " +
|
||||
"m.channel_type = c.channel_type WHERE m.is_deleted=0 and searchable_word LIKE '%" + searchKey + "%' GROUP BY " +
|
||||
"m.channel_type = c.channel_type WHERE m.is_deleted=0 and searchable_word LIKE ? GROUP BY " +
|
||||
"c.channel_id, c.channel_type ORDER BY m.created_at DESC limit 100";
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql);
|
||||
Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{"%" + searchKey + "%"});
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -1092,24 +1113,25 @@ public class MsgDbManager {
|
||||
String whereStr = "";
|
||||
for (int contentType : contentTypes) {
|
||||
if (TextUtils.isEmpty(whereStr)) {
|
||||
whereStr = "(" + contentType;
|
||||
whereStr = contentType + "";
|
||||
} else {
|
||||
whereStr = "," + contentType;
|
||||
}
|
||||
}
|
||||
whereStr = whereStr + ")";
|
||||
|
||||
Object[] args;
|
||||
String sql;
|
||||
if (oldestOrderSeq <= 0) {
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id= " + messageExtra + ".message_id where " + message + ".channel_id='" + channelID + "' and " + message + ".channel_type=" + channelType + " and " + message + ".type<>0 and " + message + ".type<>99 and " + message + ".type in " + whereStr + ") where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
args = new Object[]{channelID, channelType, whereStr};
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id= " + messageExtra + ".message_id where " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".type<>0 and " + message + ".type<>99 and " + message + ".type in (?)) where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
} else {
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id= " + messageExtra + ".message_id where " + message + ".channel_id='" + channelID + "' and " + message + ".channel_type=" + channelType + " and " + message + ".order_seq<" + oldestOrderSeq + " and " + message + ".type<>0 and " + message + ".type<>99 and " + message + ".type in " + whereStr + ") where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
args = new Object[]{channelID, channelType, oldestOrderSeq, whereStr};
|
||||
sql = "select * from (select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id= " + messageExtra + ".message_id where " + message + ".channel_id=? and " + message + ".channel_type=? and " + message + ".order_seq<? and " + message + ".type<>0 and " + message + ".type<>99 and " + message + ".type in (?)) where is_deleted=0 and revoke=0 order by order_seq desc limit 0," + limit;
|
||||
}
|
||||
List<WKMsg> wkMsgs = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, args)) {
|
||||
if (cursor == null) {
|
||||
return wkMsgs;
|
||||
}
|
||||
@ -1139,13 +1161,13 @@ public class MsgDbManager {
|
||||
* @param channelType 频道类型
|
||||
*/
|
||||
public long queryMsgExtraMaxVersionWithChannel(String channelID, byte channelType) {
|
||||
String sql = "select * from " + messageExtra + " where channel_id ='" + channelID + "' and channel_type=" + channelType + " order by extra_version desc limit 1";
|
||||
String sql = "select * from " + messageExtra + " where channel_id =? and channel_type=? order by extra_version desc limit 1";
|
||||
Cursor cursor = null;
|
||||
long version = 0;
|
||||
try {
|
||||
cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql);
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType});
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1195,11 +1217,11 @@ public class MsgDbManager {
|
||||
|
||||
public WKMsg queryWithMessageID(String messageID, boolean isGetMsgReaction) {
|
||||
WKMsg msg = null;
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " LEFT JOIN " + messageExtra + " ON " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".message_id=" + "'" + messageID + "' and " + message + ".is_deleted=0";
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " LEFT JOIN " + messageExtra + " ON " + message + ".message_id=" + messageExtra + ".message_id WHERE " + message + ".message_id=? and " + message + ".is_deleted=0";
|
||||
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{messageID})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -1213,11 +1235,11 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public int queryMaxMessageOrderSeqWithChannel(String channelID, byte channelType) {
|
||||
String sql = "SELECT max(order_seq) order_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType;
|
||||
String sql = "SELECT max(order_seq) order_seq FROM " + message + " WHERE channel_id=? AND channel_type=?";
|
||||
int orderSeq = 0;
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType})) {
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1229,11 +1251,11 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public int queryMaxMessageSeqNotDeletedWithChannel(String channelID, byte channelType) {
|
||||
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType + " AND is_deleted=0";
|
||||
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id=? AND channel_type=? AND is_deleted=0";
|
||||
int messageSeq = 0;
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType})) {
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1245,11 +1267,11 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public int queryMaxMessageSeqWithChannel(String channelID, byte channelType) {
|
||||
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType;
|
||||
String sql = "SELECT max(message_seq) message_seq FROM " + message + " WHERE channel_id=? AND channel_type=?";
|
||||
int messageSeq = 0;
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType})) {
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1261,11 +1283,11 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public int queryMinMessageSeqWithChannel(String channelID, byte channelType) {
|
||||
String sql = "SELECT min(message_seq) message_seq FROM " + message + " WHERE channel_id='" + channelID + "' AND channel_type=" + channelType;
|
||||
String sql = "SELECT min(message_seq) message_seq FROM " + message + " WHERE channel_id=? AND channel_type=?";
|
||||
int messageSeq = 0;
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType})) {
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1280,12 +1302,12 @@ public class MsgDbManager {
|
||||
String sql;
|
||||
int messageSeq = 0;
|
||||
if (pullMode == 1) {
|
||||
sql = "select * from " + message + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and order_seq>" + oldestOrderSeq + " and message_seq<>0 order by message_seq desc limit 1";
|
||||
sql = "select * from " + message + " where channel_id=? and channel_type=? and order_seq>? and message_seq<>0 order by message_seq desc limit 1";
|
||||
} else
|
||||
sql = "select * from " + message + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and order_seq<" + oldestOrderSeq + " and message_seq<>0 order by message_seq asc limit 1";
|
||||
sql = "select * from " + message + " where channel_id=? and channel_type=? and order_seq<? and message_seq<>0 order by message_seq asc limit 1";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, oldestOrderSeq})) {
|
||||
if (cursor == null) {
|
||||
return 0;
|
||||
}
|
||||
@ -1305,8 +1327,7 @@ public class MsgDbManager {
|
||||
}
|
||||
sb.append("'").append(messageIds.get(i)).append("'");
|
||||
}
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".message_id in (" + sb + ")";
|
||||
WKLoggerUtils.getInstance().e("查询sql:" + sql);
|
||||
String sql = "select " + messageCols + "," + extraCols + " from " + message + " left join " + messageExtra + " on " + message + ".message_id=" + messageExtra + ".message_id where " + message + ".message_id in (?)";
|
||||
List<WKMsg> list = new ArrayList<>();
|
||||
List<String> gChannelIds = new ArrayList<>();
|
||||
List<String> pChannelIds = new ArrayList<>();
|
||||
@ -1314,7 +1335,7 @@ public class MsgDbManager {
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -1503,8 +1524,8 @@ public class MsgDbManager {
|
||||
|
||||
public List<WKMsgExtra> queryMsgExtraWithNeedUpload(int needUpload) {
|
||||
List<WKMsgExtra> list = new ArrayList<>();
|
||||
String sql = "select * from " + messageExtra + " where needUpload=" + needUpload;
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
String sql = "select * from " + messageExtra + " where needUpload=?";
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{needUpload})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -1517,14 +1538,14 @@ public class MsgDbManager {
|
||||
}
|
||||
|
||||
public WKMsgExtra queryMsgExtraWithMsgID(String msgID) {
|
||||
String sql = "select * from " + messageExtra + " where message_id='" + msgID + "'";
|
||||
String sql = "select * from " + messageExtra + " where message_id=?";
|
||||
WKMsgExtra extra = null;
|
||||
try {
|
||||
if (WKIMApplication.getInstance().getDbHelper() != null) {
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql);
|
||||
.rawQuery(sql,new Object[]{msgID});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
extra = serializeMsgExtra(cursor);
|
||||
|
@ -68,10 +68,10 @@ class MsgReactionDBManager {
|
||||
private boolean isExist(String uid, String messageID) {
|
||||
boolean isExist = false;
|
||||
String sql = "select * from " + messageReaction
|
||||
+ " where message_id='" + messageID + "' and uid='" + uid + "'";
|
||||
+ " where message_id=? and uid=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{messageID, uid})) {
|
||||
if (cursor != null && cursor.moveToLast()) {
|
||||
isExist = true;
|
||||
}
|
||||
@ -81,8 +81,8 @@ class MsgReactionDBManager {
|
||||
|
||||
public List<WKMsgReaction> queryWithMessageId(String messageID) {
|
||||
List<WKMsgReaction> list = new ArrayList<>();
|
||||
String sql = "select * from " + messageReaction + " where message_id='" + messageID + "' and is_deleted=0 ORDER BY created_at desc";
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
String sql = "select * from " + messageReaction + " where message_id=? and is_deleted=0 ORDER BY created_at desc";
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{messageID})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -108,13 +108,13 @@ class MsgReactionDBManager {
|
||||
}
|
||||
stringBuffer.append(messageIds.get(i));
|
||||
}
|
||||
String sql = "select * from " + messageReaction + " where message_id in (" + stringBuffer + ") and is_deleted=0 ORDER BY created_at desc";
|
||||
String sql = "select * from " + messageReaction + " where message_id in (?) and is_deleted=0 ORDER BY created_at desc";
|
||||
List<WKMsgReaction> list = new ArrayList<>();
|
||||
List<String> channelIds = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{stringBuffer.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -140,10 +140,10 @@ class MsgReactionDBManager {
|
||||
public WKMsgReaction queryWithMsgIdAndUIDAndText(String messageID, String uid, String emoji) {
|
||||
WKMsgReaction reaction = null;
|
||||
String sql = "select * from " + messageReaction
|
||||
+ " where message_id='" + messageID + "' and uid='" + uid + "' and emoji='" + emoji + "'";
|
||||
+ " where message_id=? and uid=? and emoji=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{messageID, uid, emoji})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -158,10 +158,10 @@ class MsgReactionDBManager {
|
||||
public WKMsgReaction queryWithMsgIdAndUID(String messageID, String uid) {
|
||||
WKMsgReaction reaction = null;
|
||||
String sql = "select * from " + messageReaction
|
||||
+ " where message_id='" + messageID + "' and uid='" + uid + "'";
|
||||
+ " where message_id=? and uid=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{messageID, uid})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -176,13 +176,13 @@ class MsgReactionDBManager {
|
||||
public long queryMaxSeqWithChannel(String channelID, byte channelType) {
|
||||
int maxSeq = 0;
|
||||
String sql = "select max(seq) seq from " + messageReaction
|
||||
+ " where channel_id='" + channelID + "' and channel_type=" + channelType + " limit 0, 1";
|
||||
+ " where channel_id=? and channel_type=? limit 0, 1";
|
||||
try {
|
||||
if (WKIMApplication.getInstance().getDbHelper() != null) {
|
||||
Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql);
|
||||
.rawQuery(sql, new Object[]{channelID, channelType});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
maxSeq = WKCursor.readInt(cursor, "seq");
|
||||
|
@ -48,9 +48,9 @@ public class ReminderDBManager {
|
||||
}
|
||||
|
||||
public List<WKReminder> queryWithChannelAndDone(String channelID, byte channelType, int done) {
|
||||
String sql = "select * from " + reminders + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " order by message_seq desc";
|
||||
String sql = "select * from " + reminders + " where channel_id=? and channel_type=? and done=? order by message_seq desc";
|
||||
List<WKReminder> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, done})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -62,10 +62,10 @@ public class ReminderDBManager {
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<WKReminder> queryWithChannelAndTypeAndDone(String channelID, byte channelType, int type,int done) {
|
||||
String sql = "select * from " + reminders + " where channel_id='" + channelID + "' and channel_type=" + channelType + " and done=" + done + " and type =" + type + " order by message_seq desc";
|
||||
public List<WKReminder> queryWithChannelAndTypeAndDone(String channelID, byte channelType, int type, int done) {
|
||||
String sql = "select * from " + reminders + " where channel_id=? and channel_type=? and done=? and type =? order by message_seq desc";
|
||||
List<WKReminder> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{channelID, channelType, done, type})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -85,12 +85,12 @@ public class ReminderDBManager {
|
||||
}
|
||||
stringBuffer.append(ids.get(i));
|
||||
}
|
||||
String sql = "select * from " + reminders + " where reminder_id in (" + stringBuffer + ")";
|
||||
String sql = "select * from " + reminders + " where reminder_id in (?)";
|
||||
List<WKReminder> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{stringBuffer.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -107,16 +107,16 @@ public class ReminderDBManager {
|
||||
StringBuilder stringBuffer = new StringBuilder();
|
||||
for (int i = 0, size = channelIds.size(); i < size; i++) {
|
||||
if (i != 0) {
|
||||
stringBuffer.append("'");
|
||||
stringBuffer.append(",");
|
||||
}
|
||||
stringBuffer.append(channelIds.get(i)).append("'");
|
||||
stringBuffer.append("'").append(channelIds.get(i)).append("'");
|
||||
}
|
||||
String sql = "select * from " + reminders + " where channel_id in ('" + stringBuffer + ")";
|
||||
String sql = "select * from " + reminders + " where channel_id in (?)";
|
||||
List<WKReminder> list = new ArrayList<>();
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper()
|
||||
.rawQuery(sql)) {
|
||||
.rawQuery(sql, new Object[]{stringBuffer.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ public class RobotDBManager {
|
||||
|
||||
public boolean isExitMenu(String robotID, String cmd) {
|
||||
boolean isExist = false;
|
||||
String sql = "select * from " + robotMenu + " where robot_id ='" + robotID + "' and cmd='" + cmd + "'";
|
||||
String sql = "select * from " + robotMenu + " where robot_id =? and cmd=?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{robotID, cmd})) {
|
||||
if (cursor != null && cursor.moveToLast()) {
|
||||
isExist = true;
|
||||
}
|
||||
@ -78,10 +78,10 @@ public class RobotDBManager {
|
||||
|
||||
public boolean isExist(String robotID) {
|
||||
boolean isExist = false;
|
||||
String sql = "select * from " + robot + " where robot_id ='" + robotID + "'";
|
||||
String sql = "select * from " + robot + " where robot_id =?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{robotID})) {
|
||||
if (cursor != null && cursor.moveToLast()) {
|
||||
isExist = true;
|
||||
}
|
||||
@ -138,10 +138,10 @@ public class RobotDBManager {
|
||||
|
||||
public WKRobot query(String robotID) {
|
||||
WKRobot wkRobot = null;
|
||||
String sql = "select * from " + robot + " where robot_id ='" + robotID + "'";
|
||||
String sql = "select * from " + robot + " where robot_id =?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{robotID})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -154,10 +154,10 @@ public class RobotDBManager {
|
||||
|
||||
public WKRobot queryWithUsername(String username) {
|
||||
WKRobot wkRobot = null;
|
||||
String sql = "select * from " + robot + " where username ='" + username + "'";
|
||||
String sql = "select * from " + robot + " where username =?";
|
||||
try (Cursor cursor = WKIMApplication
|
||||
.getInstance()
|
||||
.getDbHelper().rawQuery(sql)) {
|
||||
.getDbHelper().rawQuery(sql, new Object[]{username})) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
@ -169,17 +169,17 @@ public class RobotDBManager {
|
||||
}
|
||||
|
||||
public List<WKRobot> queryRobots(List<String> robotIds) {
|
||||
StringBuilder sb = new StringBuilder("select * from " + robot + " where robot_id in (");
|
||||
String sql = "select * from " + robot + " where robot_id in (?)";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < robotIds.size(); i++) {
|
||||
if (i != 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("'").append(robotIds.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
List<WKRobot> list = new ArrayList<>();
|
||||
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sb.toString())) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -192,17 +192,17 @@ public class RobotDBManager {
|
||||
}
|
||||
|
||||
public List<WKRobotMenu> queryRobotMenus(List<String> robotIds) {
|
||||
StringBuilder sb = new StringBuilder("select * from " + robotMenu + " where robot_id in (");
|
||||
String sql = "select * from " + robotMenu + " where robot_id in (?)";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < robotIds.size(); i++) {
|
||||
if (i != 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("'").append(robotIds.get(i)).append("'");
|
||||
}
|
||||
sb.append(")");
|
||||
List<WKRobotMenu> list = new ArrayList<>();
|
||||
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sb.toString())) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql, new Object[]{sb.toString()})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
@ -216,9 +216,9 @@ public class RobotDBManager {
|
||||
|
||||
public List<WKRobotMenu> queryRobotMenus(String robotID) {
|
||||
List<WKRobotMenu> list = new ArrayList<>();
|
||||
String sql = "select * from " + robotMenu + " where robot_id ='" + robotID + "'";
|
||||
String sql = "select * from " + robotMenu + " where robot_id =?";
|
||||
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql)) {
|
||||
try (Cursor cursor = WKIMApplication.getInstance().getDbHelper().rawQuery(sql,new Object[]{robotID})) {
|
||||
if (cursor == null) {
|
||||
return list;
|
||||
}
|
||||
|
@ -116,6 +116,13 @@ public class WKDBHelper {
|
||||
return mDb.rawQuery(sql, null);
|
||||
}
|
||||
|
||||
public Cursor rawQuery(String sql, Object[] selectionArgs) {
|
||||
if (mDb == null) {
|
||||
return null;
|
||||
}
|
||||
return mDb.rawQuery(sql, selectionArgs);
|
||||
}
|
||||
|
||||
public Cursor select(String table, String selection,
|
||||
String[] selectionArgs,
|
||||
String orderBy) {
|
||||
@ -135,7 +142,8 @@ public class WKDBHelper {
|
||||
if (mDb == null) return 0;
|
||||
long count = 0;
|
||||
try {
|
||||
count = mDb.insert(table, null, cv);
|
||||
count = mDb.insert(table, SQLiteDatabase.CONFLICT_REPLACE, cv);
|
||||
// count = mDb.insert(table, null, cv);
|
||||
} catch (Exception e) {
|
||||
StringBuilder fields = new StringBuilder();
|
||||
for (Map.Entry<String, Object> item : cv.valueSet()) {
|
||||
|
@ -1173,7 +1173,9 @@ public class MsgManager extends BaseManager {
|
||||
List<WKMsgExtra> list = MsgDbManager.getInstance().queryMsgExtraWithNeedUpload(1);
|
||||
if (list != null && list.size() > 0) {
|
||||
for (WKMsgExtra extra : list) {
|
||||
setUploadMsgExtra(extra);
|
||||
if (iUploadMsgExtraListener != null) {
|
||||
iUploadMsgExtraListener.onUpload(extra);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
checkMsgNeedUploadTimer.cancel();
|
||||
|
@ -173,6 +173,7 @@ class WKProto {
|
||||
sendAckMsg.clientSeq = wkRead.readInt();
|
||||
sendAckMsg.messageSeq = wkRead.readInt();
|
||||
sendAckMsg.reasonCode = wkRead.readByte();
|
||||
WKLoggerUtils.getInstance().e("发送ack" + sendAckMsg.messageID);
|
||||
WKLoggerUtils.getInstance().e("发送返回状态:" + sendAckMsg.reasonCode);
|
||||
} catch (IOException e) {
|
||||
WKLoggerUtils.getInstance().e("解码发送消息ack错误");
|
||||
@ -245,6 +246,7 @@ class WKProto {
|
||||
try {
|
||||
WKRead wkRead = new WKRead(bytes);
|
||||
int packetType = wkRead.readPacketType();
|
||||
WKLoggerUtils.getInstance().e("解码出包类型" + packetType);
|
||||
wkRead.readRemainingLength();
|
||||
if (packetType == WKMsgType.CONNACK) {
|
||||
int hasServerVersion = WKTypeUtils.getInstance().getBit(bytes[0], 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user