Java Code Examples for com.j256.ormlite.support.DatabaseResults#getString()

The following examples show how to use com.j256.ormlite.support.DatabaseResults#getString() . 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: StatementExecutor.java    From ormlite-core with ISC License 5 votes vote down vote up
@Override
public String[] mapRow(DatabaseResults results) throws SQLException {
	int columnN = results.getColumnCount();
	String[] result = new String[columnN];
	for (int colC = 0; colC < columnN; colC++) {
		result[colC] = results.getString(colC);
	}
	return result;
}
 
Example 2
Source File: BaseDaoImplTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Override
public Foo mapRow(DatabaseResults databaseResults) throws SQLException {
	Foo foo = new Foo();
	String[] columnNames = databaseResults.getColumnNames();
	for (int i = 0; i < columnNames.length; i++) {
		if (columnNames[i].equalsIgnoreCase(Foo.ID_COLUMN_NAME)) {
			foo.id = databaseResults.getInt(i);
		} else if (columnNames[i].equalsIgnoreCase(Foo.VAL_COLUMN_NAME)) {
			foo.val = databaseResults.getInt(i);
		} else if (columnNames[i].equalsIgnoreCase(Foo.STRING_COLUMN_NAME)) {
			foo.stringField = databaseResults.getString(i);
		}
	}
	return foo;
}
 
Example 3
Source File: ConditionPersister.java    From moVirt with Apache License 2.0 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
    return results.getString(columnPos);
}
 
Example 4
Source File: UuidType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 5
Source File: StringType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 6
Source File: BigDecimalStringType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 7
Source File: BigIntegerType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 8
Source File: DateStringType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 9
Source File: EnumStringType.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 10
Source File: DataPersisterManagerTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
	return results.getString(columnPos);
}
 
Example 11
Source File: BaseTypeTest.java    From ormlite-core with ISC License 4 votes vote down vote up
protected <T, ID> void testType(Dao<T, ID> dao, T foo, Class<T> clazz, Object javaVal, Object defaultSqlVal,
		Object sqlArg, String defaultValStr, DataType dataType, String columnName, boolean isValidGeneratedType,
		boolean isAppropriateId, boolean isEscapedValue, boolean isPrimitive, boolean isSelectArgRequired,
		boolean isStreamType, boolean isComparable, boolean isConvertableId) throws Exception {
	DataPersister dataPersister = dataType.getDataPersister();
	DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
	CompiledStatement stmt = null;
	if (sqlArg != null) {
		assertEquals(defaultSqlVal.getClass(), sqlArg.getClass());
	}
	try {
		stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
		DatabaseResults results = stmt.runQuery(null);
		assertTrue(results.next());
		int colNum = results.findColumn(columnName);
		Field field = clazz.getDeclaredField(columnName);
		FieldType fieldType = FieldType.createFieldType(databaseType, TABLE_NAME, field, clazz);
		assertEquals(dataType.getDataPersister(), fieldType.getDataPersister());
		Class<?>[] classes = fieldType.getDataPersister().getAssociatedClasses();
		if (classes.length > 0) {
			assertTrue(classes[0].isAssignableFrom(fieldType.getType()));
		}
		assertTrue(fieldType.getDataPersister().isValidForField(field));
		if (javaVal instanceof byte[]) {
			assertTrue(Arrays.equals((byte[]) javaVal,
					(byte[]) dataPersister.resultToJava(fieldType, results, colNum)));
		} else {
			Map<String, Integer> colMap = new HashMap<String, Integer>();
			colMap.put(columnName, colNum);
			Object result = fieldType.resultToJava(results, colMap);
			assertEquals(javaVal, result);
		}
		if (dataType == DataType.SERIALIZABLE) {
			try {
				dataPersister.parseDefaultString(fieldType, "");
				fail("parseDefaultString should have thrown for " + dataType);
			} catch (SQLException e) {
				// expected
			}
		} else if (defaultValStr != null) {
			Object parsedDefault = dataPersister.parseDefaultString(fieldType, defaultValStr);
			assertEquals(defaultSqlVal.getClass(), parsedDefault.getClass());
			if (dataType == DataType.BYTE_ARRAY || dataType == DataType.STRING_BYTES) {
				assertTrue(Arrays.equals((byte[]) defaultSqlVal, (byte[]) parsedDefault));
			} else {
				assertEquals(defaultSqlVal, parsedDefault);
			}
		}
		if (sqlArg == null) {
			// noop
		} else if (sqlArg instanceof byte[]) {
			assertTrue(Arrays.equals((byte[]) sqlArg, (byte[]) dataPersister.javaToSqlArg(fieldType, javaVal)));
		} else {
			assertEquals(sqlArg, dataPersister.javaToSqlArg(fieldType, javaVal));
		}
		assertEquals(isValidGeneratedType, dataPersister.isValidGeneratedType());
		assertEquals(isAppropriateId, dataPersister.isAppropriateId());
		assertEquals(isEscapedValue, dataPersister.isEscapedValue());
		assertEquals(isEscapedValue, dataPersister.isEscapedDefaultValue());
		assertEquals(isPrimitive, dataPersister.isPrimitive());
		assertEquals(isSelectArgRequired, dataPersister.isArgumentHolderRequired());
		assertEquals(isStreamType, dataPersister.isStreamType());
		assertEquals(isComparable, dataPersister.isComparable());
		if (isConvertableId) {
			assertNotNull(dataPersister.convertIdNumber(10));
		} else {
			assertNull(dataPersister.convertIdNumber(10));
		}
		List<T> list = dao.queryForAll();
		assertEquals(1, list.size());
		assertTrue(dao.objectsEqual(foo, list.get(0)));
		// if we have a value then look for it, floats don't find any results because of rounding issues
		if (javaVal != null && dataPersister.isComparable() && dataType != DataType.FLOAT
				&& dataType != DataType.FLOAT_OBJ) {
			// test for inline arguments
			list = dao.queryForMatching(foo);
			assertEquals(1, list.size());
			assertTrue(dao.objectsEqual(foo, list.get(0)));
			// test for SelectArg arguments
			list = dao.queryForMatchingArgs(foo);
			assertEquals(1, list.size());
			assertTrue(dao.objectsEqual(foo, list.get(0)));
		}
		if (dataType == DataType.STRING_BYTES || dataType == DataType.BYTE_ARRAY
				|| dataType == DataType.SERIALIZABLE) {
			// no converting from string to value
		} else {
			// test string conversion
			String stringVal = results.getString(colNum);
			Object convertedJavaVal = fieldType.convertStringToJavaField(stringVal, 0);
			assertEquals(javaVal, convertedJavaVal);
		}
	} finally {
		if (stmt != null) {
			stmt.close();
		}
		connectionSource.releaseConnection(conn);
	}
}