Home | History | Annotate | Download | only in telephony

Lines Matching refs:db

217     static final String DATABASE_NAME = "mmssms.db";
244 private static void removeUnferencedCanonicalAddresses(SQLiteDatabase db) {
245 Cursor c = db.query(MmsSmsProvider.TABLE_THREADS, new String[] { "recipient_ids" },
251 int rows = db.delete("canonical_addresses", null, null);
276 int rows = db.delete("canonical_addresses", sb.toString(), null);
285 public static void updateThread(SQLiteDatabase db, long thread_id) {
287 updateAllThreads(db, null, null);
291 db.beginTransaction();
296 int rows = db.delete(MmsSmsProvider.TABLE_THREADS,
303 removeUnferencedCanonicalAddresses(db);
307 db.execSQL(
323 db.execSQL(
351 Cursor c = db.rawQuery(query, null);
361 c = db.rawQuery(errorQuery, null);
368 db.execSQL("UPDATE threads SET error=" + setError +
377 db.setTransactionSuccessful();
381 db.endTransaction();
385 public static void updateAllThreads(SQLiteDatabase db, String where, String[] whereArgs) {
386 db.beginTransaction();
395 Cursor c = db.rawQuery(query, whereArgs);
399 updateThread(db, c.getInt(0));
405 // TODO: there are several db operations in this function. Lets wrap them in a
408 db.delete(MmsSmsProvider.TABLE_THREADS,
413 removeUnferencedCanonicalAddresses(db);
415 db.setTransactionSuccessful();
419 db.endTransaction();
423 public static int deleteOneSms(SQLiteDatabase db, int message_id) {
426 Cursor c = db.query("sms", new String[] { "thread_id" },
436 int rows = db.delete("sms", "_id=" + message_id, null);
439 updateThread(db, thread_id);
445 public void onCreate(SQLiteDatabase db) {
446 createMmsTables(db);
447 createSmsTables(db);
448 createCommonTables(db);
449 createCommonTriggers(db);
450 createMmsTriggers(db);
451 createWordsTables(db);
452 createIndices(db);
457 private void populateWordsTable(SQLiteDatabase db) {
460 Cursor smsRows = db.query(
482 db.insert(TABLE_WORDS, Telephony.MmsSms.WordsTable.INDEXED_TEXT, cv);
493 Cursor mmsRows = db.query(
515 db.insert(TABLE_WORDS, Telephony.MmsSms.WordsTable.INDEXED_TEXT, cv);
526 private void createWordsTables(SQLiteDatabase db) {
528 db.execSQL("CREATE VIRTUAL TABLE words USING FTS3 (_id INTEGER PRIMARY KEY, index_text TEXT, source_id INTEGER, table_to_use INTEGER);");
535 db.execSQL("CREATE TRIGGER sms_words_update AFTER UPDATE ON sms BEGIN UPDATE words " +
538 db.execSQL("CREATE TRIGGER sms_words_delete AFTER DELETE ON sms BEGIN DELETE FROM " +
541 populateWordsTable(db);
547 private void createIndices(SQLiteDatabase db) {
548 createThreadIdIndex(db);
551 private void createThreadIdIndex(SQLiteDatabase db) {
553 db.execSQL("CREATE INDEX IF NOT EXISTS typeThreadIdIndex ON sms" +
560 private void createMmsTables(SQLiteDatabase db) {
563 db.execSQL("CREATE TABLE " + MmsProvider.TABLE_PDU + " (" +
599 db.execSQL("CREATE TABLE " + MmsProvider.TABLE_ADDR + " (" +
607 db.execSQL("CREATE TABLE " + MmsProvider.TABLE_PART + " (" +
623 db.execSQL("CREATE TABLE " + MmsProvider.TABLE_RATE + " (" +
626 db.execSQL("CREATE TABLE " + MmsProvider.TABLE_DRM + " (" +
633 private void createMmsTriggers(SQLiteDatabase db) {
635 db.execSQL("DROP TRIGGER IF EXISTS part_cleanup");
636 db.execSQL("CREATE TRIGGER part_cleanup DELETE ON " + MmsProvider.TABLE_PDU + " " +
643 db.execSQL("DROP TRIGGER IF EXISTS addr_cleanup");
644 db.execSQL("CREATE TRIGGER addr_cleanup DELETE ON " + MmsProvider.TABLE_PDU + " " +
652 db.execSQL("DROP TRIGGER IF EXISTS cleanup_delivery_and_read_report");
653 db.execSQL("CREATE TRIGGER cleanup_delivery_and_read_report " +
664 db.execSQL("DROP TRIGGER IF EXISTS update_threads_on_insert_part");
665 db.execSQL(PART_UPDATE_THREADS_ON_INSERT_TRIGGER);
667 db.execSQL("DROP TRIGGER IF EXISTS update_threads_on_update_part");
668 db.execSQL(PART_UPDATE_THREADS_ON_UPDATE_TRIGGER);
670 db.execSQL("DROP TRIGGER IF EXISTS update_threads_on_delete_part");
671 db.execSQL(PART_UPDATE_THREADS_ON_DELETE_TRIGGER);
673 db.execSQL("DROP TRIGGER IF EXISTS update_threads_on_update_pdu");
674 db.execSQL(PDU_UPDATE_THREADS_ON_UPDATE_TRIGGER);
677 db.execSQL("DROP TRIGGER IF EXISTS delete_mms_pending_on_delete");
678 db.execSQL("CREATE TRIGGER delete_mms_pending_on_delete " +
686 db
687 db.execSQL("CREATE TRIGGER delete_mms_pending_on_update " +
698 db.execSQL("DROP TRIGGER IF EXISTS insert_mms_pending_on_insert");
699 db.execSQL("CREATE TRIGGER insert_mms_pending_on_insert " +
721 db.execSQL("DROP TRIGGER IF EXISTS insert_mms_pending_on_update");
722 db.execSQL("CREATE TRIGGER insert_mms_pending_on_update " +
743 db.execSQL("DROP TRIGGER IF EXISTS mms_words_update");
744 db.execSQL("CREATE TRIGGER mms_words_update AFTER UPDATE ON part BEGIN UPDATE words " +
748 db.execSQL("DROP TRIGGER IF EXISTS mms_words_delete");
749 db.execSQL("CREATE TRIGGER mms_words_delete AFTER DELETE ON part BEGIN DELETE FROM " +
753 db.execSQL("DROP TRIGGER IF EXISTS pdu_update_thread_date_subject_on_update");
754 db.execSQL("CREATE TRIGGER pdu_update_thread_date_subject_on_update AFTER" +
761 db.execSQL("DROP TRIGGER IF EXISTS pdu_update_thread_on_delete");
762 db.execSQL("CREATE TRIGGER pdu_update_thread_on_delete " +
773 db.execSQL("DROP TRIGGER IF EXISTS pdu_update_thread_on_insert");
774 db.execSQL("CREATE TRIGGER pdu_update_thread_on_insert AFTER INSERT ON " +
780 db.execSQL("DROP TRIGGER IF EXISTS pdu_update_thread_read_on_update");
781 db.execSQL("CREATE TRIGGER pdu_update_thread_read_on_update AFTER" +
790 db.execSQL("DROP TRIGGER IF EXISTS update_threads_error_on_delete_mms");
791 db.execSQL("CREATE TRIGGER update_threads_error_on_delete_mms " +
803 db.execSQL("DROP TRIGGER IF EXISTS update_threads_error_on_move_mms");
804 db.execSQL("CREATE TRIGGER update_threads_error_on_move_mms " +
816 private void createSmsTables(SQLiteDatabase db) {
819 db.execSQL("CREATE TABLE sms (" +
846 db.execSQL("CREATE TABLE raw (" +
856 db.execSQL("CREATE TABLE attachments (" +
865 db.execSQL("CREATE TABLE sr_pending (" +
871 private void createCommonTables(SQLiteDatabase db) {
884 db.execSQL("CREATE TABLE canonical_addresses (" +
896 db.execSQL("CREATE TABLE threads (" +
911 db.execSQL("CREATE TABLE " + MmsSmsProvider.TABLE_PENDING_MSG +" (" +
925 private void createCommonTriggers(SQLiteDatabase db) {
927 db.execSQL("CREATE TRIGGER sms_update_thread_on_insert AFTER INSERT ON sms " +
931 db.execSQL("CREATE TRIGGER sms_update_thread_date_subject_on_update AFTER" +
937 db.execSQL("CREATE TRIGGER sms_update_thread_read_on_update AFTER" +
952 // db.execSQL("CREATE TRIGGER delete_obsolete_threads_pdu " +
963 // db.execSQL("CREATE TRIGGER delete_obsolete_threads_when_update_pdu " +
979 db.execSQL("CREATE TRIGGER update_threads_error_on_update_mms " +
997 db.execSQL("CREATE TRIGGER update_threads_error_on_update_sms " +
1012 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
1022 db.beginTransaction();
1024 upgradeDatabaseToVersion41(db);
1025 db.setTransactionSuccessful();
1030 db.endTransaction();
1038 db.beginTransaction();
1040 upgradeDatabaseToVersion42(db);
1041 db.setTransactionSuccessful();
1046 db.endTransaction();
1054 db.beginTransaction();
1056 upgradeDatabaseToVersion43(db);
1057 db.setTransactionSuccessful();
1062 db.endTransaction();
1070 db.beginTransaction();
1072 upgradeDatabaseToVersion44(db);
1073 db.setTransactionSuccessful();
1078 db.endTransaction();
1086 db.beginTransaction();
1088 upgradeDatabaseToVersion45(db);
1089 db.setTransactionSuccessful();
1094 db.endTransaction();
1101 db.beginTransaction();
1103 upgradeDatabaseToVersion46(db);
1104 db.setTransactionSuccessful();
1109 db.endTransaction();
1117 db.beginTransaction();
1119 upgradeDatabaseToVersion47(db);
1120 db.setTransactionSuccessful();
1125 db.endTransaction();
1133 db.beginTransaction();
1135 upgradeDatabaseToVersion48(db);
1136 db.setTransactionSuccessful();
1141 db.endTransaction();
1149 db.beginTransaction();
1151 createWordsTables(db);
1152 db.setTransactionSuccessful();
1157 db.endTransaction();
1164 db.beginTransaction();
1166 createThreadIdIndex(db);
1167 db.setTransactionSuccessful();
1172 db.endTransaction();
1180 db.beginTransaction();
1182 upgradeDatabaseToVersion51(db);
1183 db.setTransactionSuccessful();
1188 db.endTransaction();
1202 db.beginTransaction();
1204 upgradeDatabaseToVersion53(db);
1205 db.setTransactionSuccessful();
1210 db.endTransaction();
1218 db.beginTransaction();
1220 upgradeDatabaseToVersion54(db);
1221 db.setTransactionSuccessful();
1226 db.endTransaction();
1234 db.beginTransaction();
1236 upgradeDatabaseToVersion55(db);
1237 db.setTransactionSuccessful();
1242 db.endTransaction();
1250 db.beginTransaction();
1252 upgradeDatabaseToVersion56(db);
1253 db.setTransactionSuccessful();
1258 db.endTransaction();
1266 db.beginTransaction();
1268 upgradeDatabaseToVersion57(db);
1269 db.setTransactionSuccessful();
1274 db.endTransaction();
1280 dropAll(db);
1281 onCreate(db);
1284 private void dropAll(SQLiteDatabase db) {
1288 db.execSQL("DROP TABLE IF EXISTS canonical_addresses");
1289 db.execSQL("DROP TABLE IF EXISTS threads");
1290 db.execSQL("DROP TABLE IF EXISTS " + MmsSmsProvider.TABLE_PENDING_MSG);
1291 db.execSQL("DROP TABLE IF EXISTS sms");
1292 db.execSQL("DROP TABLE IF EXISTS raw");
1293 db.execSQL("DROP TABLE IF EXISTS attachments");
1294 db.execSQL("DROP TABLE IF EXISTS thread_ids");
1295 db.execSQL("DROP TABLE IF EXISTS sr_pending");
1296 db.execSQL("DROP TABLE IF EXISTS " + MmsProvider.TABLE_PDU + ";");
1297 db.execSQL("DROP TABLE IF EXISTS " + MmsProvider.TABLE_ADDR + ";");
1298 db.execSQL("DROP TABLE IF EXISTS " + MmsProvider.TABLE_PART + ";");
1299 db.execSQL("DROP TABLE IF EXISTS " + MmsProvider.TABLE_RATE + ";");
1300 db.execSQL("DROP TABLE IF EXISTS " + MmsProvider.TABLE_DRM + ";");
1303 private void upgradeDatabaseToVersion41(SQLiteDatabase db) {
1304 db.execSQL("DROP TRIGGER IF EXISTS update_threads_error_on_move_mms");
1305 db.execSQL("CREATE TRIGGER update_threads_error_on_move_mms " +
1317 private void upgradeDatabaseToVersion42(SQLiteDatabase db) {
1318 db.execSQL("DROP TRIGGER IF EXISTS sms_update_thread_on_delete");
1319 db.execSQL("DROP TRIGGER IF EXISTS delete_obsolete_threads_sms");
1320 db.execSQL("DROP TRIGGER IF EXISTS update_threads_error_on_delete_sms");
1323 private void upgradeDatabaseToVersion43(SQLiteDatabase db) {
1325 db.execSQL("ALTER TABLE threads ADD COLUMN has_attachment INTEGER DEFAULT 0");
1327 updateThreadsAttachmentColumn(db);
1330 db.execSQL(PART_UPDATE_THREADS_ON_INSERT_TRIGGER);
1331 db.execSQL(PART_UPDATE_THREADS_ON_DELETE_TRIGGER);
1334 private void upgradeDatabaseToVersion44(SQLiteDatabase db) {
1335 updateThreadsAttachmentColumn(db);
1338 db.execSQL(PART_UPDATE_THREADS_ON_UPDATE_TRIGGER);
1341 private void upgradeDatabaseToVersion45(SQLiteDatabase db) {
1343 db.execSQL("ALTER TABLE sms ADD COLUMN " + Sms.LOCKED + " INTEGER DEFAULT 0");
1346 db.execSQL("ALTER TABLE pdu ADD COLUMN " + Mms.LOCKED + " INTEGER DEFAULT 0");
1349 private void upgradeDatabaseToVersion46(SQLiteDatabase db) {
1352 db.execSQL("ALTER TABLE part ADD COLUMN " + Part.TEXT + " TEXT");
1354 Cursor textRows = db.query(
1364 db.beginTransaction();
1380 db.execSQL("UPDATE part SET " + Part._DATA + " = NULL, " +
1391 db.setTransactionSuccessful();
1393 db.endTransaction();
1407 private void upgradeDatabaseToVersion47(SQLiteDatabase db) {
1408 updateThreadsAttachmentColumn(db);
1411 db.execSQL(PDU_UPDATE_THREADS_ON_UPDATE_TRIGGER);
1414 private void upgradeDatabaseToVersion48(SQLiteDatabase db) {
1416 db.execSQL("ALTER TABLE sms ADD COLUMN error_code INTEGER DEFAULT 0");
1419 private void upgradeDatabaseToVersion51(SQLiteDatabase db) {
1420 db.execSQL("ALTER TABLE sms add COLUMN seen INTEGER DEFAULT 0");
1421 db.execSQL("ALTER TABLE pdu add COLUMN seen INTEGER DEFAULT 0");
1428 int count = db.update("sms", contentValues, "read=1", null);
1431 count = db.update("pdu", contentValues, "read=1", null);
1439 private void upgradeDatabaseToVersion53(SQLiteDatabase db) {
1440 db.execSQL("DROP TRIGGER IF EXISTS pdu_update_thread_read_on_update");
1443 db.execSQL("CREATE TRIGGER pdu_update_thread_read_on_update AFTER" +
1452 private void upgradeDatabaseToVersion54(SQLiteDatabase db) {
1454 db.execSQL("ALTER TABLE sms ADD COLUMN " + Sms.DATE_SENT + " INTEGER DEFAULT 0");
1457 db.execSQL("ALTER TABLE pdu ADD COLUMN " + Mms.DATE_SENT + " INTEGER DEFAULT 0");
1460 private void upgradeDatabaseToVersion55(SQLiteDatabase db) {
1462 db.execSQL("DROP TRIGGER IF EXISTS delete_obsolete_threads_pdu");
1463 db.execSQL("DROP TRIGGER IF EXISTS delete_obsolete_threads_when_update_pdu");
1466 private void upgradeDatabaseToVersion56(SQLiteDatabase db) {
1468 db
1472 private void upgradeDatabaseToVersion57(SQLiteDatabase db) {
1474 db.execSQL("DELETE FROM " + MmsProvider.TABLE_PDU + " WHERE " + Mms.THREAD_ID + " IS NULL");
1479 SQLiteDatabase db = super.getWritableDatabase();
1483 boolean hasAutoIncrementThreads = hasAutoIncrement(db, MmsSmsProvider.TABLE_THREADS);
1484 boolean hasAutoIncrementAddresses = hasAutoIncrement(db, "canonical_addresses");
1485 boolean hasAutoIncrementPart = hasAutoIncrement(db, "part");
1486 boolean hasAutoIncrementPdu = hasAutoIncrement(db, "pdu");
1496 db.beginTransaction();
1503 upgradeThreadsTableToAutoIncrement(db); // a no-op if already upgraded
1504 db.setTransactionSuccessful();
1509 db.endTransaction();
1513 db.beginTransaction();
1520 upgradeAddressTableToAutoIncrement(db); // a no-op if already upgraded
1521 db.setTransactionSuccessful();
1527 db.endTransaction();
1531 db.beginTransaction();
1538 upgradePartTableToAutoIncrement(db); // a no-op if already upgraded
1539 db.setTransactionSuccessful();
1545 db.endTransaction();
1549 db.beginTransaction();
1556 upgradePduTableToAutoIncrement(db); // a no-op if already upgraded
1557 db.setTransactionSuccessful();
1563 db.endTransaction();
1593 return db;
1597 private boolean hasAutoIncrement(SQLiteDatabase db, String tableName) {
1601 Cursor c = db.rawQuery(query, null);
1621 private void upgradeThreadsTableToAutoIncrement(SQLiteDatabase db) {
1622 if (hasAutoIncrement(db, MmsSmsProvider.TABLE_THREADS)) {
1631 db.execSQL("CREATE TABLE threads_temp (" +
1643 db.execSQL("INSERT INTO threads_temp SELECT * from threads;");
1644 db.execSQL("DROP TABLE threads;");
1645 db.execSQL("ALTER TABLE threads_temp RENAME TO threads;");
1652 private void upgradeAddressTableToAutoIncrement(SQLiteDatabase db) {
1653 if (hasAutoIncrement(db, "canonical_addresses")) {
1662 db.execSQL("CREATE TABLE canonical_addresses_temp (_id INTEGER PRIMARY KEY AUTOINCREMENT," +
1665 db.execSQL("INSERT INTO canonical_addresses_temp SELECT * from canonical_addresses;");
1666 db.execSQL("DROP TABLE canonical_addresses;");
1667 db.execSQL("ALTER TABLE canonical_addresses_temp RENAME TO canonical_addresses;");
1674 private void upgradePartTableToAutoIncrement(SQLiteDatabase db) {
1675 if (hasAutoIncrement(db, "part")) {
1684 db.execSQL("CREATE TABLE part_temp (" +
1700 db.execSQL("INSERT INTO part_temp SELECT * from part;");
1701 db.execSQL("DROP TABLE part;");
1702 db.execSQL("ALTER TABLE part_temp RENAME TO part;");
1705 createMmsTriggers(db);
1712 private void upgradePduTableToAutoIncrement(SQLiteDatabase db) {
1713 if (hasAutoIncrement(db, "pdu")) {
1722 db.execSQL("CREATE TABLE pdu_temp (" +
1758 db.execSQL("INSERT INTO pdu_temp SELECT * from pdu;");
1759 db.execSQL("DROP TABLE pdu;");
1760 db.execSQL("ALTER TABLE pdu_temp RENAME TO pdu;");
1763 createMmsTriggers(db);
1782 private void updateThreadsAttachmentColumn(SQLiteDatabase db) {
1785 db.execSQL("UPDATE threads SET has_attachment=1 WHERE _id IN " +