android Mms 数据库5

2024-03-31 09:38
文章标签 android 数据库 mms

本文主要是介绍android Mms 数据库5,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Mms数据库的triggers


1. threads表将SMS、MMS的信息组织成一个conversation,所以当MMS、SMS信息发生改变时也需要更新threads表

2. 维护pending_msgs表格,其中包含pending_msgs表用于存储待发送或下载的SMS/MMS

3. 维护错误标志位

    /*** the name of the table that is used to store the queue of* messages(both MMS and SMS) to be sent/downloaded.*/public static final String TABLE_PENDING_MSG = "pending_msgs";

    private void createCommonTriggers(SQLiteDatabase db) {// Updates threads table whenever a message is added to pdu.db.execSQL("CREATE TRIGGER pdu_update_thread_on_insert AFTER INSERT ON " +MmsProvider.TABLE_PDU + " " +PDU_UPDATE_THREAD_CONSTRAINTS +PDU_UPDATE_THREAD_DATE_SNIPPET_COUNT_ON_UPDATE);// Updates threads table whenever a message is added to sms.db.execSQL("CREATE TRIGGER sms_update_thread_on_insert AFTER INSERT ON sms " +SMS_UPDATE_THREAD_DATE_SNIPPET_COUNT_ON_UPDATE);// Updates threads table whenever a message in pdu is updated.db.execSQL("CREATE TRIGGER pdu_update_thread_date_subject_on_update AFTER" +"  UPDATE OF " + Mms.DATE + ", " + Mms.SUBJECT + ", " + Mms.MESSAGE_BOX +"  ON " + MmsProvider.TABLE_PDU + " " +PDU_UPDATE_THREAD_CONSTRAINTS +PDU_UPDATE_THREAD_DATE_SNIPPET_COUNT_ON_UPDATE);// Updates threads table whenever a message in sms is updated.db.execSQL("CREATE TRIGGER sms_update_thread_date_subject_on_update AFTER" +"  UPDATE OF " + Sms.DATE + ", " + Sms.BODY + ", " + Sms.TYPE +"  ON sms " +SMS_UPDATE_THREAD_DATE_SNIPPET_COUNT_ON_UPDATE);// Updates threads table whenever a message in pdu is updated.db.execSQL("CREATE TRIGGER pdu_update_thread_read_on_update AFTER" +"  UPDATE OF " + Mms.READ +"  ON " + MmsProvider.TABLE_PDU + " " +PDU_UPDATE_THREAD_CONSTRAINTS +"BEGIN " +PDU_UPDATE_THREAD_READ_BODY +"END;");// Updates threads table whenever a message in sms is updated.db.execSQL("CREATE TRIGGER sms_update_thread_read_on_update AFTER" +"  UPDATE OF " + Sms.READ +"  ON sms " +"BEGIN " +SMS_UPDATE_THREAD_READ_BODY +"END;");// Update threads table whenever a message in pdu is deleteddb.execSQL("CREATE TRIGGER pdu_update_thread_on_delete " +"AFTER DELETE ON pdu " +"BEGIN " +"  UPDATE threads SET " +"     date = (strftime('%s','now') * 1000)" +"  WHERE threads._id = old." + Mms.THREAD_ID + "; " +UPDATE_THREAD_COUNT_ON_OLD +UPDATE_THREAD_SNIPPET_SNIPPET_CS_ON_DELETE +"END;");// As of DATABASE_VERSION 55, we've removed these triggers that delete empty threads.// These triggers interfere with saving drafts on brand new threads. Instead of// triggers cleaning up empty threads, the empty threads should be cleaned up by// an explicit call to delete with Threads.OBSOLETE_THREADS_URI.//        // When the last message in a thread is deleted, these
//        // triggers ensure that the entry for its thread ID is removed
//        // from the threads table.
//        db.execSQL("CREATE TRIGGER delete_obsolete_threads_pdu " +
//                   "AFTER DELETE ON pdu " +
//                   "BEGIN " +
//                   "  DELETE FROM threads " +
//                   "  WHERE " +
//                   "    _id = old.thread_id " +
//                   "    AND _id NOT IN " +
//                   "    (SELECT thread_id FROM sms " +
//                   "     UNION SELECT thread_id from pdu); " +
//                   "END;");
//
//        db.execSQL("CREATE TRIGGER delete_obsolete_threads_when_update_pdu " +
//                   "AFTER UPDATE OF " + Mms.THREAD_ID + " ON pdu " +
//                   "WHEN old." + Mms.THREAD_ID + " != new." + Mms.THREAD_ID + " " +
//                   "BEGIN " +
//                   "  DELETE FROM threads " +
//                   "  WHERE " +
//                   "    _id = old.thread_id " +
//                   "    AND _id NOT IN " +
//                   "    (SELECT thread_id FROM sms " +
//                   "     UNION SELECT thread_id from pdu); " +
//                   "END;");// Insert pending status for M-Notification.ind or M-ReadRec.ind// when they are inserted into Inbox/Outbox.db.execSQL("CREATE TRIGGER insert_mms_pending_on_insert " +"AFTER INSERT ON pdu " +"WHEN new." + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND +"  OR new." + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_READ_REC_IND +" " +"BEGIN " +"  INSERT INTO " + MmsSmsProvider.TABLE_PENDING_MSG +"    (" + PendingMessages.PROTO_TYPE + "," +"     " + PendingMessages.MSG_ID + "," +"     " + PendingMessages.MSG_TYPE + "," +"     " + PendingMessages.ERROR_TYPE + "," +"     " + PendingMessages.ERROR_CODE + "," +"     " + PendingMessages.RETRY_INDEX + "," +"     " + PendingMessages.DUE_TIME + ") " +"  VALUES " +"    (" + MmsSms.MMS_PROTO + "," +"      new." + BaseColumns._ID + "," +"      new." + Mms.MESSAGE_TYPE + ",0,0,0,0);" +"END;");// Insert pending status for M-Send.req when it is moved into Outbox.db.execSQL("CREATE TRIGGER insert_mms_pending_on_update " +"AFTER UPDATE ON pdu " +"WHEN new." + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_SEND_REQ +"  AND new." + Mms.MESSAGE_BOX + "=" + Mms.MESSAGE_BOX_OUTBOX +"  AND old." + Mms.MESSAGE_BOX + "!=" + Mms.MESSAGE_BOX_OUTBOX + " " +"BEGIN " +"  INSERT INTO " + MmsSmsProvider.TABLE_PENDING_MSG +"    (" + PendingMessages.PROTO_TYPE + "," +"     " + PendingMessages.MSG_ID + "," +"     " + PendingMessages.MSG_TYPE + "," +"     " + PendingMessages.ERROR_TYPE + "," +"     " + PendingMessages.ERROR_CODE + "," +"     " + PendingMessages.RETRY_INDEX + "," +"     " + PendingMessages.DUE_TIME + ") " +"  VALUES " +"    (" + MmsSms.MMS_PROTO + "," +"      new." + BaseColumns._ID + "," +"      new." + Mms.MESSAGE_TYPE + ",0,0,0,0);" +"END;");// When a message is moved out of Outbox, delete its pending status.db.execSQL("CREATE TRIGGER delete_mms_pending_on_update " +"AFTER UPDATE ON " + MmsProvider.TABLE_PDU + " " +"WHEN old." + Mms.MESSAGE_BOX + "=" + Mms.MESSAGE_BOX_OUTBOX +"  AND new." + Mms.MESSAGE_BOX + "!=" + Mms.MESSAGE_BOX_OUTBOX + " " +"BEGIN " +"  DELETE FROM " + MmsSmsProvider.TABLE_PENDING_MSG +"  WHERE " + PendingMessages.MSG_ID + "=new._id; " +"END;");// Delete pending status for a message when it is deleted.db.execSQL("CREATE TRIGGER delete_mms_pending_on_delete " +"AFTER DELETE ON " + MmsProvider.TABLE_PDU + " " +"BEGIN " +"  DELETE FROM " + MmsSmsProvider.TABLE_PENDING_MSG +"  WHERE " + PendingMessages.MSG_ID + "=old._id; " +"END;");// TODO Add triggers for SMS retry-status management.// Update the error flag of threads when the error type of// a pending MM is updated.db.execSQL("CREATE TRIGGER update_threads_error_on_update_mms " +"  AFTER UPDATE OF err_type ON pending_msgs " +"  WHEN (OLD.err_type < 10 AND NEW.err_type >= 10)" +"    OR (OLD.err_type >= 10 AND NEW.err_type < 10) " +"BEGIN" +"  UPDATE threads SET error = " +"    CASE" +"      WHEN NEW.err_type >= 10 THEN error + 1" +"      ELSE error - 1" +"    END " +"  WHERE _id =" +"   (SELECT DISTINCT thread_id" +"    FROM pdu" +"    WHERE _id = NEW.msg_id); " +"END;");// Update the error flag of threads when delete pending message.db.execSQL("CREATE TRIGGER update_threads_error_on_delete_mms " +"  BEFORE DELETE ON pdu" +"  WHEN OLD._id IN (SELECT DISTINCT msg_id" +"                   FROM pending_msgs" +"                   WHERE err_type >= 10) " +"BEGIN " +"  UPDATE threads SET error = error - 1" +"  WHERE _id = OLD.thread_id; " +"END;");// Update the error flag of threads while moving an MM out of Outbox,// which was failed to be sent permanently.db.execSQL("CREATE TRIGGER update_threads_error_on_move_mms " +"  BEFORE UPDATE OF msg_box ON pdu " +"  WHEN (OLD.msg_box = 4 AND NEW.msg_box != 4) " +"  AND (OLD._id IN (SELECT DISTINCT msg_id" +"                   FROM pending_msgs" +"                   WHERE err_type >= 10)) " +"BEGIN " +"  UPDATE threads SET error = error - 1" +"  WHERE _id = OLD.thread_id; " +"END;");// Update the error flag of threads after a text message was// failed to send/receive.db.execSQL("CREATE TRIGGER update_threads_error_on_update_sms " +"  AFTER UPDATE OF type ON sms" +"  WHEN (OLD.type != 5 AND NEW.type = 5)" +"    OR (OLD.type = 5 AND NEW.type != 5) " +"BEGIN " +"  UPDATE threads SET error = " +"    CASE" +"      WHEN NEW.type = 5 THEN error + 1" +"      ELSE error - 1" +"    END " +"  WHERE _id = NEW.thread_id; " +"END;");}


4. 特别为Mms设计的triggers

从中可以得知对于Mms delivery report/read report信息是分别作为一条数据项放在pdu表中的。


        // Cleans up parts when a MM is deleted.db.execSQL("CREATE TRIGGER part_cleanup DELETE ON " + MmsProvider.TABLE_PDU + " " +"BEGIN " +"  DELETE FROM " + MmsProvider.TABLE_PART +"  WHERE " + Part.MSG_ID + "=old._id;" +"END;");// Cleans up address info when a MM is deleted.db.execSQL("CREATE TRIGGER addr_cleanup DELETE ON " + MmsProvider.TABLE_PDU + " " +"BEGIN " +"  DELETE FROM " + MmsProvider.TABLE_ADDR +"  WHERE " + Addr.MSG_ID + "=old._id;" +"END;");// Delete obsolete delivery-report, read-report while deleting their// associated Send.req.db.execSQL("CREATE TRIGGER cleanup_delivery_and_read_report " +"AFTER DELETE ON " + MmsProvider.TABLE_PDU + " " +"WHEN old." + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_SEND_REQ + " " +"BEGIN " +"  DELETE FROM " + MmsProvider.TABLE_PDU +"  WHERE (" + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_DELIVERY_IND +"    OR " + Mms.MESSAGE_TYPE + "=" + PduHeaders.MESSAGE_TYPE_READ_ORIG_IND +")" +"    AND " + Mms.MESSAGE_ID + "=old." + Mms.MESSAGE_ID + "; " +"END;");// Update threads table to indicate whether attachments exist when// parts are inserted or deleted.db.execSQL(PART_UPDATE_THREADS_ON_INSERT_TRIGGER);db.execSQL(PART_UPDATE_THREADS_ON_UPDATE_TRIGGER);db.execSQL(PART_UPDATE_THREADS_ON_DELETE_TRIGGER);db.execSQL(PDU_UPDATE_THREADS_ON_UPDATE_TRIGGER);




这篇关于android Mms 数据库5的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/864024

相关文章

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

MySQL数据库宕机,启动不起来,教你一招搞定!

作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG、Mongodb数据库运维(如安装迁移,性能优化、故障应急处理等)公众号:老苏畅谈运维欢迎关注本人公众号,更多精彩与您分享。 MySQL数据库宕机,数据页损坏问题,启动不起来,该如何排查和解决,本文将为你说明具体的排查过程。 查看MySQL error日志 查看 MySQL error日志,排查哪个表(表空间

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

深入理解数据库的 4NF:多值依赖与消除数据异常

在数据库设计中, "范式" 是一个常常被提到的重要概念。许多初学者在学习数据库设计时,经常听到第一范式(1NF)、第二范式(2NF)、第三范式(3NF)以及 BCNF(Boyce-Codd范式)。这些范式都旨在通过消除数据冗余和异常来优化数据库结构。然而,当我们谈到 4NF(第四范式)时,事情变得更加复杂。本文将带你深入了解 多值依赖 和 4NF,帮助你在数据库设计中消除更高级别的异常。 什么是

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

android应用中res目录说明

Android应用的res目录是一个特殊的项目,该项目里存放了Android应用所用的全部资源,包括图片、字符串、颜色、尺寸、样式等,类似于web开发中的public目录,js、css、image、style。。。。 Android按照约定,将不同的资源放在不同的文件夹中,这样可以方便的让AAPT(即Android Asset Packaging Tool , 在SDK的build-tools目

Android fill_parent、match_parent、wrap_content三者的作用及区别

这三个属性都是用来适应视图的水平或者垂直大小,以视图的内容或尺寸为基础的布局,比精确的指定视图的范围更加方便。 1、fill_parent 设置一个视图的布局为fill_parent将强制性的使视图扩展至它父元素的大小 2、match_parent 和fill_parent一样,从字面上的意思match_parent更贴切一些,于是从2.2开始,两个属性都可以使用,但2.3版本以后的建议使