热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

按排序顺序存储传入的消息(根据传入的号码)-storetheincomingmessagesinsortedorder(aspertheincomingnumbers)

Iamdesigninganappinthatiamstoringtheincomingmessagesinmyowncreateddatabaseandfrom

I am designing an app in that i am storing the incoming messages in my own created database and from this database i am displaying these messages in my application. for this i am using this code, To insert the data,

我正在设计一个应用程序,我将传入的消息存储在我自己创建的数据库中,从这个数据库我在我的应用程序中显示这些消息。为此我使用此代码,要插入数据,

mydb =  openOrCreateDatabase("db",MODE_PRIVATE, null);                              
        mydb.execSQL("CREATE TABLE IF NOT EXISTS sms_inbox (SMS_TEXT varchar , SENDER_NUMBER varchar );");      

        mydb.execSQL("INSERT INTO sms_inbox VALUES('" + stBody + "', '" + stPhoneNumber + "');");

To read the data,

要读取数据,

Cursor c = mydb.rawQuery("SELECT * from sms_inbox", null);

and then i am displaying these messages,

然后我显示这些消息,

So now my problem is this that I want to store these messages according to the phone numbers, example,

所以现在我的问题是,我想根据电话号码存储这些消息,例如,

phoneno.-12345 "ALL the messages of 12345 will be shown here" phone no.-23456 "ALL the messages of 23456 will be shown here"

phoneno.-12345“12345的所有信息将在这里显示”电话号码-23456“23456的所有信息将在这里显示”

1 个解决方案

#1


2  

Well, you could store those messages as another entry in sms_inbox table, but it would be helpful to store a timestamp as well to be able to distinguish each message.

好吧,您可以将这些消息存储为sms_inbox表中的另一个条目,但存储时间戳以及区分每条消息也会很有帮助。

When you query you could pass the phone number as what is the phone number you're interested into: SELECT * from sms_inbox where 'SENDER_NUMBER' = '?'

当您查询时,您可以将电话号码作为您感兴趣的电话号码传递:SELECT * from sms_inbox其中'SENDER_NUMBER'='?'

Or you could make a select ordered by SENDER_NUMBER: SELECT * from sms_inbox order by 'SENDER_NUMBER' desc;

或者您可以按SENDER_NUMBER命令选择SENDER_NUMBER:SELECT * from sms_inbox order by'SENDER_NUMBER'desc;

In the end it all depends on the use-cases you have. You could also use another table for keeping only the messages for a number and map a one-to-many relationship.

最后,这一切都取决于你拥有的用例。您还可以使用另一个表来仅保留数字的消息并映射一对多关系。


推荐阅读
author-avatar
wen260693700
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有