use of com.microsoft.sqlserver.testframework.DBStatement in project mssql-jdbc by Microsoft.
the class BulkCopyTestUtil method validateValues.
/**
* validate if same values are in both source and destination table
*
* @param con
* @param sourceTable
* @param destinationTable
* @throws SQLException
*/
static void validateValues(DBConnection con, DBTable sourceTable, DBTable destinationTable) throws SQLException {
try (DBStatement srcStmt = con.createStatement();
DBStatement dstStmt = con.createStatement();
DBResultSet srcResultSet = srcStmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
DBResultSet dstResultSet = dstStmt.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
ResultSetMetaData destMeta = ((ResultSet) dstResultSet.product()).getMetaData();
int totalColumns = destMeta.getColumnCount();
// verify data from sourceType and resultSet
while (srcResultSet.next() && dstResultSet.next()) {
for (int i = 1; i <= totalColumns; i++) {
// TODO: check row and column count in both the tables
Object srcValue, dstValue;
srcValue = srcResultSet.getObject(i);
dstValue = dstResultSet.getObject(i);
ComparisonUtil.compareExpectedAndActual(destMeta.getColumnType(i), srcValue, dstValue);
}
}
}
}
use of com.microsoft.sqlserver.testframework.DBStatement in project mssql-jdbc by Microsoft.
the class TVPAllTypes method setupVariation.
private void setupVariation() throws SQLException {
conn = DriverManager.getConnection(connectionString);
stmt = conn.createStatement();
Utils.dropProcedureIfExists(procedureName, stmt);
dropTVPS(tvpName);
DBConnection dbConnection = new DBConnection(connectionString);
DBStatement dbStmt = dbConnection.createStatement();
tableSrc = new DBTable(true);
tableDest = tableSrc.cloneSchema();
dbStmt.createTable(tableSrc);
dbStmt.createTable(tableDest);
createTVPS(tvpName, tableSrc.getDefinitionOfColumns());
createPreocedure(procedureName, tableDest.getEscapedTableName());
dbStmt.populateTable(tableSrc);
}
use of com.microsoft.sqlserver.testframework.DBStatement in project mssql-jdbc by Microsoft.
the class lobsTest method testMultipleClose.
/**
* Tests stream closures
*
* @param streamClass
* @throws Exception
*/
private void testMultipleClose(Class streamClass) throws Exception {
DBConnection conn = new DBConnection(connectionString);
String[] types = { "varchar(max)", "nvarchar(max)", "varbinary(max)" };
try {
table = this.createTable(table, types, true);
DBStatement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
String query = "select * from " + table.getEscapedTableName();
DBResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
for (int i = 0; i < 3; i++) {
DBColumn col = table.getColumns().get(i);
if (!col.getSqlType().canConvert(streamClass, DBCoercion.GET, new DBConnection(connectionString)))
continue;
Object stream = rs.getXXX(i + 1, streamClass);
if (stream == null) {
assertEquals(stream, rs.getObject(i + 1), "Stream is null when data is not");
} else {
// close the stream twice
if (streamClass == DBCharacterStream.class) {
((Reader) stream).close();
((Reader) stream).close();
} else {
((InputStream) stream).close();
((InputStream) stream).close();
}
}
}
}
} finally {
if (null != table)
this.dropTables(table);
if (null != null)
conn.close();
}
}
use of com.microsoft.sqlserver.testframework.DBStatement in project mssql-jdbc by Microsoft.
the class BulkCopyColumnMappingTest method validateValuesRepetativeCM.
/**
* validate if same values are in both source and destination table taking into account 1 extra column in destination which should be a copy of
* first column of source.
*
* @param con
* @param sourceTable
* @param destinationTable
* @throws SQLException
*/
private void validateValuesRepetativeCM(DBConnection con, DBTable sourceTable, DBTable destinationTable) throws SQLException {
try (DBStatement srcStmt = con.createStatement();
DBStatement dstStmt = con.createStatement();
DBResultSet srcResultSet = srcStmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
DBResultSet dstResultSet = dstStmt.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
ResultSetMetaData sourceMeta = ((ResultSet) srcResultSet.product()).getMetaData();
int totalColumns = sourceMeta.getColumnCount();
// verify data from sourceType and resultSet
while (srcResultSet.next() && dstResultSet.next()) {
for (int i = 1; i <= totalColumns; i++) {
// TODO: check row and column count in both the tables
Object srcValue, dstValue;
srcValue = srcResultSet.getObject(i);
dstValue = dstResultSet.getObject(i);
ComparisonUtil.compareExpectedAndActual(sourceMeta.getColumnType(i), srcValue, dstValue);
// compare value of first column of source with extra column in destination
if (1 == i) {
Object srcValueFirstCol = srcResultSet.getObject(i);
Object dstValLastCol = dstResultSet.getObject(totalColumns + 1);
ComparisonUtil.compareExpectedAndActual(sourceMeta.getColumnType(i), srcValueFirstCol, dstValLastCol);
}
}
}
}
}
use of com.microsoft.sqlserver.testframework.DBStatement in project mssql-jdbc by Microsoft.
the class bvtTest method testStmtSserverCursorForwardOnly.
/**
* Create a statement TYPE_SS_SEVER_CURSOR_FORWARD_ONLY, CONCUR_READ_ONLY, executeQuery verify cursor by using next and verify data
*
* @throws SQLException
*/
@Test
public void testStmtSserverCursorForwardOnly() throws SQLException {
DBResultSetTypes rsType = DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY;
String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(rsType.resultsetCursor, rsType.resultSetConcurrency);
DBResultSet rs = stmt.executeQuery(query)) {
// Verify resultset behavior
rs.next();
rs.verify(table1);
}
}
Aggregations