Java Code Examples for android.database.Cursor#getColumnName()

The following examples show how to use android.database.Cursor#getColumnName() . 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 File: Recipe.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe} object with the basic attributes populated.
 */
public static Recipe fromCursor(Cursor cursor) {
    Recipe recipe = new Recipe(null);
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeTable.ID_COLUMN)) {
            recipe.id = cursor.getString(c);
        } else if (columnName.equals(RecipeTable.TITLE_COLUMN)) {
            recipe.setTitle(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.DESCRIPTION_COLUMN)) {
            recipe.setDescription(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PHOTO_COLUMN)) {
            recipe.setPhoto(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PREP_TIME_COLUMN)) {
            recipe.setPrepTime(cursor.getString(c));
        }
    }
    return recipe;
}
 
Example 2
Source File: Logger.java    From chess with Apache License 2.0 6 votes vote down vote up
public static void log(final Cursor c) {
    if (!BuildConfig.DEBUG) return;
    c.moveToFirst();
    String title = "";
    for (int i = 0; i < c.getColumnCount(); i++)
        title += c.getColumnName(i) + " | ";
    log(title);
    while (!c.isAfterLast()) {
        title = "";
        for (int i = 0; i < c.getColumnCount(); i++)
            title += c.getString(i) + " | ";
        log(title);
        c.moveToNext();
    }
    c.close();
}
 
Example 3
Source File: ModelInflater.java    From QuantumFlux with Apache License 2.0 6 votes vote down vote up
public static <T> T inflate(Cursor cursor, TableDetails tableDetails) {
    T dataModelObject;

    try {
        dataModelObject = (T) tableDetails.createNewModelInstance();
    } catch (Exception ex) {
        throw new QuantumFluxException("Could not create a new instance of data model object: " + tableDetails.getTableName());
    }

    for (int i = 0; i < cursor.getColumnCount(); i++) {
        String columnName = cursor.getColumnName(i);
        TableDetails.ColumnDetails columnDetails = tableDetails.findColumn(columnName);
        inflateColumn(cursor, dataModelObject, columnDetails, i);

    }

    return dataModelObject;
}
 
Example 4
Source File: Recipe.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe} object with the basic attributes populated.
 */
public static Recipe fromCursor(Cursor cursor) {
    Recipe recipe = new Recipe(null);
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeTable.ID_COLUMN)) {
            recipe.id = cursor.getString(c);
        } else if (columnName.equals(RecipeTable.TITLE_COLUMN)) {
            recipe.setTitle(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.DESCRIPTION_COLUMN)) {
            recipe.setDescription(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PHOTO_COLUMN)) {
            recipe.setPhoto(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PREP_TIME_COLUMN)) {
            recipe.setPrepTime(cursor.getString(c));
        }
    }
    return recipe;
}
 
Example 5
Source File: Recipe.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe} object with the basic attributes populated.
 */
public static Recipe fromCursor(Cursor cursor) {
    Recipe recipe = new Recipe(null);
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeTable.ID_COLUMN)) {
            recipe.id = cursor.getString(c);
        } else if (columnName.equals(RecipeTable.TITLE_COLUMN)) {
            recipe.setTitle(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.DESCRIPTION_COLUMN)) {
            recipe.setDescription(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PHOTO_COLUMN)) {
            recipe.setPhoto(cursor.getString(c));
        } else if (columnName.equals(RecipeTable.PREP_TIME_COLUMN)) {
            recipe.setPrepTime(cursor.getString(c));
        }
    }
    return recipe;
}
 
Example 6
Source File: Recipe.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe.Ingredient} object with all attributes populated.
 */
public static Ingredient fromCursor(Cursor cursor) {
    Ingredient ingredient = new Ingredient();
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeIngredientTable.AMOUNT_COLUMN)) {
            ingredient.setAmount(cursor.getString(c));
        } else if (columnName.equals(RecipeIngredientTable.DESCRIPTION_COLUMN)) {
            ingredient.setDescription(cursor.getString(c));
        }
    }
    return ingredient;
}
 
Example 7
Source File: Recipe.java    From search-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe.Step} object with all attributes
 * populated.
 */
public static Step fromCursor(Cursor cursor) {
    Step step = new Step();
    for (int c = 0; c < cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeInstructionsTable.PHOTO_COLUMN)) {
            step.setPhoto(cursor.getString(c));
        } else if (columnName.equals(RecipeInstructionsTable.DESCRIPTION_COLUMN)) {
            step.setDescription(cursor.getString(c));
        }
    }
    return step;
}
 
Example 8
Source File: InstalledApp.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
public InstalledApp(Cursor cursor) {

        checkCursorPosition(cursor);

        for (int i = 0; i < cursor.getColumnCount(); i++) {
            String n = cursor.getColumnName(i);
            switch (n) {
                case Schema.InstalledAppTable.Cols._ID:
                    id = cursor.getLong(i);
                    break;
                case Schema.InstalledAppTable.Cols.Package.NAME:
                    packageName = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.VERSION_CODE:
                    versionCode = cursor.getInt(i);
                    break;
                case Schema.InstalledAppTable.Cols.VERSION_NAME:
                    versionName = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.APPLICATION_LABEL:
                    applicationLabel = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.SIGNATURE:
                    signature = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.LAST_UPDATE_TIME:
                    lastUpdateTime = cursor.getLong(i);
                    break;
                case Schema.InstalledAppTable.Cols.HASH_TYPE:
                    hashType = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.HASH:
                    hash = cursor.getString(i);
                    break;
            }
        }
    }
 
Example 9
Source File: Recipe.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe.Ingredient} object with all attributes populated.
 */
public static Ingredient fromCursor(Cursor cursor) {
    Ingredient ingredient = new Ingredient();
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeIngredientTable.AMOUNT_COLUMN)) {
            ingredient.setAmount(cursor.getString(c));
        } else if (columnName.equals(RecipeIngredientTable.DESCRIPTION_COLUMN)) {
            ingredient.setDescription(cursor.getString(c));
        }
    }
    return ingredient;
}
 
Example 10
Source File: DataHelper.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the column names for the range table
 */
public String[] getRangeColumns() {
    Cursor cursor = db.rawQuery("SELECT * from range limit 1", null);

    String[] data = null;

    if (cursor.moveToFirst()) {
        int i = cursor.getColumnCount() - 1;

        data = new String[i];

        int k = 0;

        for (int j = 0; j < cursor.getColumnCount(); j++) {
            if (!cursor.getColumnName(j).equals("id")) {
                data[k] = cursor.getColumnName(j);
                k += 1;
            }
        }
    }

    if (!cursor.isClosed()) {
        cursor.close();
    }

    return data;
}
 
Example 11
Source File: Recipe.java    From search-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Static helper method for populating attributes from a database cursor.
 *
 * @param cursor The cursor returned from a database query.
 * @return A new {@link com.recipe_app.client.Recipe.Step} object with all attributes populated.
 */
public static Step fromCursor(Cursor cursor) {
    Step step = new Step();
    for (int c=0; c<cursor.getColumnCount(); c++) {
        String columnName = cursor.getColumnName(c);
        if (columnName.equals(RecipeInstructionsTable.PHOTO_COLUMN)) {
            step.setPhoto(cursor.getString(c));
        } else if (columnName.equals(RecipeInstructionsTable.DESCRIPTION_COLUMN)) {
            step.setDescription(cursor.getString(c));
        }
    }
    return step;
}
 
Example 12
Source File: DownloadCompleteReveiver.java    From WayHoo with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();

	if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
		long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
		if (id == Preferences.getDownloadId(context)) {
			Query query = new Query();
			query.setFilterById(id);
			downloadManager = (DownloadManager) context
					.getSystemService(Context.DOWNLOAD_SERVICE);
			Cursor cursor = downloadManager.query(query);

			int columnCount = cursor.getColumnCount();
			String path = null;
			while (cursor.moveToNext()) {
				for (int j = 0; j < columnCount; j++) {
					String columnName = cursor.getColumnName(j);
					String string = cursor.getString(j);
					if ("local_uri".equals(columnName)) {
						path = string;
					}
				}
			}
			cursor.close();

			if (path != null) {
				Preferences.setDownloadPath(context, path);
				Preferences.setDownloadStatus(context, -1);
				Intent installApkIntent = new Intent();
				installApkIntent.setAction(Intent.ACTION_VIEW);
				installApkIntent.setDataAndType(Uri.parse(path),
						"application/vnd.android.package-archive");
				installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
						| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
				context.startActivity(installApkIntent);
			}
		}
	} else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
		long[] ids = intent
				.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
		if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) {
			Intent downloadIntent = new Intent();
			downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
			downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
					| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
			context.startActivity(downloadIntent);
		}
	}
}
 
Example 13
Source File: DatabaseHelper.java    From AndroidDemo with MIT License 4 votes vote down vote up
private static List<TableDataResponse.TableInfo> getTableInfo(SQLiteDatabase db, String pragmaQuery) {

        Cursor cursor;
        try {
            cursor = db.rawQuery(pragmaQuery, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        if (cursor != null) {

            List<TableDataResponse.TableInfo> tableInfoList = new ArrayList<>();

            cursor.moveToFirst();

            if (cursor.getCount() > 0) {
                do {
                    TableDataResponse.TableInfo tableInfo = new TableDataResponse.TableInfo();

                    for (int i = 0; i < cursor.getColumnCount(); i++) {

                        final String columnName = cursor.getColumnName(i);

                        switch (columnName) {
                            case Constants.PK:
                                tableInfo.isPrimary = cursor.getInt(i) == 1;
                                break;
                            case Constants.NAME:
                                tableInfo.title = cursor.getString(i);
                                break;
                            default:
                        }

                    }
                    tableInfoList.add(tableInfo);

                } while (cursor.moveToNext());
            }
            cursor.close();
            return tableInfoList;
        }
        return null;
    }
 
Example 14
Source File: DatabaseHelper.java    From AndroidDemo with MIT License 4 votes vote down vote up
public static TableDataResponse getTableData(SQLiteDatabase db, String selectQuery, String tableName) {

        TableDataResponse tableData = new TableDataResponse();
        tableData.isSelectQuery = true;
        if (tableName == null) {
            tableName = getTableName(selectQuery);
        }

        if (tableName != null) {
            final String pragmaQuery = "PRAGMA table_info(" + tableName + ")";
            tableData.tableInfos = getTableInfo(db, pragmaQuery);
        }

        tableData.isEditable = tableName != null && tableData.tableInfos != null;

        Cursor cursor;
        try {
            cursor = db.rawQuery(selectQuery, null);
        } catch (Exception e) {
            e.printStackTrace();
            tableData.isSuccessful = false;
            tableData.errorMessage = e.getMessage();
            return tableData;
        }

        if (cursor != null) {
            cursor.moveToFirst();

            // setting tableInfo when tableName is not known and making
            // it non-editable also by making isPrimary true for all
            if (tableData.tableInfos == null) {
                tableData.tableInfos = new ArrayList<>();
                for (int i = 0; i < cursor.getColumnCount(); i++) {
                    TableDataResponse.TableInfo tableInfo = new TableDataResponse.TableInfo();
                    tableInfo.title = cursor.getColumnName(i);
                    tableInfo.isPrimary = true;
                    tableData.tableInfos.add(tableInfo);
                }
            }

            tableData.isSuccessful = true;
            tableData.rows = new ArrayList<>();
            if (cursor.getCount() > 0) {

                do {
                    List<TableDataResponse.ColumnData> row = new ArrayList<>();
                    for (int i = 0; i < cursor.getColumnCount(); i++) {
                        TableDataResponse.ColumnData columnData = new TableDataResponse.ColumnData();
                        switch (cursor.getType(i)) {
                            case Cursor.FIELD_TYPE_BLOB:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = ConverterUtils.blobToString(cursor.getBlob(i));
                                break;
                            case Cursor.FIELD_TYPE_FLOAT:
                                columnData.dataType = DataType.REAL;
                                columnData.value = cursor.getDouble(i);
                                break;
                            case Cursor.FIELD_TYPE_INTEGER:
                                columnData.dataType = DataType.INTEGER;
                                columnData.value = cursor.getLong(i);
                                break;
                            case Cursor.FIELD_TYPE_STRING:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = cursor.getString(i);
                                break;
                            default:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = cursor.getString(i);
                        }
                        row.add(columnData);
                    }
                    tableData.rows.add(row);

                } while (cursor.moveToNext());
            }
            cursor.close();
            return tableData;
        } else {
            tableData.isSuccessful = false;
            tableData.errorMessage = "Cursor is null";
            return tableData;
        }

    }
 
Example 15
Source File: DbConnection.java    From Ecommerce-Morningmist-Android with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void printRecords() {

		MLog.log("Printing...");
		Cursor cursor = database.query(MainActivity.DB_TABLE, MainActivity.DB_ALL_COL, null, null, null, null, null);
		cursor.moveToFirst();
		while(!cursor.isAfterLast()) {

			String str = "";
			for(int i = 0; i < cursor.getColumnCount(); i++) {

				str += cursor.getColumnName(i) + "=" + cursor.getString(i) + " "; 

			}

			MLog.log(str);
			cursor.moveToNext();
		}


	}
 
Example 16
Source File: CursorUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T getEntity(final DbUtils db, final Cursor cursor, Class<T> entityType, long findCacheSequence) {
    if (db == null || cursor == null) return null;

    EntityTempCache.setSeq(findCacheSequence);
    try {
        Table table = Table.get(db, entityType);
        Id id = table.id;
        String idColumnName = id.getColumnName();
        int idIndex = id.getIndex();
        if (idIndex < 0) {
            idIndex = cursor.getColumnIndex(idColumnName);
        }
        Object idValue = id.getColumnConverter().getFieldValue(cursor, idIndex);
        T entity = EntityTempCache.get(entityType, idValue);
        if (entity == null) {
            entity = entityType.newInstance();
            id.setValue2Entity(entity, cursor, idIndex);
            EntityTempCache.put(entityType, idValue, entity);
        } else {
            return entity;
        }
        int columnCount = cursor.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            String columnName = cursor.getColumnName(i);
            Column column = table.columnMap.get(columnName);
            if (column != null) {
                column.setValue2Entity(entity, cursor, i);
            }
        }

        // init finder
        for (Finder finder : table.finderMap.values()) {
            finder.setValue2Entity(entity, null, 0);
        }
        return entity;
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }

    return null;
}
 
Example 17
Source File: CursorUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T getEntity(final DbUtils db, final Cursor cursor, Class<T> entityType, long findCacheSequence) {
    if (db == null || cursor == null) return null;

    EntityTempCache.setSeq(findCacheSequence);
    try {
        Table table = Table.get(db, entityType);
        Id id = table.id;
        String idColumnName = id.getColumnName();
        int idIndex = id.getIndex();
        if (idIndex < 0) {
            idIndex = cursor.getColumnIndex(idColumnName);
        }
        Object idValue = id.getColumnConverter().getFieldValue(cursor, idIndex);
        T entity = EntityTempCache.get(entityType, idValue);
        if (entity == null) {
            entity = entityType.newInstance();
            id.setValue2Entity(entity, cursor, idIndex);
            EntityTempCache.put(entityType, idValue, entity);
        } else {
            return entity;
        }
        int columnCount = cursor.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            String columnName = cursor.getColumnName(i);
            Column column = table.columnMap.get(columnName);
            if (column != null) {
                column.setValue2Entity(entity, cursor, i);
            }
        }

        // init finder
        for (Finder finder : table.finderMap.values()) {
            finder.setValue2Entity(entity, null, 0);
        }
        return entity;
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }

    return null;
}
 
Example 18
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 4 votes vote down vote up
/**
 * Execute Sql Statement Query
 *
 * @param mydb - database
 * @param query - SQL query to execute
 * @param queryParams - parameters to the query
 * @param cbc - callback object
 *
 * @throws Exception
 * @return results in string form
 */
private WritableMap executeSqlStatementQuery(SQLiteDatabase mydb,
                                             String query, ReadableArray queryParams,
                                             CallbackContext cbc) throws Exception {
    WritableMap rowsResult = Arguments.createMap();

    Cursor cur = null;
    try {
        try {
            String[] params = new String[0];
            if (queryParams != null) {
                int size = queryParams.size();
                params = new String[size];
                for (int j = 0; j < size; j++) {
                    if (queryParams.isNull(j)) {
                        params[j] = "";
                    } else {
                        params[j] = SQLitePluginConverter.getString(queryParams, j, "");
                    }
                }
            }

            cur = mydb.rawQuery(query, params);
        } catch (Exception ex) {
            FLog.e(TAG, "SQLitePlugin.executeSql[Batch]() failed", ex);
            throw ex;
        }

        // If query result has rows
        if (cur != null && cur.moveToFirst()) {
            WritableArray rowsArrayResult = Arguments.createArray();
            String key;
            int colCount = cur.getColumnCount();

            // Build up result object for each row
            do {
                WritableMap row = Arguments.createMap();
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    bindRow(row, key, cur, i);
                }

                rowsArrayResult.pushMap(row);
            } while (cur.moveToNext());

            rowsResult.putArray("rows", rowsArrayResult);
        }
    } finally {
        closeQuietly(cur);
    }

    return rowsResult;
}
 
Example 19
Source File: DatabaseHelper.java    From AndroidDemo with MIT License 4 votes vote down vote up
public static TableDataResponse getTableData(SQLiteDatabase db, String selectQuery, String tableName) {

        TableDataResponse tableData = new TableDataResponse();
        tableData.isSelectQuery = true;
        if (tableName == null) {
            tableName = getTableName(selectQuery);
        }

        if (tableName != null) {
            final String pragmaQuery = "PRAGMA table_info(" + tableName + ")";
            tableData.tableInfos = getTableInfo(db, pragmaQuery);
        }

        tableData.isEditable = tableName != null && tableData.tableInfos != null;

        Cursor cursor;
        try {
            cursor = db.rawQuery(selectQuery, null);
        } catch (Exception e) {
            e.printStackTrace();
            tableData.isSuccessful = false;
            tableData.errorMessage = e.getMessage();
            return tableData;
        }

        if (cursor != null) {
            cursor.moveToFirst();

            // setting tableInfo when tableName is not known and making
            // it non-editable also by making isPrimary true for all
            if (tableData.tableInfos == null) {
                tableData.tableInfos = new ArrayList<>();
                for (int i = 0; i < cursor.getColumnCount(); i++) {
                    TableDataResponse.TableInfo tableInfo = new TableDataResponse.TableInfo();
                    tableInfo.title = cursor.getColumnName(i);
                    tableInfo.isPrimary = true;
                    tableData.tableInfos.add(tableInfo);
                }
            }

            tableData.isSuccessful = true;
            tableData.rows = new ArrayList<>();
            if (cursor.getCount() > 0) {

                do {
                    List<TableDataResponse.ColumnData> row = new ArrayList<>();
                    for (int i = 0; i < cursor.getColumnCount(); i++) {
                        TableDataResponse.ColumnData columnData = new TableDataResponse.ColumnData();
                        switch (cursor.getType(i)) {
                            case Cursor.FIELD_TYPE_BLOB:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = ConverterUtils.blobToString(cursor.getBlob(i));
                                break;
                            case Cursor.FIELD_TYPE_FLOAT:
                                columnData.dataType = DataType.REAL;
                                columnData.value = cursor.getDouble(i);
                                break;
                            case Cursor.FIELD_TYPE_INTEGER:
                                columnData.dataType = DataType.INTEGER;
                                columnData.value = cursor.getLong(i);
                                break;
                            case Cursor.FIELD_TYPE_STRING:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = cursor.getString(i);
                                break;
                            default:
                                columnData.dataType = DataType.TEXT;
                                columnData.value = cursor.getString(i);
                        }
                        row.add(columnData);
                    }
                    tableData.rows.add(row);

                } while (cursor.moveToNext());
            }
            cursor.close();
            return tableData;
        } else {
            tableData.isSuccessful = false;
            tableData.errorMessage = "Cursor is null";
            return tableData;
        }

    }
 
Example 20
Source File: Repo.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
public Repo(Cursor cursor) {

        checkCursorPosition(cursor);

        for (int i = 0; i < cursor.getColumnCount(); i++) {
            switch (cursor.getColumnName(i)) {
                case Cols._ID:
                    id = cursor.getInt(i);
                    break;
                case Cols.LAST_ETAG:
                    lastetag = cursor.getString(i);
                    break;
                case Cols.ADDRESS:
                    address = cursor.getString(i);
                    break;
                case Cols.DESCRIPTION:
                    description = cursor.getString(i);
                    break;
                case Cols.FINGERPRINT:
                    fingerprint = cursor.getString(i);
                    break;
                case Cols.IN_USE:
                    inuse = cursor.getInt(i) == 1;
                    break;
                case Cols.LAST_UPDATED:
                    String dateString = cursor.getString(i);
                    lastUpdated = Utils.parseTime(dateString, Utils.parseDate(dateString, null));
                    break;
                case Cols.MAX_AGE:
                    maxage = cursor.getInt(i);
                    break;
                case Cols.VERSION:
                    version = cursor.getInt(i);
                    break;
                case Cols.NAME:
                    name = cursor.getString(i);
                    break;
                case Cols.SIGNING_CERT:
                    signingCertificate = cursor.getString(i);
                    break;
                case Cols.PRIORITY:
                    priority = cursor.getInt(i);
                    break;
                case Cols.IS_SWAP:
                    isSwap = cursor.getInt(i) == 1;
                    break;
                case Cols.USERNAME:
                    username = cursor.getString(i);
                    break;
                case Cols.PASSWORD:
                    password = cursor.getString(i);
                    break;
                case Cols.TIMESTAMP:
                    timestamp = cursor.getLong(i);
                    break;
                case Cols.ICON:
                    icon = cursor.getString(i);
                    break;
                case Cols.MIRRORS:
                    mirrors = Utils.parseCommaSeparatedString(cursor.getString(i));
                    break;
                case Cols.USER_MIRRORS:
                    userMirrors = Utils.parseCommaSeparatedString(cursor.getString(i));
                    break;
                case Cols.DISABLED_MIRRORS:
                    disabledMirrors = Utils.parseCommaSeparatedString(cursor.getString(i));
                    break;
                case Cols.PUSH_REQUESTS:
                    pushRequests = cursor.getInt(i);
                    break;
            }
        }
    }