public String getNString(int columnIndex) throws SQLException { return getString(columnIndex); }
public String getNString(int columnIndex) throws SQLException { return getString(columnIndex); }
public String getNString(String columnLabel) throws SQLException { return getString(columnLabel); }
public String getNString(String columnLabel) throws SQLException { return getString(columnLabel); }
public String getString(String columnName) throws SQLException { // find the columnIndex for the given column name. return getString(findColumn(columnName)); }
public String getString(String columnName) throws SQLException { // find the columnIndex for the given column name. return getString(findColumn(columnName)); }
@Test public void testAllGetters() throws SQLException { ResultSetImpl cs = helpExecuteQuery(); cs.next(); assertEquals(" Actual value of getInt() doesn't match with expected one. ", 1, cs.getInt("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(" Actual value of getString() doesn't match with expected one. ", "1", cs.getString("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // Add these back when the MediumA has all those columns assertEquals(" Actual value of getFloat() doesn't match with expected one. ", new Float(1), new Float(cs.getFloat("IntKey"))); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(" Actual value of getLong() doesn't match with expected one. ", 1, cs.getLong("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(" Actual value of getDouble() doesn't match with expected one. ", new Double(1), new Double(cs.getDouble("IntKey"))); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(" Actual value of getByte() doesn't match with expected one. ", (byte)1, cs.getByte("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testXML() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>(); future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true)); XMLType result = new XMLType(); Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future); ResultsMessage resultsMsg = new ResultsMessage(); result.setEncoding("UTF-8"); resultsMsg.setResults(new List<?>[] {Arrays.asList(result)}); resultsMsg.setLastRow(1); resultsMsg.setFirstRow(1); resultsMsg.setFinalRow(1); resultsMsg.setColumnNames(new String[] {"x"}); //$NON-NLS-1$ resultsMsg.setDataTypes(new String[] {"xml"}); //$NON-NLS-1$ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement); cs.next(); assertEquals("<a/>", cs.getString(1)); }
@Test public void testGetters() throws SQLException{ TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00")); //$NON-NLS-1$ ResultsMessage message = exampleMessage(new List[] { Arrays.asList(1, TimestampUtil.createTime(0, 0, 0), TimestampUtil.createDate(1, 1, 1), TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), "<root/>") }, //$NON-NLS-1$ new String[] { "int", "time", "date", "timestamp", "sqlxml" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.TIME, DataTypeManager.DefaultDataTypes.DATE, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.STRING }); TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$ ResultSetImpl rs = new ResultSetImpl(message, statement); assertTrue(rs.next()); assertEquals(Boolean.TRUE.booleanValue(), rs.getBoolean(1)); assertEquals(1, rs.getShort(1)); assertEquals(1, rs.getInt(1)); assertEquals(1l, rs.getLong(1)); assertEquals(1f, rs.getFloat(1), 0); assertEquals(1d, rs.getDouble(1), 0); assertEquals("1", rs.getString(1)); //$NON-NLS-1$ assertEquals(Integer.valueOf(1), rs.getObject(1)); //the mock statement is in GMT-6 the server results are from GMT-5, so we expect them to display the same assertEquals(TimestampUtil.createTime(0, 0, 0), rs.getTime(2)); assertEquals(TimestampUtil.createDate(1, 1, 1), rs.getDate(3)); assertEquals(TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), rs.getTimestamp(4)); assertEquals("<root/>", rs.getSQLXML(5).getString()); //$NON-NLS-1$ try { rs.getSQLXML(1); } catch (SQLException e) { assertEquals("Unable to transform the column value 1 to a SQLXML.", e.getMessage()); //$NON-NLS-1$ } assertFalse(rs.next()); TimestampWithTimezone.resetCalendar(null); }
@Test public void testWasNull() throws SQLException{ ResultsMessage message = exampleMessage(new List[] { Arrays.asList((String)null), Arrays.asList("1") }, new String[] { "string" }, //$NON-NLS-1$ new String[] { DataTypeManager.DefaultDataTypes.STRING }); ResultSetImpl rs = new ResultSetImpl(message, statement); assertTrue(rs.next()); assertEquals(Boolean.FALSE.booleanValue(), rs.getBoolean(1)); assertTrue(rs.wasNull()); assertEquals(0, rs.getShort(1)); assertTrue(rs.wasNull()); assertEquals(0, rs.getInt(1)); assertTrue(rs.wasNull()); assertEquals(0l, rs.getLong(1)); assertTrue(rs.wasNull()); assertEquals(0f, rs.getFloat(1), 0); assertTrue(rs.wasNull()); assertEquals(0d, rs.getDouble(1), 0); assertTrue(rs.wasNull()); assertNull(rs.getString(1)); assertTrue(rs.wasNull()); assertTrue(rs.next()); assertEquals(1, rs.getShort(1)); assertFalse(rs.wasNull()); assertFalse(rs.next()); }