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

相关文章

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

MySQL数据库中ENUM的用法是什么详解

《MySQL数据库中ENUM的用法是什么详解》ENUM是一个字符串对象,用于指定一组预定义的值,并可在创建表时使用,下面:本文主要介绍MySQL数据库中ENUM的用法是什么的相关资料,文中通过代码... 目录mysql 中 ENUM 的用法一、ENUM 的定义与语法二、ENUM 的特点三、ENUM 的用法1

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

Go语言数据库编程GORM 的基本使用详解

《Go语言数据库编程GORM的基本使用详解》GORM是Go语言流行的ORM框架,封装database/sql,支持自动迁移、关联、事务等,提供CRUD、条件查询、钩子函数、日志等功能,简化数据库操作... 目录一、安装与初始化1. 安装 GORM 及数据库驱动2. 建立数据库连接二、定义模型结构体三、自动迁

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、

MySQL数据库的内嵌函数和联合查询实例代码

《MySQL数据库的内嵌函数和联合查询实例代码》联合查询是一种将多个查询结果组合在一起的方法,通常使用UNION、UNIONALL、INTERSECT和EXCEPT关键字,下面:本文主要介绍MyS... 目录一.数据库的内嵌函数1.1聚合函数COUNT([DISTINCT] expr)SUM([DISTIN

MySQL追踪数据库表更新操作来源的全面指南

《MySQL追踪数据库表更新操作来源的全面指南》本文将以一个具体问题为例,如何监测哪个IP来源对数据库表statistics_test进行了UPDATE操作,文内探讨了多种方法,并提供了详细的代码... 目录引言1. 为什么需要监控数据库更新操作2. 方法1:启用数据库审计日志(1)mysql/mariad

postgresql数据库基本操作及命令详解

《postgresql数据库基本操作及命令详解》本文介绍了PostgreSQL数据库的基础操作,包括连接、创建、查看数据库,表的增删改查、索引管理、备份恢复及退出命令,适用于数据库管理和开发实践,感兴... 目录1. 连接 PostgreSQL 数据库2. 创建数据库3. 查看当前数据库4. 查看所有数据库