Java Code Examples for android.database.Cursor#FIELD_TYPE_INTEGER

The following examples show how to use android.database.Cursor#FIELD_TYPE_INTEGER . 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: OCursorUtils.java    From hr with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Object cursorValue(String column, Cursor cr) {
    Object value = false;
    int index = cr.getColumnIndex(column);
    switch (cr.getType(index)) {
        case Cursor.FIELD_TYPE_NULL:
            value = false;
            break;
        case Cursor.FIELD_TYPE_STRING:
            value = cr.getString(index);
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            value = cr.getInt(index);
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            value = cr.getFloat(index);
            break;
        case Cursor.FIELD_TYPE_BLOB:
            value = cr.getBlob(index);
            break;
    }
    return value;
}
 
Example 2
Source File: SQLiteAndroidDatabase.java    From AvI with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void bindPostHoneycomb(JSONObject row, String key, Cursor cur, int i) throws JSONException {
    int curType = cur.getType(i);

    switch (curType) {
        case Cursor.FIELD_TYPE_NULL:
            row.put(key, JSONObject.NULL);
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            row.put(key, cur.getLong(i));
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            row.put(key, cur.getDouble(i));
            break;
        /* ** Read BLOB as Base-64 DISABLED in this branch:
        case Cursor.FIELD_TYPE_BLOB:
            row.put(key, new String(Base64.encode(cur.getBlob(i), Base64.DEFAULT)));
            break;
        // ** Read BLOB as Base-64 DISABLED to HERE. */
        case Cursor.FIELD_TYPE_STRING:
        default: /* (not expected) */
            row.put(key, cur.getString(i));
            break;
    }
}
 
Example 3
Source File: PermissionTester.java    From PermissionAgent with Apache License 2.0 6 votes vote down vote up
public static void read(Cursor cursor) {
    int count = cursor.getCount();
    if (count > 0) {
        cursor.moveToFirst();
        int type = cursor.getType(0);
        switch (type) {
            case Cursor.FIELD_TYPE_BLOB:
            case Cursor.FIELD_TYPE_NULL: {
                break;
            }
            case Cursor.FIELD_TYPE_INTEGER:
            case Cursor.FIELD_TYPE_FLOAT:
            case Cursor.FIELD_TYPE_STRING:
            default: {
                cursor.getString(0);
                break;
            }
        }
    }
}
 
Example 4
Source File: SuntimesThemeProviderTest.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private boolean columnIsInt(Cursor cursor, String column)
{
    if (cursor != null) {
        try {
            int index = cursor.getColumnIndex(column);
            if (cursor.getType(index) == Cursor.FIELD_TYPE_INTEGER);
            {
                int value = cursor.getInt(index);
                return true;
            }

        } catch (NumberFormatException e) {
            return false;
        }
    }
    return false;
}
 
Example 5
Source File: CalculatorProviderTest.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private boolean columnIsInt(Cursor cursor, String column)
{
    if (cursor != null) {
        try {
            int index = cursor.getColumnIndex(column);
            if (cursor.getType(index) == Cursor.FIELD_TYPE_INTEGER);
            {
                int value = cursor.getInt(index);
                return true;
            }

        } catch (NumberFormatException e) {
            return false;
        }
    }
    return false;
}
 
Example 6
Source File: TestContentProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public int getType(int columnIndex) {
    if (columnIndex == ColumnIndex.RESOURCE_REQUEST_COUNT_COLUMN.ordinal()) {
        return Cursor.FIELD_TYPE_INTEGER;
    }
    return Cursor.FIELD_TYPE_NULL;
}
 
Example 7
Source File: PaginatedCursor.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
/**
 * Try to load un-cached data with size {@link PAGE_SIZE} starting from given index.
 */
private void loadCacheStartingFromPosition(int index) {
    mCursor.moveToPosition(index);
    for (int row = index; row < (index + PAGE_SIZE) && row < mRowCount; row++) {
        if (!mCachedRows[row]) {
            for (int col = 0; col < mColumnCount; col++) {
                switch (mCursor.getType(col)) {
                    case Cursor.FIELD_TYPE_BLOB:
                        mByteArrayDataCache[row][mByteArrayCacheIndexMap[col]] =
                                mCursor.getBlob(col);
                        break;
                    case Cursor.FIELD_TYPE_FLOAT:
                        mFloatDataCache[row][mFloatCacheIndexMap[col]] = mCursor.getFloat(col);
                        break;
                    case Cursor.FIELD_TYPE_INTEGER:
                        mIntDataCache[row][mIntCacheIndexMap[col]] = mCursor.getInt(col);
                        break;
                    case Cursor.FIELD_TYPE_STRING:
                        mStringDataCache[row][mStringCacheIndexMap[col]] =
                                mCursor.getString(col);
                        break;
                }
            }
            mCachedRows[row] = true;
        }
        mCursor.moveToNext();
    }
    mLastCachePosition = Math.min(index + PAGE_SIZE, mRowCount) - 1;
}
 
Example 8
Source File: CompatibilityFileProvider.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames) return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
                case Cursor.FIELD_TYPE_INTEGER:
                    row.add(source.getInt(i));
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    row.add(source.getFloat(i));
                    break;
                case Cursor.FIELD_TYPE_STRING:
                    row.add(source.getString(i));
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    row.add(source.getBlob(i));
                    break;
                case Cursor.FIELD_TYPE_NULL:
                default:
                    row.add(null);
                    break;
            }
        }
    }

    source.close();
    return cursor;
}
 
Example 9
Source File: Database.java    From stetho with MIT License 5 votes vote down vote up
/**
 * Flatten all columns and all rows of a cursor to a single array.  The array cannot be
 * interpreted meaningfully without the number of columns.
 *
 * @param cursor
 * @param limit Maximum number of rows to process.
 * @return List of Java primitives matching the value type of each column, converted to
 *      strings.
 */
private static ArrayList<String> flattenRows(Cursor cursor, int limit) {
  Util.throwIfNot(limit >= 0);
  ArrayList<String> flatList = new ArrayList<>();
  final int numColumns = cursor.getColumnCount();
  for (int row = 0; row < limit && cursor.moveToNext(); row++) {
    for (int column = 0; column < numColumns; column++) {
      switch (cursor.getType(column)) {
        case Cursor.FIELD_TYPE_NULL:
          flatList.add(null);
          break;
        case Cursor.FIELD_TYPE_INTEGER:
          flatList.add(String.valueOf(cursor.getLong(column)));
          break;
        case Cursor.FIELD_TYPE_FLOAT:
          flatList.add(String.valueOf(cursor.getDouble(column)));
          break;
        case Cursor.FIELD_TYPE_BLOB:
          flatList.add(blobToString(cursor.getBlob(column)));
          break;
        case Cursor.FIELD_TYPE_STRING:
        default:
          flatList.add(cursor.getString(column));
          break;
      }
    }
  }
  if (!cursor.isAfterLast()) {
    for (int column = 0; column < numColumns; column++) {
      flatList.add("{truncated}");
    }
  }
  return flatList;
}
 
Example 10
Source File: DataBaseUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static int getTypeOfObject(Object obj) {
    if (obj == null) {
        return Cursor.FIELD_TYPE_NULL;
    } else if (obj instanceof byte[]) {
        return Cursor.FIELD_TYPE_BLOB;
    } else if (obj instanceof Float || obj instanceof Double) {
        return Cursor.FIELD_TYPE_FLOAT;
    } else if (obj instanceof Long || obj instanceof Integer
            || obj instanceof Short || obj instanceof Byte) {
        return Cursor.FIELD_TYPE_INTEGER;
    } else {
        return Cursor.FIELD_TYPE_STRING;
    }
}
 
Example 11
Source File: SMSReceive.java    From cordova-plugin-sms-receive with MIT License 5 votes vote down vote up
private JSONObject getJsonFromCursor(Cursor cur) {
	JSONObject json = new JSONObject();
	int nCol = cur.getColumnCount();
	String keys[] = cur.getColumnNames();
	try {
		for (int j=0; j<nCol; j++) {
			switch(cur.getType(j)) {
				case Cursor.FIELD_TYPE_NULL:
					json.put(keys[j], JSONObject.NULL);
				break;
				case Cursor.FIELD_TYPE_INTEGER:
					json.put(keys[j], cur.getLong(j));
				break;
				case Cursor.FIELD_TYPE_FLOAT:
					json.put(keys[j], cur.getFloat(j));
				break;
				case Cursor.FIELD_TYPE_STRING:
					json.put(keys[j], cur.getString(j));
				break;
				case Cursor.FIELD_TYPE_BLOB:
					json.put(keys[j], cur.getBlob(j));
				break;
			}
		}
	}
	catch (Exception e) {
		return null;
	}
	return json;
}
 
Example 12
Source File: DbSqlite.java    From Collection-Android with MIT License 5 votes vote down vote up
/**
 * set data in cursor to ResultSet List
 * @param cursor
 * @param resultList the data will set in it
 */
private void parseCursorToResult(Cursor cursor, List<ResultSet> resultList){
	int columnCount;
	int columnType;
	Object columnVal = null;
	while (cursor.moveToNext()) {
		columnCount = cursor.getColumnCount();
		ResultSet result = new ResultSet();
		for (int index = 0; index < columnCount; ++index) {
			columnType = cursor.getType(index);
			switch (columnType) {
			case Cursor.FIELD_TYPE_BLOB:
				columnVal = cursor.getBlob(index);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columnVal = cursor.getDouble(index);
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columnVal = cursor.getLong(index);
				break;
			case Cursor.FIELD_TYPE_NULL:
				columnVal = null;
				break;
			default:
				columnVal = cursor.getString(index);
				break;
			}
			result.setValue(cursor.getColumnName(index), columnVal);
		}
		resultList.add(result);
	}
}
 
Example 13
Source File: DbSqlite.java    From SqliteLookup with Apache License 2.0 5 votes vote down vote up
/**
 * set data in cursor to ResultSet List
 * @param cursor
 * @param resultList the data will set in it
 */
private void parseCursorToResult(Cursor cursor,List<ResultSet> resultList){
	int columnCount;
	int columnType;
	Object columnVal = null;
	while (cursor.moveToNext()) {
		columnCount = cursor.getColumnCount();
		ResultSet result = new ResultSet();
		for (int index = 0; index < columnCount; ++index) {
			columnType = cursor.getType(index);
			switch (columnType) {
			case Cursor.FIELD_TYPE_BLOB:
				columnVal = cursor.getBlob(index);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columnVal = cursor.getDouble(index);
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columnVal = cursor.getLong(index);
				break;
			case Cursor.FIELD_TYPE_NULL:
				columnVal = null;
				break;
			default:
				columnVal = cursor.getString(index);
				break;
			}
			result.setValue(cursor.getColumnName(index), columnVal);
		}
		resultList.add(result);
	}
}
 
Example 14
Source File: FullBackupExporter.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static int exportTable(@NonNull   String table,
                               @NonNull   SQLiteDatabase input,
                               @NonNull   BackupFrameOutputStream outputStream,
                               @Nullable  Predicate<Cursor> predicate,
                               @Nullable  Consumer<Cursor> postProcess,
                                          int count)
    throws IOException
{
  String template = "INSERT INTO " + table + " VALUES ";

  try (Cursor cursor = input.rawQuery("SELECT * FROM " + table, null)) {
    while (cursor != null && cursor.moveToNext()) {
      EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.PROGRESS, ++count));

      if (predicate == null || predicate.test(cursor)) {
        StringBuilder                     statement        = new StringBuilder(template);
        BackupProtos.SqlStatement.Builder statementBuilder = BackupProtos.SqlStatement.newBuilder();

        statement.append('(');

        for (int i=0;i<cursor.getColumnCount();i++) {
          statement.append('?');

          if (cursor.getType(i) == Cursor.FIELD_TYPE_STRING) {
            statementBuilder.addParameters(BackupProtos.SqlStatement.SqlParameter.newBuilder().setStringParamter(cursor.getString(i)));
          } else if (cursor.getType(i) == Cursor.FIELD_TYPE_FLOAT) {
            statementBuilder.addParameters(BackupProtos.SqlStatement.SqlParameter.newBuilder().setDoubleParameter(cursor.getDouble(i)));
          } else if (cursor.getType(i) == Cursor.FIELD_TYPE_INTEGER) {
            statementBuilder.addParameters(BackupProtos.SqlStatement.SqlParameter.newBuilder().setIntegerParameter(cursor.getLong(i)));
          } else if (cursor.getType(i) == Cursor.FIELD_TYPE_BLOB) {
            statementBuilder.addParameters(BackupProtos.SqlStatement.SqlParameter.newBuilder().setBlobParameter(ByteString.copyFrom(cursor.getBlob(i))));
          } else if (cursor.getType(i) == Cursor.FIELD_TYPE_NULL) {
            statementBuilder.addParameters(BackupProtos.SqlStatement.SqlParameter.newBuilder().setNullparameter(true));
          } else {
            throw new AssertionError("unknown type?"  + cursor.getType(i));
          }

          if (i < cursor.getColumnCount()-1) {
            statement.append(',');
          }
        }

        statement.append(')');

        outputStream.write(statementBuilder.setStatement(statement.toString()).build());

        if (postProcess != null) postProcess.accept(cursor);
      }
    }
  }

  return count;
}
 
Example 15
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 16
Source File: SqliteManagerPresenter.java    From SqliteManager with Apache License 2.0 4 votes vote down vote up
private
@NonNull
SqliteResponseData getSqliteResponseDataFromQuery(String query, String[] selectionArgs) {
    SqliteResponse sqliteResponse = mSqliteResponseRetriever.getData(query, selectionArgs);
    if (sqliteResponse.isQuerySuccess()) {
        try {
            Cursor cursor = sqliteResponse.getCursor();
            String[] selectedTableColumnNames = cursor.getColumnNames();
            int[] selectedTableColumnTypes = new int[selectedTableColumnNames.length];
            int columnCount = cursor.getColumnCount();
            List<SparseArray<Object>> valuesArray = new ArrayList<>(cursor.getCount());

            if (cursor.moveToFirst()) {
                do {
                    SparseArray<Object> columnValuePair = new SparseArray<>(columnCount);
                    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                        int fieldType = cursor.getType(columnIndex);
                        selectedTableColumnTypes[columnIndex] = fieldType;
                        if (fieldType == Cursor.FIELD_TYPE_NULL) {
                            columnValuePair.put(columnIndex, cursor.getString(columnIndex));
                        } else if (fieldType == Cursor.FIELD_TYPE_INTEGER) {
                            columnValuePair.put(columnIndex, cursor.getInt(columnIndex));
                        } else if (fieldType == Cursor.FIELD_TYPE_FLOAT) {
                            columnValuePair.put(columnIndex, cursor.getFloat(columnIndex));
                        } else if (fieldType == Cursor.FIELD_TYPE_STRING) {
                            columnValuePair.put(columnIndex, cursor.getString(columnIndex));
                        } else if (fieldType == Cursor.FIELD_TYPE_BLOB) {
                            columnValuePair.put(columnIndex, cursor.getBlob(columnIndex));
                        } else {
                            // never in this case
                            columnValuePair.put(columnIndex, cursor.getString(columnIndex));
                        }
                    }
                    valuesArray.add(columnValuePair);
                } while (cursor.moveToNext());
            }
            return new SqliteResponseData(columnCount, selectedTableColumnNames, selectedTableColumnTypes, valuesArray);
        } catch (Exception exception) {
            // sometimes cursor will not be null. when there are any constraints
            return new SqliteResponseData(exception);
        } finally {
            mSqliteDataRetriever.freeResources();
        }
    } else {
        mSqliteDataRetriever.freeResources();
        return new SqliteResponseData(sqliteResponse.getThrowable());
    }
}
 
Example 17
Source File: HumanReadables.java    From android-test with Apache License 2.0 4 votes vote down vote up
public static String describe(Cursor c) {
  if (c.isBeforeFirst()) {
    return "Cursor positioned before first element.";
  } else if (c.isAfterLast()) {
    return "Cursor positioned after last element.";
  }
  StringBuilder result = new StringBuilder("Row ").append(c.getPosition()).append(": {");
  String[] columns = c.getColumnNames();
  for (int i = 0; i < columns.length; i++) {
    result.append(columns[i]).append(":");
    int type = Cursor.FIELD_TYPE_STRING;
    if (Build.VERSION.SDK_INT > 10) {
      type = c.getType(i);
    }
    switch (type) {
      case Cursor.FIELD_TYPE_STRING:
        result.append("\"").append(c.getString(i)).append("\"");
        break;
      case Cursor.FIELD_TYPE_INTEGER:
        result.append(c.getLong(i));
        break;
      case Cursor.FIELD_TYPE_FLOAT:
        result.append(c.getDouble(i));
        result.append("f");
        break;
      case Cursor.FIELD_TYPE_NULL:
        result.append("null");
        break;
      case Cursor.FIELD_TYPE_BLOB:
        byte[] val = c.getBlob(i);
        result.append("[");
        for (int j = 0; j < 5 && j < val.length; j++) {
          result.append(val[j]);
          result.append(",");
        }
        if (5 < val.length) {
          result.append("... (").append(val.length - 5).append(" more elements)");
        }
        result.append("]");
        break;
      default:
        result.append("\"").append(c.getString(i)).append("\"");
        break;
    }
    result.append(", ");
  }
  result.append("}");
  return result.toString();
}
 
Example 18
Source File: PaginatedCursor.java    From BuildingForAndroidTV with MIT License 4 votes vote down vote up
public PaginatedCursor(Cursor cursor) {
    super();
    mCursor = cursor;
    mRowCount = mCursor.getCount();
    mCachedRows = new boolean[mRowCount];
    mColumnNames = mCursor.getColumnNames();
    mColumnCount = mCursor.getColumnCount();
    mColumnTypes = new int[mColumnCount];

    mByteArrayCacheColumnSize = 0;
    mFloatCacheColumnSize = 0;
    mIntCacheColumnSize = 0;
    mStringCacheColumnSize = 0;

    mByteArrayCacheIndexMap = new int[mColumnCount];
    mFloatCacheIndexMap = new int[mColumnCount];
    mIntCacheIndexMap = new int[mColumnCount];
    mStringCacheIndexMap = new int[mColumnCount];

    mCursor.moveToFirst();
    for (int i = 0; i < mColumnCount; i++) {
        int type = mCursor.getType(i);
        mColumnTypes[i] = type;
        switch (type) {
            case Cursor.FIELD_TYPE_BLOB:
                mByteArrayCacheIndexMap[i] = mByteArrayCacheColumnSize++;
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                mFloatCacheIndexMap[i] = mFloatCacheColumnSize++;
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                mIntCacheIndexMap[i] = mIntCacheColumnSize++;
                break;
            case Cursor.FIELD_TYPE_STRING:
                mStringCacheIndexMap[i] = mStringCacheColumnSize++;
                break;
        }
    }

    mByteArrayDataCache = mByteArrayCacheColumnSize > 0 ? new byte[mRowCount][][] : null;
    mFloatDataCache = mFloatCacheColumnSize > 0 ? new float[mRowCount][] : null;
    mIntDataCache = mIntCacheColumnSize > 0 ? new int[mRowCount][] : null;
    mStringDataCache = mStringCacheColumnSize > 0 ? new String[mRowCount][] : null;

    for (int i = 0; i < mRowCount; i++) {
        mCachedRows[i] = false;
        if (mByteArrayDataCache != null) {
            mByteArrayDataCache[i] = new byte[mByteArrayCacheColumnSize][];
        }
        if (mFloatDataCache != null) {
            mFloatDataCache[i] = new float[mFloatCacheColumnSize];
        }
        if (mIntDataCache != null) {
            mIntDataCache[i] = new int[mIntCacheColumnSize];
        }
        if (mStringDataCache != null) {
            mStringDataCache[i] = new String[mStringCacheColumnSize];
        }
    }

    // Cache at the initialization stage.
    loadCacheStartingFromPosition(0);
}
 
Example 19
Source File: DebugHelper.java    From XMiTools with GNU General Public License v3.0 4 votes vote down vote up
public static void printCursor(Uri uri, Cursor c) {
    XLog.d("%s", uri.toString());
    if (c == null) {
        return;
    }
    boolean hasNext = c.moveToNext();
    if (!hasNext) {
        return;
    }

    int columnCount = c.getColumnCount();
    String[] columnNames = c.getColumnNames();
    int[] columnTypes = new int[columnCount];
    for (int i = 0; i < columnCount; i++) {
        columnTypes[i] = c.getType(i);
    }
    c.moveToPrevious();
    while (c.moveToNext()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < columnCount; i++) {
            Object value = null;
            int columnType = columnTypes[i];
            if (columnType == Cursor.FIELD_TYPE_INTEGER) {
                c.getInt(i);
            }
            switch (columnType) {
                case Cursor.FIELD_TYPE_INTEGER:
                    value = c.getInt(i);
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    value = c.getBlob(i);
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    value = c.getFloat(i);
                    break;
                case Cursor.FIELD_TYPE_STRING:
                    value = c.getString(i);
                    break;
                default:
                case Cursor.FIELD_TYPE_NULL:
                    break;
            }
            sb.append(columnNames[i]).append(" = ").append(value).append(", ");
        }
        sb.append("\n");
        XLog.d("%s", sb.toString());
    }
}
 
Example 20
Source File: ExtraUtils.java    From squidb with Apache License 2.0 3 votes vote down vote up
/**
 * Returns data type of the given object's value.
 *<p>
 * Returned values are
 * <ul>
 *   <li>{@link Cursor#FIELD_TYPE_NULL}</li>
 *   <li>{@link Cursor#FIELD_TYPE_INTEGER}</li>
 *   <li>{@link Cursor#FIELD_TYPE_FLOAT}</li>
 *   <li>{@link Cursor#FIELD_TYPE_STRING}</li>
 *   <li>{@link Cursor#FIELD_TYPE_BLOB}</li>
 *</ul>
 *</p>
 *
 * @param obj the object whose value type is to be returned
 * @return object value type
 */
public static int getTypeOfObject(Object obj) {
    if (obj == null) {
        return Cursor.FIELD_TYPE_NULL;
    } else if (obj instanceof byte[]) {
        return Cursor.FIELD_TYPE_BLOB;
    } else if (obj instanceof Float || obj instanceof Double) {
        return Cursor.FIELD_TYPE_FLOAT;
    } else if (obj instanceof Long || obj instanceof Integer
            || obj instanceof Short || obj instanceof Byte) {
        return Cursor.FIELD_TYPE_INTEGER;
    } else {
        return Cursor.FIELD_TYPE_STRING;
    }
}