| 692 | } |
| 693 | |
| 694 | private static void createTriggers(@NonNull SupportSQLiteDatabase db) { |
| 695 | db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" + |
| 696 | " AFTER INSERT ON attachment" + |
| 697 | " BEGIN" + |
| 698 | " UPDATE message SET attachments = attachments + 1" + |
| 699 | " WHERE message.id = NEW.message" + |
| 700 | " AND NEW.encryption IS NULL" + |
| 701 | " AND NOT ((NEW.disposition = 'inline' OR (NEW.related IS NOT 0 AND NEW.cid IS NOT NULL)) AND NEW.type LIKE 'image/%');" + |
| 702 | " END"); |
| 703 | db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" + |
| 704 | " AFTER DELETE ON attachment" + |
| 705 | " BEGIN" + |
| 706 | " UPDATE message SET attachments = attachments - 1" + |
| 707 | " WHERE message.id = OLD.message" + |
| 708 | " AND OLD.encryption IS NULL" + |
| 709 | " AND NOT ((OLD.disposition = 'inline' OR (OLD.related IS NOT 0 AND OLD.cid IS NOT NULL)) AND OLD.type LIKE 'image/%');" + |
| 710 | " END"); |
| 711 | |
| 712 | db.execSQL("CREATE TRIGGER IF NOT EXISTS account_update" + |
| 713 | " AFTER UPDATE ON account" + |
| 714 | " BEGIN" + |
| 715 | " UPDATE account SET last_modified = strftime('%s') * 1000" + |
| 716 | " WHERE OLD.id = NEW.id" + |
| 717 | " AND OLD.last_modified = NEW.last_modified" + |
| 718 | " AND (NEW.auth_type = " + AUTH_TYPE_PASSWORD + " OR OLD.password = NEW.password)" + |
| 719 | " AND OLD.keep_alive_ok IS NEW.keep_alive_ok" + |
| 720 | " AND OLD.keep_alive_failed IS NEW.keep_alive_failed" + |
| 721 | " AND OLD.keep_alive_succeeded IS NEW.keep_alive_succeeded" + |
| 722 | " AND OLD.quota_usage IS NEW.quota_usage" + |
| 723 | " AND OLD.thread IS NEW.thread" + |
| 724 | " AND OLD.state IS NEW.state" + |
| 725 | " AND OLD.warning IS NEW.warning" + |
| 726 | " AND OLD.error IS NEW.error" + |
| 727 | " AND OLD.last_connected IS NEW.last_connected" + |
| 728 | " AND OLD.backoff_until IS NEW.backoff_until;" + |
| 729 | " END"); |
| 730 | |
| 731 | db.execSQL("CREATE TRIGGER IF NOT EXISTS identity_update" + |
| 732 | " AFTER UPDATE ON identity" + |
| 733 | " BEGIN" + |
| 734 | " UPDATE identity SET last_modified = strftime('%s') * 1000" + |
| 735 | " WHERE OLD.id = NEW.id" + |
| 736 | " AND OLD.last_modified = NEW.last_modified" + |
| 737 | " AND OLD.state IS NEW.state" + |
| 738 | " AND OLD.error IS NEW.error" + |
| 739 | " AND OLD.last_connected IS NEW.last_connected" + |
| 740 | " AND (NEW.auth_type = " + AUTH_TYPE_PASSWORD + " OR OLD.password = NEW.password);" + |
| 741 | " END"); |
| 742 | } |
| 743 | |
| 744 | private static void dataUpdates(SupportSQLiteDatabase db, Context context) { |
| 745 | try { |