Java Code Examples for android.arch.persistence.db.SupportSQLiteDatabase

The following examples show how to use android.arch.persistence.db.SupportSQLiteDatabase. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sqlbrite   Source File: BriteDatabase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Insert a row into the specified {@code table} and notify any subscribed queries.
 *
 * @see SupportSQLiteDatabase#insert(String, int, ContentValues)
 */
@WorkerThread
public long insert(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm,
    @NonNull ContentValues values) {
  SupportSQLiteDatabase db = getWritableDatabase();

  if (logging) {
    log("INSERT\n  table: %s\n  values: %s\n  conflictAlgorithm: %s", table, values,
        conflictString(conflictAlgorithm));
  }
  long rowId = db.insert(table, conflictAlgorithm, values);

  if (logging) log("INSERT id: %s", rowId);

  if (rowId != -1) {
    // Only send a table trigger if the insert was successful.
    sendTableTrigger(Collections.singleton(table));
  }
  return rowId;
}
 
Example 2
Source Project: sqlbrite   Source File: BriteDatabase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Delete rows from the specified {@code table} and notify any subscribed queries. This method
 * will not trigger a notification if no rows were deleted.
 *
 * @see SupportSQLiteDatabase#delete(String, String, Object[])
 */
@WorkerThread
public int delete(@NonNull String table, @Nullable String whereClause,
    @Nullable String... whereArgs) {
  SupportSQLiteDatabase db = getWritableDatabase();

  if (logging) {
    log("DELETE\n  table: %s\n  whereClause: %s\n  whereArgs: %s", table, whereClause,
        Arrays.toString(whereArgs));
  }
  int rows = db.delete(table, whereClause, whereArgs);

  if (logging) log("DELETE affected %s %s", rows, rows != 1 ? "rows" : "row");

  if (rows > 0) {
    // Only send a table trigger if rows were affected.
    sendTableTrigger(Collections.singleton(table));
  }
  return rows;
}
 
Example 3
Source Project: sqlbrite   Source File: BriteDatabase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Update rows in the specified {@code table} and notify any subscribed queries. This method
 * will not trigger a notification if no rows were updated.
 *
 * @see SupportSQLiteDatabase#update(String, int, ContentValues, String, Object[])
 */
@WorkerThread
public int update(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm,
    @NonNull ContentValues values, @Nullable String whereClause, @Nullable String... whereArgs) {
  SupportSQLiteDatabase db = getWritableDatabase();

  if (logging) {
    log("UPDATE\n  table: %s\n  values: %s\n  whereClause: %s\n  whereArgs: %s\n  conflictAlgorithm: %s",
        table, values, whereClause, Arrays.toString(whereArgs),
        conflictString(conflictAlgorithm));
  }
  int rows = db.update(table, conflictAlgorithm, values, whereClause, whereArgs);

  if (logging) log("UPDATE affected %s %s", rows, rows != 1 ? "rows" : "row");

  if (rows > 0) {
    // Only send a table trigger if rows were affected.
    sendTableTrigger(Collections.singleton(table));
  }
  return rows;
}
 
Example 4
Source Project: Tok-Android   Source File: InfoDB.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `friend_conversation` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `tox_key` TEXT, `last_msg_db_id` INTEGER NOT NULL, `update_time` INTEGER NOT NULL, `unread_count` INTEGER NOT NULL)");

    //db table update friend_requests
    database.execSQL("ALTER TABLE `friend_requests` RENAME TO `friend_requests_old`");
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `friend_requests` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `tox_key` TEXT, `message` TEXT, `has_read` INTEGER NOT NULL default 0)");
    database.execSQL(
        "INSERT INTO `friend_requests` (`tox_key`, `message`) SELECT `tox_key`, `message` FROM friend_requests_old");
    database.execSQL("DROP TABLE IF EXISTS `friend_requests_old`");

    //db table update friend_contacts
    database.execSQL("ALTER TABLE `friend_contacts` RENAME TO `friend_contacts_old`");
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `friend_contacts` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `tox_key` TEXT, `name` TEXT, `avatar` TEXT, `isonline` INTEGER NOT NULL, `status` TEXT, `note` TEXT, `received_avatar` INTEGER NOT NULL, `isblocked` INTEGER NOT NULL, `mute` INTEGER NOT NULL, `alias` TEXT, `contact_type` INTEGER NOT NULL, `is_bot` INTEGER NOT NULL default 0, `bot_type` INTEGER NOT NULL default 0)");
    database.execSQL(
        "INSERT INTO `friend_contacts` (`tox_key`, `name`,`avatar`,`isonline`, `status`, `note`, `received_avatar`, `isblocked`,`mute`,`alias`, `contact_type`) SELECT `tox_key`, `name`,`avatar`,`isonline`, `status`, `note`, `received_avatar`, `isblocked`,`mute`,`alias`, `contact_type` FROM friend_contacts_old");
    database.execSQL("DROP TABLE IF EXISTS `friend_contacts_old`");

    //db table update friend_messages
    database.execSQL("ALTER TABLE `friend_messages` RENAME TO `friend_messages_old`");
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `friend_messages` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `message_id` INTEGER NOT NULL, `tox_key` TEXT, `sender_key` TEXT, `sender_name` TEXT, `message` TEXT, `sent_status` INTEGER NOT NULL, `receive_status` INTEGER NOT NULL, `has_been_read` INTEGER NOT NULL, `has_played` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `size` INTEGER NOT NULL, `type` INTEGER, `file_kind` INTEGER)");
    database.execSQL(
        "INSERT INTO `friend_messages` (`message_id`, `tox_key`,`sender_key`,`sender_name`, `message`, `sent_status`, `receive_status`, `has_been_read`,`has_played`,`timestamp`, `size`, `type`, `file_kind`) SELECT `message_id`, `tox_key`,`sender_key`,`sender_name`, `message`, `sent_status`, `receive_status`, `has_been_read`,`has_played`,`timestamp`, `size`, `type`, `file_kind` FROM friend_messages_old");
    database.execSQL("DROP TABLE IF EXISTS `friend_messages_old`");

    //db table update group_peers
    database.execSQL("ALTER TABLE `group_peers` RENAME TO `group_peers_old`");
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `group_peers` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `group_number` INTEGER NOT NULL, `peer_pk` TEXT, `peer_name` TEXT, `peer_signature` TEXT)");
    database.execSQL(
        "INSERT INTO `group_peers` (`group_number`, `peer_pk`,`peer_name`,`peer_signature`) SELECT `group_number`, `peer_pk`,`peer_name`,`peer_signature` FROM group_peers_old");
    database.execSQL("DROP TABLE IF EXISTS `group_peers_old`");
}
 
Example 5
Source Project: Tok-Android   Source File: UserDB.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
    //scheme change
    database.execSQL("ALTER TABLE `users` RENAME TO `users_old`");
    database.execSQL(
        "CREATE TABLE IF NOT EXISTS `users` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `username` TEXT, `password` TEXT, `nickname` TEXT, `status` TEXT, `status_message` TEXT, `avatar` TEXT)");
    database.execSQL(
        "INSERT INTO `users` (`username`, `password`, `nickname`,`status`,`status_message`,`avatar`) SELECT `username`, `password`, `nickname`,`status`,`status_message`,`avatar` FROM users_old");

    database.execSQL("DROP TABLE IF EXISTS `users_old`");
}
 
Example 6
public static ApplicationDatabase getInstance(final Context context) throws Exception {
    if (sInstance == null) {
        synchronized (ApplicationDatabase.class) {
            if (sInstance == null) {
                SafeHelperFactory factory = new SafeHelperFactory(KeyGenHelper.getSecretKeyAsChar(context));

                sInstance = Room.databaseBuilder(context.getApplicationContext(),ApplicationDatabase.class, DATABASE_NAME)
                        .openHelperFactory(factory)
                        .allowMainThreadQueries()
                        .addCallback(new Callback() {
                            @Override
                            public void onCreate(@NonNull SupportSQLiteDatabase db) {
                                super.onCreate(db);
                                try {
                                    ApplicationDatabase database = ApplicationDatabase.getInstance(context);
                                    // notify that the database was created and it's ready to be used
                                    database.setDatabaseCreated();
                                } catch (Exception e) {
                                    Log.e("ApplicationDatabase", e.getMessage());
                                }
                            }
                        }).build();

            }
        }
    }
    return sInstance;
}
 
Example 7
Source Project: notSABS   Source File: Migration_21_22.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfDisabledPackages INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfHosts INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfUserBlockedDomains INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfUserWhitelistedDomains INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfChangedPermissions INTEGER DEFAULT 0");
}
 
Example 8
Source Project: notSABS   Source File: Migration_16_17.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {

    database.execSQL("CREATE TABLE PolicyPackage " +
            "(id TEXT PRIMARY KEY, " +
            "name TEXT NOT NULL, " +
            "createdAt INTEGER, " +
            "updatedAt INTEGER) ");

    Date currentDate = new Date();
    ContentValues contentValues = new ContentValues();
    contentValues.put("id", "default-policy");
    contentValues.put("name", "Default Policy");
    contentValues.put("createdAt", currentDate.getTime());
    contentValues.put("updatedAt", currentDate.getTime());
    database.insert("PolicyPackage", SQLiteDatabase.CONFLICT_REPLACE, contentValues);

    database.execSQL("CREATE TABLE AppPermission " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "permissionName TEXT NOT NULL, " +
            "permissionStatus INTEGER DEFAULT 0, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX app_permission_policy_package_idx " +
            "ON AppPermission (packageName, permissionName, policyPackageId)");

    database.execSQL("CREATE TABLE DisabledPackage " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX disabled_package_policy_package_idx " +
            "ON DisabledPackage (packageName, policyPackageId)");
}
 
Example 9
Source Project: notSABS   Source File: Migration_19_20.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("CREATE TABLE FirewallWhitelistedPackage " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX firewall_whitelisted_package_policy_package_idx " +
            "ON FirewallWhitelistedPackage (packageName, policyPackageId)");
}
 
Example 10
public static LocationDatabase getLocationDatabase(Context context) {
    if (INSTANCE == null) {
        INSTANCE =
                Room.databaseBuilder(context.getApplicationContext(), LocationDatabase.class, "locations")
                        .addMigrations(new Migration(1, 2) {
                            @Override
                            public void migrate(@NonNull SupportSQLiteDatabase database) {
                                final String TABLE_TEMP = "_location_migration_1_2_temp";
                                final String TABLE_ORIG = "location";

                                final String CREATE_STMT_2 = "CREATE TABLE IF NOT EXISTS " +
                                        "`"+ TABLE_TEMP +"` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
                                        "`accuracy` REAL, " +
                                        "`longitude` REAL, " +
                                        "`latitude` REAL, " +
                                        "`altitude` REAL," +
                                        " `speed` REAL, " +
                                        "`time` INTEGER, " +
                                        "`vertical_accuracy` REAL, " +
                                        "`course` REAL, " +
                                        "`course_accuracy` REAL, " +
                                        "`speed_accuracy` REAL, `provider` TEXT, `read_count` INTEGER)";

                                database.execSQL(CREATE_STMT_2);

                                database.execSQL("INSERT INTO `" + TABLE_TEMP + "` (" +
                                            "id, accuracy, longitude, latitude, altitude, time" +
                                        ") SELECT id, accuracy, longitude, latitude, altitude, time FROM " + TABLE_ORIG);

                                database.execSQL("DROP TABLE " + TABLE_ORIG);
                                database.execSQL("ALTER TABLE " + TABLE_TEMP + " RENAME TO " + TABLE_ORIG);
                            }
                        })
                        .build();
    }
    return INSTANCE;
}
 
Example 11
Source Project: SABS   Source File: Migration_21_22.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfDisabledPackages INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfHosts INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfUserBlockedDomains INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfUserWhitelistedDomains INTEGER DEFAULT 0");
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN numberOfChangedPermissions INTEGER DEFAULT 0");
}
 
Example 12
Source Project: SABS   Source File: Migration_16_17.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {

    database.execSQL("CREATE TABLE PolicyPackage " +
            "(id TEXT PRIMARY KEY, " +
            "name TEXT NOT NULL, " +
            "createdAt INTEGER, " +
            "updatedAt INTEGER) ");

    Date currentDate = new Date();
    ContentValues contentValues = new ContentValues();
    contentValues.put("id", "default-policy");
    contentValues.put("name", "Default Policy");
    contentValues.put("createdAt", currentDate.getTime());
    contentValues.put("updatedAt", currentDate.getTime());
    database.insert("PolicyPackage", SQLiteDatabase.CONFLICT_REPLACE, contentValues);

    database.execSQL("CREATE TABLE AppPermission " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "permissionName TEXT NOT NULL, " +
            "permissionStatus INTEGER DEFAULT 0, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX app_permission_policy_package_idx " +
            "ON AppPermission (packageName, permissionName, policyPackageId)");

    database.execSQL("CREATE TABLE DisabledPackage " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX disabled_package_policy_package_idx " +
            "ON DisabledPackage (packageName, policyPackageId)");
}
 
Example 13
Source Project: SABS   Source File: Migration_19_20.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("CREATE TABLE FirewallWhitelistedPackage " +
            "(id INTEGER PRIMARY KEY, " +
            "packageName TEXT NOT NULL, " +
            "policyPackageId TEXT DEFAULT 'default-policy', " +
            "FOREIGN KEY (policyPackageId) REFERENCES PolicyPackage(id))");
    database.execSQL("CREATE UNIQUE INDEX firewall_whitelisted_package_policy_package_idx " +
            "ON FirewallWhitelistedPackage (packageName, policyPackageId)");
}
 
Example 14
Source Project: RoomDemo   Source File: MyDatabase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE product "
            + " ADD COLUMN price INTEGER");

    // enable flag to force update products
    App.get().setForceUpdate(true);
}
 
Example 15
Source Project: AndroidNewArchitectureExample   Source File: AppModule.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.beginTransaction();
    try {
        database.execSQL("INSERT INTO 'Weather' (CityName, Temperature, Description) VALUES ('Moscow', NULL, NULL)");
        database.execSQL("INSERT INTO 'Weather' (CityName, Temperature, Description) VALUES ('London', NULL, NULL)");
        database.execSQL("INSERT INTO 'Weather' (CityName, Temperature, Description) VALUES (git 'Berlin', NULL, NULL)");
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
 
Example 16
Source Project: Android-Debug-Database   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setInMemoryRoomDatabases(SupportSQLiteDatabase... database) {
    if (BuildConfig.DEBUG) {
        try {
            Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
            Class[] argTypes = new Class[]{HashMap.class};
            HashMap<String, SupportSQLiteDatabase> inMemoryDatabases = new HashMap<>();
            // set your inMemory databases
            inMemoryDatabases.put("InMemoryOne.db", database[0]);
            Method setRoomInMemoryDatabase = debugDB.getMethod("setInMemoryRoomDatabases", argTypes);
            setRoomInMemoryDatabase.invoke(null, inMemoryDatabases);
        } catch (Exception ignore) {

        }
    }
}
 
Example 17
Source Project: Android-Debug-Database   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setInMemoryRoomDatabases(SupportSQLiteDatabase... database) {
    if (BuildConfig.DEBUG) {
        try {
            Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
            Class[] argTypes = new Class[]{HashMap.class};
            HashMap<String, SupportSQLiteDatabase> inMemoryDatabases = new HashMap<>();
            // set your inMemory databases
            inMemoryDatabases.put("InMemoryOne.db", database[0]);
            Method setRoomInMemoryDatabase = debugDB.getMethod("setInMemoryRoomDatabases", argTypes);
            setRoomInMemoryDatabase.invoke(null, inMemoryDatabases);
        } catch (Exception ignore) {

        }
    }
}
 
Example 18
Source Project: Travel-Mate   Source File: AppDataBase.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    // Create the new table to be used
    database.execSQL(
            "CREATE TABLE checklist_items (id INTEGER PRIMARY KEY NOT NULL, name TEXT," +
                    " isDone TEXT NOT NULL, position INTEGER DEFAULT 0 NOT NULL)");

    // Create a temp table to generate positions
    database.execSQL("CREATE TABLE seq_generator(pos INTEGER PRIMARY KEY AUTOINCREMENT," +
            "id INTEGER)");

    // Copy each of the existing id(s) into this; `pos` generated with 1-indexing
    database.execSQL("INSERT INTO seq_generator (id)" +
            "SELECT id from events_new");

    // Get old data, JOIN the position column, and insert into new table
    // `pos`-1 is done to achieve 0-indexing
    database.execSQL(
            "INSERT INTO checklist_items " +
                    "SELECT old.id, old.name, old.isDone, t.pos-1 " +
                    "FROM events_new old JOIN seq_generator t ON old.id = t.id");

    // Remove the temp table
    database.execSQL("DROP TABLE seq_generator");

    // Remove the old table
    database.execSQL("DROP TABLE events_new");

    // Change the table name to the correct one
    database.execSQL("ALTER TABLE checklist_items RENAME TO events_new");
}
 
Example 19
Source Project: Travel-Mate   Source File: DbChecklist.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    // Create the new table
    database.execSQL(
            "CREATE TABLE checklist_items (id INTEGER PRIMARY KEY NOT NULL, name TEXT," +
                    " isDone TEXT)");
    // Copy the data
    database.execSQL(
            "INSERT INTO checklist_items (id, name, isDone) " +
                    "SELECT id, name, isDone FROM events_new");
    // Remove the old table
    database.execSQL("DROP TABLE events_new");
    // Change the table name to the correct one
    database.execSQL("ALTER TABLE checklist_items RENAME TO events_new");
}
 
Example 20
Source Project: Travel-Mate   Source File: DbChecklist.java    License: MIT License 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    // Create the new table to be used
    database.execSQL(
            "CREATE TABLE checklist_items (id INTEGER PRIMARY KEY NOT NULL, name TEXT," +
                    " isDone TEXT NOT NULL, position INTEGER DEFAULT 0 NOT NULL)");

    // Create a temp table to generate positions
    database.execSQL("CREATE TABLE seq_generator(pos INTEGER PRIMARY KEY AUTOINCREMENT," +
            "id INTEGER)");

    // Copy each of the existing id(s) into this; `pos` generated with 1-indexing
    database.execSQL("INSERT INTO seq_generator (id)" +
            "SELECT id from events_new");

    // Get old data, JOIN the position column, and insert into new table
    // `pos`-1 is done to achieve 0-indexing
    database.execSQL(
            "INSERT INTO checklist_items " +
                    "SELECT old.id, old.name, old.isDone, t.pos-1 " +
                    "FROM events_new old JOIN seq_generator t ON old.id = t.id");

    // Remove the temp table
    database.execSQL("DROP TABLE seq_generator");

    // Remove the old table
    database.execSQL("DROP TABLE events_new");

    // Change the table name to the correct one
    database.execSQL("ALTER TABLE checklist_items RENAME TO events_new");
}
 
Example 21
Source Project: sqlbrite   Source File: TestDb.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void onCreate(@NonNull SupportSQLiteDatabase db) {
  db.execSQL("PRAGMA foreign_keys=ON");

  db.execSQL(CREATE_EMPLOYEE);
  aliceId = db.insert(TABLE_EMPLOYEE, CONFLICT_FAIL, employee("alice", "Alice Allison"));
  bobId = db.insert(TABLE_EMPLOYEE, CONFLICT_FAIL, employee("bob", "Bob Bobberson"));
  eveId = db.insert(TABLE_EMPLOYEE, CONFLICT_FAIL, employee("eve", "Eve Evenson"));

  db.execSQL(CREATE_MANAGER);
  db.insert(TABLE_MANAGER, CONFLICT_FAIL, manager(eveId, aliceId));
}
 
Example 22
Source Project: Tok-Android   Source File: InfoDB.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
    //TODO
    database.execSQL("DROP TABLE IF EXISTS `group_peers`");
}
 
Example 23
Source Project: Tok-Android   Source File: InfoDB.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
    //add column(friend_contacts) on TABLE 'friend_contacts'
    database.execSQL("ALTER TABLE `friend_contacts` ADD `has_offline_bot` INTEGER NOT NULL default 0");
}
 
Example 24
Source Project: Tok-Android   Source File: UserDB.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE `users` ADD `login_time` INTEGER NOT NULL default 0");
}
 
Example 25
Source Project: mobikul-standalone-pos   Source File: AppDatabase.java    License: MIT License 4 votes vote down vote up
@Override
        public void migrate(SupportSQLiteDatabase database) {

            // Create the new table
            database.execSQL(
                    "CREATE TABLE admin_new (uid INTEGER NOT NULL, first_name TEXT, last_name TEXT, email TEXT,username TEXT, password TEXT, PRIMARY KEY(uid))");
// Copy the data
            database.execSQL(
                    "INSERT INTO admin_new (uid, first_name, last_name, email, password) SELECT uid, first_name, last_name, email, password FROM Administrator");
// Remove the old table
            database.execSQL("DROP TABLE Administrator");
// Change the table name to the correct one
            database.execSQL("ALTER TABLE admin_new RENAME TO Administrator");
            // Since we didn't alter the table, there's nothing else to do here.

            // Create the new table
            database.execSQL(
                    "CREATE TABLE Category_new (cId INTEGER NOT NULL, category_name TEXT, is_active INTEGER NOT NULL, is_include_in_drawer_menu INTEGER NOT NULL, category_icon INTEGER NOT NULL, level INTEGER NOT NULL, parent_id INTEGER NOT NULL, path TEXT, PRIMARY KEY(cId))");
            database.execSQL(
                    "INSERT INTO Category_new (cId, category_name, is_active, is_include_in_drawer_menu, category_icon, level, parent_id, path) SELECT cId, category_name, is_active, is_include_in_drawer_menu, category_icon, level, parent_id, path FROM Category");
            database.execSQL("DROP TABLE Category");
            database.execSQL("ALTER TABLE Category_new RENAME TO Category");

            // Create the new table
            database.execSQL(
                    "CREATE TABLE Product_new (pId INTEGER NOT NULL, product_name TEXT, product_s_deccription TEXT, sku TEXT, is_enabled INTEGER NOT NULL, price TEXT, special_price TEXT, is_taxable_goods_applied INTEGER NOT NULL" +
                            ",track_inventory INTEGER NOT NULL, quantity TEXT, stock_availability INTEGER NOT NULL, image TEXT, weight TEXT, productCategories TEXT,formatted_price TEXT, formatted_special_price TEXT" +
                            ",barCode TEXT, product_tax TEXT, options TEXT, PRIMARY KEY(pId))");
            database.execSQL(
                    "INSERT INTO Product_new (pId, product_name, product_s_deccription, sku, is_enabled, price, special_price, is_taxable_goods_applied, track_inventory, quantity, stock_availability, image, weight, productCategories" +
                            ", formatted_price, formatted_special_price, barCode, product_tax, options )" +
                            " SELECT pId, product_name, product_s_deccription, sku, is_enabled, price, special_price, is_taxable_goods_applied, track_inventory" +
                            ", quantity, stock_availability, image, weight,productCategories, formatted_price, formatted_special_price, barCode, product_tax, options " +
                            " FROM Product");
            database.execSQL("DROP TABLE Product");
            database.execSQL("ALTER TABLE Product_new RENAME TO Product");

            //create customer table
            database.execSQL(
                    "CREATE TABLE Customer_new (customerId INTEGER NOT NULL, customer_first_name TEXT, customer_last_name TEXT, email TEXT, contact_number TEXT" +
                            ", address_line TEXT,city TEXT,postal_code TEXT,state TEXT,country TEXT, PRIMARY KEY(customerId))");
            database.execSQL(
                    "INSERT INTO Customer_new (customerId, customer_first_name, customer_last_name, email, contact_number, address_line, city, postal_code,state" +
                            ", country) SELECT customerId, customer_first_name, customer_last_name, email, contact_number, address_line, city, postal_code,state" +
                            ", country FROM Customer");
            database.execSQL("DROP TABLE Customer");
            database.execSQL("ALTER TABLE Customer_new RENAME TO Customer");

            //create OrderEntity table
            database.execSQL(
                    "CREATE TABLE OrderEntity_new (orderId INTEGER NOT NULL, time TEXT, date TEXT, cart_data TEXT, qty TEXT" +
                            ", cash_data TEXT,is_synced TEXT,is_return TEXT,refunded_order_id TEXT, PRIMARY KEY(orderId))");
            database.execSQL(
                    "INSERT INTO OrderEntity_new (orderId, time, date, cart_data, qty, cash_data, is_synced, is_return,refunded_order_id) " +
                            "SELECT orderId, time, date, cart_data, qty, cash_data, is_synced, is_return,refunded_order_id FROM OrderEntity");
            database.execSQL("DROP TABLE OrderEntity");
            database.execSQL("ALTER TABLE OrderEntity_new RENAME TO OrderEntity");

            //create HoldCart table
            database.execSQL(
                    "CREATE TABLE HoldCart_new (holdCartId INTEGER NOT NULL, time TEXT, date TEXT, cart_data TEXT, qty TEXT" +
                            ", is_synced TEXT, PRIMARY KEY(holdCartId))");
            database.execSQL(
                    "INSERT INTO HoldCart_new (holdCartId, time, date, cart_data, qty, is_synced) " +
                            "SELECT holdCartId, time, date, cart_data, qty, is_synced FROM HoldCart");
            database.execSQL("DROP TABLE HoldCart");
            database.execSQL("ALTER TABLE HoldCart_new RENAME TO HoldCart");

            //create CashDrawerModel table
            database.execSQL(
                    "CREATE TABLE CashDrawerModel_new (date INTEGER NOT NULL, cash_drawer_items TEXT, opening_balance TEXT, formatted_opening_balance TEXT" +
                            ", closing_balance TEXT, formatted_closing_balance TEXT, net_revenue TEXT, formatted_net_revenue TEXT, " +
                            ", in_amount TEXT, formatted_in_amount TEXT, out_amount TEXT, formatted_out_amount TEXT, is_synced TEXT, PRIMARY KEY(date))");
            database.execSQL(
                    "INSERT INTO CashDrawerModel_new (date, cash_drawer_items, opening_balance, formatted_opening_balance, closing_balance, formatted_closing_balance, net_revenue, formatted_net_revenue, in_amount, formatted_in_amount, out_amount, formatted_out_amount, is_synced) " +
                            "SELECT date, cash_drawer_items, opening_balance, formatted_opening_balance, closing_balance, formatted_closing_balance, net_revenue, formatted_net_revenue, in_amount, formatted_in_amount, out_amount, formatted_out_amount, is_synced FROM CashDrawerModel");
            database.execSQL("DROP TABLE CashDrawerModel");
            database.execSQL("ALTER TABLE CashDrawerModel_new RENAME TO CashDrawerModel");

            //create HoldCart table
            database.execSQL(
                    "CREATE TABLE Option_new (optionId INTEGER NOT NULL, option_name TEXT, option_type TEXT, option_values TEXT, sort_order TEXT" +
                            ", PRIMARY KEY(optionId))");
            database.execSQL(
                    "INSERT INTO Option_new (optionId, option_name, option_type, option_values, sort_order) " +
                            "SELECT optionId, option_name, option_type, option_values, sort_order FROM Option");
            database.execSQL("DROP TABLE Option");
            database.execSQL("ALTER TABLE Option_new RENAME TO HoldCart");

            //create Tax table
            database.execSQL(
                    "CREATE TABLE Tax_new (taxId INTEGER NOT NULL, tax_name TEXT, is_enabled TEXT, type TEXT, tax_rate TEXT" +
                            ", PRIMARY KEY(taxId))");
            database.execSQL(
                    "INSERT INTO Tax_new (taxId, tax_name, is_enabled, type, tax_rate) " +
                            "SELECT taxId, tax_name, is_enabled, type, tax_rate FROM Tax");
            database.execSQL("DROP TABLE Tax");
            database.execSQL("ALTER TABLE Tax_new RENAME TO Tax");
        }
 
Example 26
Source Project: mobikul-standalone-pos   Source File: AppDatabase.java    License: MIT License 4 votes vote down vote up
@Override
        public void migrate(SupportSQLiteDatabase database) {

            // Create the new table
            database.execSQL(
                    "CREATE TABLE admin_new (uid INTEGER NOT NULL, first_name TEXT, last_name TEXT, email TEXT,username TEXT, password TEXT, PRIMARY KEY(uid))");
// Copy the data
            database.execSQL(
                    "INSERT INTO admin_new (uid, first_name, last_name, email, password) SELECT uid, first_name, last_name, email, password FROM Administrator");
// Remove the old table
            database.execSQL("DROP TABLE Administrator");
// Change the table name to the correct one
            database.execSQL("ALTER TABLE admin_new RENAME TO Administrator");
            // Since we didn't alter the table, there's nothing else to do here.

            // Create the new table
            database.execSQL(
                    "CREATE TABLE Category_new (cId INTEGER NOT NULL, category_name TEXT, is_active INTEGER NOT NULL, is_include_in_drawer_menu INTEGER NOT NULL, category_icon INTEGER NOT NULL, level INTEGER NOT NULL, parent_id INTEGER NOT NULL, path TEXT, PRIMARY KEY(cId))");
            database.execSQL(
                    "INSERT INTO Category_new (cId, category_name, is_active, is_include_in_drawer_menu, category_icon, level, parent_id, path) SELECT cId, category_name, is_active, is_include_in_drawer_menu, category_icon, level, parent_id, path FROM Category");
            database.execSQL("DROP TABLE Category");
            database.execSQL("ALTER TABLE Category_new RENAME TO Category");

            // Create the new table
            database.execSQL(
                    "CREATE TABLE Product_new (pId INTEGER NOT NULL, product_name TEXT, product_s_deccription TEXT, sku TEXT, is_enabled INTEGER NOT NULL, price TEXT, special_price TEXT, is_taxable_goods_applied INTEGER NOT NULL" +
                            ",track_inventory INTEGER NOT NULL, quantity TEXT, stock_availability INTEGER NOT NULL, image TEXT, weight TEXT, productCategories TEXT,formatted_price TEXT, formatted_special_price TEXT" +
                            ",barCode TEXT, product_tax TEXT, options TEXT, discount REAL NOT NULL DEFAULT 0, formatted_discount TEXT, PRIMARY KEY(pId))");
            database.execSQL(
                    "INSERT INTO Product_new (pId, product_name, product_s_deccription, sku, is_enabled, price, special_price, is_taxable_goods_applied, track_inventory, quantity, stock_availability, image, weight, productCategories" +
                            ", formatted_price, formatted_special_price, barCode, product_tax, options )" +
                            " SELECT pId, product_name, product_s_deccription, sku, is_enabled, price, special_price, is_taxable_goods_applied, track_inventory" +
                            ", quantity, stock_availability, image, weight,productCategories, formatted_price, formatted_special_price, barCode, product_tax, options " +
                            " FROM Product");
            database.execSQL("DROP TABLE Product");
            database.execSQL("ALTER TABLE Product_new RENAME TO Product");

            //create customer table
            database.execSQL(
                    "CREATE TABLE Customer_new (customerId INTEGER NOT NULL, customer_first_name TEXT, customer_last_name TEXT, email TEXT, contact_number TEXT" +
                            ", address_line TEXT,city TEXT,postal_code TEXT,state TEXT,country TEXT, PRIMARY KEY(customerId))");
            database.execSQL(
                    "INSERT INTO Customer_new (customerId, customer_first_name, customer_last_name, email, contact_number, address_line, city, postal_code,state" +
                            ", country) SELECT customerId, customer_first_name, customer_last_name, email, contact_number, address_line, city, postal_code,state" +
                            ", country FROM Customer");
            database.execSQL("DROP TABLE Customer");
            database.execSQL("ALTER TABLE Customer_new RENAME TO Customer");

            //create OrderEntity table
            database.execSQL(
                    "CREATE TABLE OrderEntity_new (orderId INTEGER NOT NULL, time TEXT, date TEXT, cart_data TEXT, qty TEXT" +
                            ", cash_data TEXT,is_synced TEXT,is_return INTEGER NOT NULL, refunded_order_id TEXT, PRIMARY KEY(orderId))");
            database.execSQL(
                    "INSERT INTO OrderEntity_new (orderId, time, date, cart_data, qty, cash_data, is_synced, is_return,refunded_order_id) " +
                            "SELECT orderId, time, date, cart_data, qty, cash_data, is_synced, is_return,refunded_order_id FROM OrderEntity");
            database.execSQL("DROP TABLE OrderEntity");
            database.execSQL("ALTER TABLE OrderEntity_new RENAME TO OrderEntity");

            //create HoldCart table
            database.execSQL(
                    "CREATE TABLE HoldCart_new (holdCartId INTEGER NOT NULL, time TEXT, date TEXT, cart_data TEXT, qty TEXT" +
                            ", is_synced TEXT, PRIMARY KEY(holdCartId))");
            database.execSQL(
                    "INSERT INTO HoldCart_new (holdCartId, time, date, cart_data, qty, is_synced) " +
                            "SELECT holdCartId, time, date, cart_data, qty, is_synced FROM HoldCart");
            database.execSQL("DROP TABLE HoldCart");
            database.execSQL("ALTER TABLE HoldCart_new RENAME TO HoldCart");

            //create CashDrawerModel table
//            database.execSQL(
//                    "CREATE TABLE CashDrawerModel_new (date INTEGER NOT NULL, cash_drawer_items TEXT, opening_balance TEXT, formatted_opening_balance TEXT" +
//                            ", closing_balance TEXT, formatted_closing_balance TEXT, net_revenue TEXT, formatted_net_revenue TEXT, " +
//                            ", in_amount TEXT, formatted_in_amount TEXT, out_amount TEXT, formatted_out_amount TEXT, is_synced TEXT, PRIMARY KEY(date))");
//            database.execSQL(
//                    "INSERT INTO CashDrawerModel_new (date, cash_drawer_items, opening_balance, formatted_opening_balance, closing_balance, formatted_closing_balance, net_revenue, formatted_net_revenue, in_amount, formatted_in_amount, out_amount, formatted_out_amount, is_synced) " +
//                            "SELECT date, cash_drawer_items, opening_balance, formatted_opening_balance, closing_balance, formatted_closing_balance, net_revenue, formatted_net_revenue, in_amount, formatted_in_amount, out_amount, formatted_out_amount, is_synced FROM CashDrawerModel");
//            database.execSQL("DROP TABLE CashDrawerModel");
//            database.execSQL("ALTER TABLE CashDrawerModel_new RENAME TO CashDrawerModel");

            //create HoldCart table
//            database.execSQL(
//                    "CREATE TABLE Option_new (optionId INTEGER NOT NULL, option_name TEXT, option_type TEXT, option_values TEXT, sort_order TEXT" +
//                            ", PRIMARY KEY(optionId))");
//            database.execSQL(
//                    "INSERT INTO Option_new (optionId, option_name, option_type, option_values, sort_order) " +
//                            "SELECT optionId, option_name, option_type, option_values, sort_order FROM Option");
//            database.execSQL("DROP TABLE Option");
//            database.execSQL("ALTER TABLE Option_new RENAME TO HoldCart");
//
//            //create Tax table
//            database.execSQL(
//                    "CREATE TABLE Tax_new (taxId INTEGER NOT NULL, tax_name TEXT, is_enabled TEXT, type TEXT, tax_rate TEXT" +
//                            ", PRIMARY KEY(taxId))");
//            database.execSQL(
//                    "INSERT INTO Tax_new (taxId, tax_name, is_enabled, type, tax_rate) " +
//                            "SELECT taxId, tax_name, is_enabled, type, tax_rate FROM Tax");
//            database.execSQL("DROP TABLE Tax");
//            database.execSQL("ALTER TABLE Tax_new RENAME TO Tax");
        }
 
Example 27
Source Project: notSABS   Source File: Migration_20_21.java    License: MIT License 4 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE BlockUrlProviders ADD COLUMN policyPackageId TEXT DEFAULT 'default-policy' REFERENCES PolicyPackage(id)");
    database.execSQL("ALTER TABLE UserBlockUrl ADD COLUMN policyPackageId TEXT DEFAULT 'default-policy' REFERENCES PolicyPackage(id)");
    database.execSQL("ALTER TABLE WhiteUrl ADD COLUMN policyPackageId TEXT DEFAULT 'default-policy' REFERENCES PolicyPackage(id)");
}
 
Example 28
Source Project: notSABS   Source File: Migration_18_19.java    License: MIT License 4 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN description TEXT");
}
 
Example 29
Source Project: notSABS   Source File: Migration_14_15.java    License: MIT License 4 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase supportSQLiteDatabase) {
    supportSQLiteDatabase.execSQL("ALTER TABLE AppInfo ADD COLUMN adhellWhitelisted INTEGER DEFAULT 0");
}
 
Example 30
Source Project: notSABS   Source File: Migration_17_18.java    License: MIT License 4 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    database.execSQL("ALTER TABLE PolicyPackage ADD COLUMN active INTEGER DEFAULT 1");
}