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

Android Studio 3.5 or above usb device not detected in Android Studio or Unable to detect adb version, exit value: 0xc0000135. ADB depends on the Windows Universal C Runtime, which is usually installed by default via Windows Update. You may need to manually fetch and install the runtime package here: https://support.microsoft.com/en-ca/help/2999226/update-for-universal-c-runtime-in-windows

Lint found fatal errors while assembling a release target.

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