public static TableModel findPragmaTableInfo(String tableName,SQLiteDatabase db){
  if (isTableExists(tableName,db)) {
    List<String> uniqueColumns=findUniqueColumns(tableName,db);
    TableModel tableModelDB=new TableModel();
    tableModelDB.setTableName(tableName);
    String checkingColumnSQL="pragma table_info(" + tableName + ")";
    Cursor cursor=null;
    try {
      cursor=db.rawQuery(checkingColumnSQL,null);
      if (cursor.moveToFirst()) {
        do {
          ColumnModel columnModel=new ColumnModel();
          String name=cursor.getString(cursor.getColumnIndexOrThrow("name"));
          String type=cursor.getString(cursor.getColumnIndexOrThrow("type"));
          boolean nullable=cursor.getInt(cursor.getColumnIndexOrThrow("notnull")) != 1;
          boolean unique=uniqueColumns.contains(name);
          String defaultValue=cursor.getString(cursor.getColumnIndexOrThrow("dflt_value"));
          columnModel.setColumnName(name);
          columnModel.setColumnType(type);
          columnModel.setIsNullable(nullable);
          columnModel.setIsUnique(unique);
          if (defaultValue != null) {
            defaultValue=defaultValue.replace("'","");
          }
 else {
            defaultValue="";
          }
          columnModel.setDefaultValue(defaultValue);
          tableModelDB.addColumnModel(columnModel);
        }
 while (cursor.moveToNext());
      }
    }
 catch (    Exception e) {
      e.printStackTrace();
      throw new DatabaseGenerateException(e.getMessage());
    }
 finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    return tableModelDB;
  }
 else {
    throw new DatabaseGenerateException(DatabaseGenerateException.TABLE_DOES_NOT_EXIST_WHEN_EXECUTING + tableName);
  }
}

public static TableModel findPragmaTableInfo ( String tableName , SQLiteDatabase db ) { if ( isTableExists ( tableName , db ) ) { List < String > uniqueColumns = findUniqueColumns ( tableName , db ) ; TableModel tableModelDB = new TableModel ( ) ; tableModelDB . setTableName ( tableName ) ; String checkingColumnSQL = "pragma table_info(" + tableName + ")" ; Cursor cursor = null ; try { cursor = db . rawQuery ( checkingColumnSQL , null ) ; if ( cursor . moveToFirst ( ) ) { do { ColumnModel columnModel = new ColumnModel ( ) ; String name = cursor . getString ( cursor . getColumnIndexOrThrow ( "name" ) ) ; String type = cursor . getString ( cursor . getColumnIndexOrThrow ( "type" ) ) ; boolean nullable = cursor . getInt ( cursor . getColumnIndexOrThrow ( "notnull" ) ) != 1 ; boolean unique = uniqueColumns . contains ( name ) ; String defaultValue = cursor . getString ( cursor . getColumnIndexOrThrow ( "dflt_value" ) ) ; columnModel . setColumnName ( name ) ; columnModel . setColumnType ( type ) ; columnModel . setIsNullable ( nullable ) ; columnModel . setIsUnique ( unique ) ; if ( defaultValue != null ) { defaultValue = defaultValue . replace ( "'" , "" ) ; } else { defaultValue = "" ; } columnModel . setDefaultValue ( defaultValue ) ; tableModelDB . addColumnModel ( columnModel ) ; } while ( cursor . moveToNext ( ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; throw new DatabaseGenerateException ( e . getMessage ( ) ) ; } finally { if ( cursor != null ) { cursor . close ( ) ; } } return tableModelDB ; } else { throw new DatabaseGenerateException ( DatabaseGenerateException . TABLE_DOES_NOT_EXIST_WHEN_EXECUTING + tableName ) ; } }
look from the database to find a table named same as the table name in table model . then iterate the columns and types of this table to create a new instance of table model . if there ' s no such a table in the database , then throw databasegenerateexception .
