Java Code Examples for android.database.Cursor#FIELD_TYPE_NULL

The following examples show how to use android.database.Cursor#FIELD_TYPE_NULL . 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: 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 2
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 3
Source File: OCursorListAdapter.java    From framework with GNU Affero General Public License v3.0 6 votes vote down vote up
private Object getValue(Cursor c, String column) {
    Object value = false;
    int index = c.getColumnIndex(column);
    switch (c.getType(index)) {
        case Cursor.FIELD_TYPE_NULL:
            value = false;
            break;
        case Cursor.FIELD_TYPE_BLOB:
        case Cursor.FIELD_TYPE_STRING:
            value = c.getString(index);
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            value = c.getFloat(index);
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            value = c.getInt(index);
            break;
    }
    return value;
}
 
Example 4
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void bindRow(WritableMap row, String key, Cursor cur, int i) {
    int curType = cur.getType(i);

    switch (curType) {
        case Cursor.FIELD_TYPE_NULL:
            row.putNull(key);
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            row.putDouble(key, cur.getLong(i));
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            row.putDouble(key, cur.getDouble(i));
            break;
        case Cursor.FIELD_TYPE_BLOB:
            row.putString(key, new String(Base64.encode(cur.getBlob(i), Base64.DEFAULT)));
            break;
        case Cursor.FIELD_TYPE_STRING:
        default: /* (not expected) */
            row.putString(key, cur.getString(i));
            break;
    }
}
 
Example 5
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 6
Source File: DatabaseResult.java    From pandora with Apache License 2.0 5 votes vote down vote up
private static List<List<String>> wrapRows(Cursor cursor) {
    List<List<String>> result = new ArrayList<>();

    final int numColumns = cursor.getColumnCount();
    while (cursor.moveToNext()) {
        ArrayList<String> flatList = new ArrayList<>();
        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;
            }
        }
        result.add(flatList);
    }
    return result;
}
 
Example 7
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 8
Source File: XContentResolver.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
private void copyColumns(Cursor cursor, MatrixCursor result, int count) {
	try {
		Object[] columns = new Object[count];
		for (int i = 0; i < count; i++)
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_NULL:
				columns[i] = null;
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columns[i] = cursor.getInt(i);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columns[i] = cursor.getFloat(i);
				break;
			case Cursor.FIELD_TYPE_STRING:
				columns[i] = cursor.getString(i);
				break;
			case Cursor.FIELD_TYPE_BLOB:
				columns[i] = cursor.getBlob(i);
				break;
			default:
				Util.log(this, Log.WARN, "Unknown cursor data type=" + cursor.getType(i));
			}
		result.addRow(columns);
	} catch (Throwable ex) {
		Util.bug(this, ex);
	}
}
 
Example 9
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 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: 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 12
Source File: SQLiteConnection.java    From sqlite-android with Apache License 2.0 4 votes vote down vote up
private void bindArguments(PreparedStatement statement, Object[] bindArgs) {
    final int count = bindArgs != null ? bindArgs.length : 0;
    if (count != statement.mNumParameters) {
        String message = "Expected " + statement.mNumParameters + " bind arguments but "
            + count + " were provided.";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            throw new SQLiteBindOrColumnIndexOutOfRangeException(message);
        } else {
            throw new SQLiteException(message);
        }
    }
    if (count == 0) {
        return;
    }

    final long statementPtr = statement.mStatementPtr;
    for (int i = 0; i < count; i++) {
        final Object arg = bindArgs[i];
        switch (getTypeOfObject(arg)) {
            case Cursor.FIELD_TYPE_NULL:
                nativeBindNull(mConnectionPtr, statementPtr, i + 1);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).longValue());
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                nativeBindDouble(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).doubleValue());
                break;
            case Cursor.FIELD_TYPE_BLOB:
                nativeBindBlob(mConnectionPtr, statementPtr, i + 1, (byte[])arg);
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                if (arg instanceof Boolean) {
                    // Provide compatibility with legacy applications which may pass
                    // Boolean values in bind args.
                    nativeBindLong(mConnectionPtr, statementPtr, i + 1, (Boolean) arg ? 1 : 0);
                } else {
                    nativeBindString(mConnectionPtr, statementPtr, i + 1, arg.toString());
                }
                break;
        }
    }
}
 
Example 13
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 14
Source File: CursorHelper.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * 指定したCursorの現在のレコードを文字列に変換
 * @param cursor
 */
public static String toString(@Nullable final Cursor cursor) {
	if (cursor == null) {
		return "{null}";
	} else if (cursor.isClosed()) {
		return "{closed}";
	} else if (cursor.isBeforeFirst()) {
		return "{before first}";
	} else if (cursor.isAfterLast()) {
		return "{after last}";
	} else {
		final StringBuilder sb = new StringBuilder();
		final int n = cursor.getColumnCount();
		final String[] columnNames = cursor.getColumnNames();
		sb.append("{");
		for (int i = 0; i < n; i++) {
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_FLOAT:
				sb.append(columnNames[i]).append("=").append(cursor.getDouble(i));
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				sb.append(columnNames[i]).append("=").append(cursor.getLong(i));
				break;
			case Cursor.FIELD_TYPE_STRING:
				sb.append(columnNames[i]).append("=").append(cursor.getString(i));
				break;
			case Cursor.FIELD_TYPE_BLOB:
				sb.append(columnNames[i]).append("=").append("BLOB");
				break;
			case Cursor.FIELD_TYPE_NULL:
				sb.append(columnNames[i]).append("=").append("NULL");
				break;
			default:
				sb.append(columnNames[i]).append("=").append("UNKNOWN");
				break;
			}
			if (i < n-1) {
				sb.append(",");
			}
		}
		sb.append("}");
		return sb.toString();
	}
}
 
Example 15
Source File: Utils.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Useful for debugging during development, so that arbitrary queries can be made, and their
 * results inspected in the debugger.
 */
@SuppressWarnings("unused")
@RequiresApi(api = 11)
public static List<Map<String, String>> dumpCursor(Cursor cursor) {
    List<Map<String, String>> data = new ArrayList<>();

    if (cursor == null) {
        return data;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Map<String, String> row = new HashMap<>(cursor.getColumnCount());
        for (String col : cursor.getColumnNames()) {
            int i = cursor.getColumnIndex(col);
            switch (cursor.getType(i)) {
                case Cursor.FIELD_TYPE_NULL:
                    row.put(col, null);
                    break;

                case Cursor.FIELD_TYPE_INTEGER:
                    row.put(col, Integer.toString(cursor.getInt(i)));
                    break;

                case Cursor.FIELD_TYPE_FLOAT:
                    row.put(col, Double.toString(cursor.getFloat(i)));
                    break;

                case Cursor.FIELD_TYPE_STRING:
                    row.put(col, cursor.getString(i));
                    break;

                case Cursor.FIELD_TYPE_BLOB:
                    row.put(col, new String(cursor.getBlob(i), Charset.defaultCharset()));
                    break;
            }
        }
        data.add(row);
        cursor.moveToNext();
    }

    cursor.close();
    return data;
}
 
Example 16
Source File: SQLiteConnection.java    From squidb with Apache License 2.0 4 votes vote down vote up
private void bindArguments(PreparedStatement statement, Object[] bindArgs) {
    final int count = bindArgs != null ? bindArgs.length : 0;
    if (count != statement.mNumParameters) {
        throw new SQLiteBindOrColumnIndexOutOfRangeException(
                "Expected " + statement.mNumParameters + " bind arguments but "
                + count + " were provided.");
    }
    if (count == 0) {
        return;
    }

    final long statementPtr = statement.mStatementPtr;
    for (int i = 0; i < count; i++) {
        final Object arg = bindArgs[i];
        switch (ExtraUtils.getTypeOfObject(arg)) {
            case Cursor.FIELD_TYPE_NULL:
                nativeBindNull(mConnectionPtr, statementPtr, i + 1);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).longValue());
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                nativeBindDouble(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).doubleValue());
                break;
            case Cursor.FIELD_TYPE_BLOB:
                nativeBindBlob(mConnectionPtr, statementPtr, i + 1, (byte[])arg);
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                if (arg instanceof Boolean) {
                    // Provide compatibility with legacy applications which may pass
                    // Boolean values in bind args.
                    nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                            ((Boolean)arg).booleanValue() ? 1 : 0);
                } else {
                    nativeBindString(mConnectionPtr, statementPtr, i + 1, arg.toString());
                }
                break;
        }
    }
}
 
Example 17
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 18
Source File: TileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate a tile row
 *
 * @param dao
 * @param columns
 * @param tileRow
 * @param testBitmap
 */
private static void validateTileRow(TileDao dao, String[] columns,
                                    TileRow tileRow, boolean testBitmap) {
    TestCase.assertEquals(columns.length, tileRow.columnCount());

    for (int i = 0; i < tileRow.columnCount(); i++) {
        TileColumn column = tileRow.getTable().getColumns().get(i);
        TestCase.assertEquals(i, column.getIndex());
        TestCase.assertEquals(columns[i], tileRow.getColumnName(i));
        TestCase.assertEquals(i, tileRow.getColumnIndex(columns[i]));
        int rowType = tileRow.getRowColumnType(i);
        Object value = tileRow.getValue(i);

        switch (rowType) {

            case Cursor.FIELD_TYPE_INTEGER:
                TestUtils.validateIntegerValue(value, column.getDataType());
                break;

            case Cursor.FIELD_TYPE_FLOAT:
                TestUtils.validateFloatValue(value, column.getDataType());
                break;

            case Cursor.FIELD_TYPE_STRING:
                TestCase.assertTrue(value instanceof String);
                break;

            case Cursor.FIELD_TYPE_BLOB:
                TestCase.assertTrue(value instanceof byte[]);
                break;

            case Cursor.FIELD_TYPE_NULL:
                TestCase.assertNull(value);
                break;

        }
    }

    TestCase.assertTrue(tileRow.getId() >= 0);
    TestCase.assertTrue(tileRow.getZoomLevel() >= 0);
    TestCase.assertTrue(tileRow.getTileColumn() >= 0);
    TestCase.assertTrue(tileRow.getTileRow() >= 0);
    byte[] tileData = tileRow.getTileData();
    TestCase.assertNotNull(tileData);
    TestCase.assertTrue(tileData.length > 0);

    TileMatrix tileMatrix = dao.getTileMatrix(tileRow.getZoomLevel());
    TestCase.assertNotNull(tileMatrix);

    if (testBitmap) {
        Bitmap bitmap = tileRow.getTileDataBitmap();
        if (dao.getTileMatrixSet().getContents().getDataType() != ContentsDataType.GRIDDED_COVERAGE) {
            TestCase.assertNotNull(bitmap);
            TestCase.assertEquals(tileMatrix.getTileWidth(), bitmap.getWidth());
            TestCase.assertEquals(tileMatrix.getTileHeight(),
                    bitmap.getHeight());
        }
    }
}
 
Example 19
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void bindArguments(PreparedStatement statement, Object[] bindArgs) {
    final int count = bindArgs != null ? bindArgs.length : 0;
    if (count != statement.mNumParameters) {
        throw new SQLiteBindOrColumnIndexOutOfRangeException(
                "Expected " + statement.mNumParameters + " bind arguments but "
                + count + " were provided.");
    }
    if (count == 0) {
        return;
    }

    final long statementPtr = statement.mStatementPtr;
    for (int i = 0; i < count; i++) {
        final Object arg = bindArgs[i];
        switch (DatabaseUtils.getTypeOfObject(arg)) {
            case Cursor.FIELD_TYPE_NULL:
                nativeBindNull(mConnectionPtr, statementPtr, i + 1);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).longValue());
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                nativeBindDouble(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).doubleValue());
                break;
            case Cursor.FIELD_TYPE_BLOB:
                nativeBindBlob(mConnectionPtr, statementPtr, i + 1, (byte[])arg);
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                if (arg instanceof Boolean) {
                    // Provide compatibility with legacy applications which may pass
                    // Boolean values in bind args.
                    nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                            ((Boolean)arg).booleanValue() ? 1 : 0);
                } else {
                    nativeBindString(mConnectionPtr, statementPtr, i + 1, arg.toString());
                }
                break;
        }
    }
}
 
Example 20
Source File: SQLiteConnection.java    From sqlite-android with Apache License 2.0 4 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
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private 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;
    }
}