use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testVarChar8000.
/**
* Test with varchar8000
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testVarChar8000() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 8000; i++) {
buffer.append("a");
}
String value = buffer.toString();
tvp.addRow(value);
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + destTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTable);
while (rs.next()) {
assertEquals(rs.getString(1), value);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testDuplicateColumn.
/**
* Test for allowing duplicate columns
*
* @throws SQLException
*/
@Test
public void testDuplicateColumn() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
tvp.addColumnMetadata("c2", microsoft.sql.Types.SQL_VARIANT);
try {
tvp.addColumnMetadata("c2", microsoft.sql.Types.SQL_VARIANT);
} catch (SQLException e) {
assertEquals(e.getMessage(), "A column name c2 already belongs to this SQLServerDataTable.");
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testDate.
/**
* Test with date value
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testDate() throws SQLException {
SqlDate sqlDate = new SqlDate();
Date date = (Date) sqlDate.createdata();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
tvp.addRow(date);
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + destTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTable);
while (rs.next()) {
// TODO: GetDate has issues
assertEquals(rs.getString(1), "" + date);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testLongVarChar.
/**
* Check that we throw proper error message when inserting more than 8000
*
* @throws SQLException
*/
@Test
public void testLongVarChar() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 8001; i++) {
buffer.append("a");
}
String value = buffer.toString();
tvp.addRow(value);
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + destTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
try {
pstmt.execute();
} catch (SQLException e) {
assertTrue(e.getMessage().contains("SQL_VARIANT does not support string values of length greater than 8000."));
} catch (Exception e) {
fail("Test should have failed! mistakenly inserted string value of more than 8000 in sql-variant");
} finally {
if (null != pstmt) {
pstmt.close();
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testMoney.
/**
* Test with money value
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testMoney() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
String[] numeric = createNumericValues();
tvp.addRow(new BigDecimal(numeric[14]));
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + destTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTable);
while (rs.next()) {
assertEquals(rs.getMoney(1), new BigDecimal(numeric[14]));
}
}
Aggregations