Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -568,89 +568,90 @@ public void testCallableStatementSetByAnnotatedArgs() throws SQLException {
}
}

@Test
@Tag(Constants.reqExternalSetup)
@Tag(Constants.xAzureSQLDB)
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xAzureSQLMI)
public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {
String table = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("serverList"));
try {

try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(table, stmt);
stmt.execute("CREATE TABLE " + table
+ " (serverName varchar(100),network varchar(100),serverStatus varchar(4000), id int, collation varchar(100), connectTimeout int, queryTimeout int)");
stmt.execute("INSERT " + table + " EXEC sp_helpserver");

ResultSet rs = stmt
.executeQuery("SELECT COUNT(*) FROM " + table + " WHERE serverName = N'" + linkedServer + "'");
rs.next();

if (rs.getInt(1) == 1) {
stmt.execute("EXEC sp_dropserver @server='" + linkedServer + "';");
}

stmt.execute("EXEC sp_addlinkedserver @server='" + linkedServer + "';");
stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @useself=false"
+ ", @rmtuser=N'" + linkedServerUser + "', @rmtpassword=N'" + linkedServerPassword + "'");
stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc', true;");
stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;");
}

SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(linkedServer);
ds.setUser(linkedServerUser);
ds.setPassword(linkedServerPassword);
ds.setEncrypt(false);
ds.setTrustServerCertificate(true);

try (Connection linkedServerConnection = ds.getConnection();
Statement stmt = linkedServerConnection.createStatement()) {
stmt.execute(
"create or alter procedure dbo.TestAdd(@Num1 int, @Num2 int, @Result int output) as begin set @Result = @Num1 + @Num2; end;");

stmt.execute("create or alter procedure dbo.TestReturn(@Num1 int) as select @Num1 return @Num1*3 ");
}

try (CallableStatement cstmt = connection
.prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) {
int sum = 11;
int param0 = 1;
int param1 = 10;
cstmt.setInt(1, param0);
cstmt.setInt(2, param1);
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.execute();
assertEquals(sum, cstmt.getInt(3));
}

try (CallableStatement cstmt = connection
.prepareCall("exec [" + linkedServer + "].master.dbo.TestAdd ?,?,?")) {
int sum = 11;
int param0 = 1;
int param1 = 10;
cstmt.setInt(1, param0);
cstmt.setInt(2, param1);
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.execute();
assertEquals(sum, cstmt.getInt(3));
}

try (CallableStatement cstmt = connection
.prepareCall("{? = call [" + linkedServer + "].master.dbo.TestReturn(?)}")) {
int expected = 15;
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(2, 5);
cstmt.execute();
assertEquals(expected, cstmt.getInt(1));
}
} finally {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(table, stmt);
}
}
}
// @Test
// @Tag(Constants.reqExternalSetup)
// @Tag(Constants.xAzureSQLDB)
// @Tag(Constants.xAzureSQLDW)
// @Tag(Constants.xAzureSQLMI)
// public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {
// String table = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("serverList"));
// try {

// try (Statement stmt = connection.createStatement()) {
// TestUtils.dropTableIfExists(table, stmt);
// stmt.execute("CREATE TABLE " + table
// + " (serverName varchar(100),network varchar(100),serverStatus varchar(4000), id int, collation varchar(100), connectTimeout int, queryTimeout int)");
// stmt.execute("INSERT " + table + " EXEC sp_helpserver");

// ResultSet rs = stmt
// .executeQuery("SELECT COUNT(*) FROM " + table + " WHERE serverName = N'" + linkedServer + "'");
// rs.next();

// if (rs.getInt(1) == 1) {
// // Drop all linked logins associated with the server
// stmt.execute("EXEC sp_dropserver @server='" + linkedServer + "', @droplogins='droplogins';");
// }

// stmt.execute("EXEC sp_addlinkedserver @server='" + linkedServer + "';");
// stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @useself=false"
// + ", @rmtuser=N'" + linkedServerUser + "', @rmtpassword=N'" + linkedServerPassword + "'");
// stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc', true;");
// stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;");
// }

// SQLServerDataSource ds = new SQLServerDataSource();
// ds.setServerName(linkedServer);
// ds.setUser(linkedServerUser);
// ds.setPassword(linkedServerPassword);
// ds.setEncrypt(false);
// ds.setTrustServerCertificate(true);

// try (Connection linkedServerConnection = ds.getConnection();
// Statement stmt = linkedServerConnection.createStatement()) {
// stmt.execute(
// "create or alter procedure dbo.TestAdd(@Num1 int, @Num2 int, @Result int output) as begin set @Result = @Num1 + @Num2; end;");

// stmt.execute("create or alter procedure dbo.TestReturn(@Num1 int) as select @Num1 return @Num1*3 ");
// }

// try (CallableStatement cstmt = connection
// .prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) {
// int sum = 11;
// int param0 = 1;
// int param1 = 10;
// cstmt.setInt(1, param0);
// cstmt.setInt(2, param1);
// cstmt.registerOutParameter(3, Types.INTEGER);
// cstmt.execute();
// assertEquals(sum, cstmt.getInt(3));
// }

// try (CallableStatement cstmt = connection
// .prepareCall("exec [" + linkedServer + "].master.dbo.TestAdd ?,?,?")) {
// int sum = 11;
// int param0 = 1;
// int param1 = 10;
// cstmt.setInt(1, param0);
// cstmt.setInt(2, param1);
// cstmt.registerOutParameter(3, Types.INTEGER);
// cstmt.execute();
// assertEquals(sum, cstmt.getInt(3));
// }

// try (CallableStatement cstmt = connection
// .prepareCall("{? = call [" + linkedServer + "].master.dbo.TestReturn(?)}")) {
// int expected = 15;
// cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
// cstmt.setInt(2, 5);
// cstmt.execute();
// assertEquals(expected, cstmt.getInt(1));
// }
// } finally {
// try (Statement stmt = connection.createStatement()) {
// TestUtils.dropTableIfExists(table, stmt);
// }
// }
// }

@Test
public void testTimestampStringConversion() throws SQLException {
Expand Down