Change Column Datatype in sqllite in Android.

Try this:-

String qry = "CREATE TABLE IF NOT EXISTS"
            .concat("[OrderDetail]")
            .concat("(")
            .concat("[OrderDetailID] INTEGER PRIMARY KEY 
                      AUTOINCREMENT")
            .concat(",[OrderID] int")
            .concat(",[OrderNo] int")
            .concat(",[ItemName] VARCHAR(50)")
            .concat(")")
            .concat(";");

    db.execSQL(qry);


    String newTable = "CREATE TABLE IF NOT EXISTS"
            .concat("[OrderDetail_temp]")
            .concat("(")
            .concat("[OrderDetailID] INTEGER PRIMARY KEY 
                   AUTOINCREMENT")
            .concat(",[OrderID] VARCHAR(20)")
            .concat(",[OrderNo] VARCHAR(20)")
            .concat(",[ItemName] VARCHAR(50)")
            .concat(")")
            .concat(";");


    String insert = "INSERT INTO [OrderDetail_temp] " +
            "SELECT * FROM [OrderDetail]";

    // creating new Table OrderDetail_temp.
    db.execSQL(newTable);
    // Taking backup from OrderDetail to 
     OrderDetail_temp.
    db.execSQL(insert);
    // Delete OrderMaster.
    db.execSQL("DROP TABLE [OrderDetail]");
    // Rename OrderDetail_temp to 
    OrderDetail.
    db.execSQL("ALTER TABLE `OrderDetail_temp` 
              RENAME TO `OrderDetail`");

Comments

Popular posts from this blog

Lint found fatal errors while assembling a release target.

Windows 7 all Version 64-Bit iso file Download with crack activation. (Google Drive Link)

ViewModelProviders.of(this) is deprecated what to use instead ViewModelProviders.of(this) OR if you don't want to use ViewmodelFactory OR ViewModelProviders error.