use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testInputProcedure2.
private void testInputProcedure2(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setString(1, charValues[1]);
callableStatement.setUniqueIdentifier(2, charValues[6]);
callableStatement.setString(3, charValues[2]);
callableStatement.setNString(4, charValues[3]);
callableStatement.setNString(5, charValues[4]);
callableStatement.setNString(6, charValues[5]);
callableStatement.setString(7, charValues[7]);
callableStatement.setNString(8, charValues[8]);
try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
rs.next();
assertEquals(rs.getString(1).trim(), charValues[1], "Test for input parameter fails.\n");
assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), "Test for input parameter fails.\n");
assertEquals(rs.getString(3).trim(), charValues[2], "Test for input parameter fails.\n");
assertEquals(rs.getString(4).trim(), charValues[3], "Test for input parameter fails.\n");
assertEquals(rs.getString(5).trim(), charValues[4], "Test for input parameter fails.\n");
assertEquals(rs.getString(6).trim(), charValues[5], "Test for input parameter fails.\n");
assertEquals(rs.getString(7).trim(), charValues[7], "Test for input parameter fails.\n");
assertEquals(rs.getString(8).trim(), charValues[8], "Test for input parameter fails.\n");
}
} catch (Exception e) {
fail(e.toString());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class SQLServerSpatialDatatypeTest method testCheckGeogMetaData.
@Test
public void testCheckGeogMetaData() throws SQLException {
beforeEachSetup();
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geogTableName + " (c1) VALUES (?)");
ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
Geography g = Geography.STGeomFromText("POINT (1 2 3 4)", 4326);
pstmt.setGeography(1, g);
pstmt.execute();
int sqlType = paramMetaData.getParameterType(1);
String sqlTypeName = paramMetaData.getParameterTypeName(1);
assertEquals(sqlType, -158);
assertEquals(sqlTypeName, "geography");
SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geogTableName);
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(rsmd.getColumnType(1), -158);
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetCrossReference.
/**
* test getCrossReference() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetCrossReference() throws SQLException {
String fkTable = table1;
String[] tableNames = { table2, table3, table4, table5 };
int[][] values = { // expected UPDATE_RULE, expected DELETE_RULE
{ 4, 3 }, { 2, 0 }, { 0, 2 }, { 3, 4 } };
SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
for (int i = 0; i < tableNames.length; i++) {
String pkTable = tableNames[i];
SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getCrossReference(null, null, pkTable, null, null, fkTable);
rs1.next();
assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getCrossReference(catalog, schema, pkTable, catalog, schema, fkTable);
rs2.next();
assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getCrossReference(catalog, "", pkTable, catalog, "", fkTable);
rs3.next();
assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
try {
dmd.getCrossReference("", schema, pkTable, "", schema, fkTable);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertEquals(EXPECTED_ERROR_MESSAGE2, e.getMessage());
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetExportedKeys.
/**
* test getExportedKeys() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetExportedKeys() throws SQLException {
String[] tableNames = { table2, table3, table4, table5 };
int[][] values = { // expected UPDATE_RULE, expected DELETE_RULE
{ 4, 3 }, { 2, 0 }, { 0, 2 }, { 3, 4 } };
SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
for (int i = 0; i < tableNames.length; i++) {
String pkTable = tableNames[i];
SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getExportedKeys(null, null, pkTable);
rs1.next();
assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getExportedKeys(catalog, schema, pkTable);
rs2.next();
assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getExportedKeys(catalog, "", pkTable);
rs3.next();
assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
try {
dmd.getExportedKeys("", schema, pkTable);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE));
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class ResultSetWrapper42Test method SQLServerResultSet42Test.
/**
* Tests creation of SQLServerResultSet42 object
*
* @throws SQLException
*/
@Test
public void SQLServerResultSet42Test() throws SQLException {
String sql = "SELECT SUSER_SNAME()";
ResultSet rs = null;
try {
rs = connection.createStatement().executeQuery(sql);
if (1.8d <= javaVersion && 4 == major && 2 == minor) {
assertTrue(rs instanceof SQLServerResultSet42);
} else {
assertTrue(rs instanceof SQLServerResultSet);
}
} finally {
if (null != rs) {
rs.close();
}
}
}
Aggregations