title: Android - Change a column type in SQLite database dynamically at runtime
body: <p>I have an application, where I am detecting the type of a particular column at run-time, on page load.  Please refer the below code:</p>
  
  <pre><code>public String fncCheckColumnType(String strColumnName){
          db = this.getWritableDatabase();
          String strColumnType = "";
          Cursor typeCursor = db.rawQuery("SELECT typeof (" + strColumnName +") from tblUsers, null);
          typeCursor.moveToFirst();
          strColumnType = typeCursor.getString(0);
          return strColumnType;
  }
  </code></pre>
  
  <p>The above method simply detects the type of column with column Name 'strColumnName'. I am getting the type of column in this case.</p>
  
  <p>Now, I want to change the column type to TEXT if I am receiving INTEGER as the column type. For this, I tried the below code:</p>
  
  <pre><code>public String fncChangeColumnType(String strColumnName){
          db = this.getWritableDatabase();
          String newType = "";
          Cursor changeCursor = db.rawQuery("ALTER TABLE  tblUsers  MODIFY COLUMN " + strColumnName + " TEXT", null);
          if (changeCursor != null &amp;&amp; changeCursor.moveToFirst()){
              newType = changeCursor.getString(0);
          }
  
          return newType;
   }
  </code></pre>
  
  <p>But while executing the 'fncChangeColumnType' method, I am getting this error, <code>android.database.sqlite.SQLiteException: near "MODIFY": syntax error (code 1): , while compiling: ALTER TABLE tblUsers MODIFY COLUMN UserID TEXT</code></p>
  
  <p>NOTE: I also replaced 'MODIFY' with 'ALTER', but still getting the same error.</p>
  
  <p>Please check if this is the right method to change the type dynamically.</p>
  
  <p>Please respond back if someone has a solution to this.</p>
  
  <p>Thanks in advance.</p>