Skip to content

Commit

Permalink
fixed formatting (#2378)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird committed Apr 3, 2024
1 parent 51ca5a0 commit c898a27
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4807,8 +4807,8 @@ void writeRPCUUID(String sName, UUID uuidValue, boolean bOut) throws SQLServerEx
writeByte((byte) 0);

} else {
writeByte((byte) 0x10); // maximum length = 16
writeByte((byte) 0x10); // length = 16
writeByte((byte) 0x10); // maximum length = 16
writeByte((byte) 0x10); // length = 16

byte[] val = Util.asGuidByteArray(uuidValue);
writeBytes(val, 0, val.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,10 @@ public void setAccessTokenCallbackClass(String accessTokenCallbackClass) {
public ISQLServerMessageHandler getServerMessageHandler() {
return wrappedConnection.getServerMessageHandler();
}

@Override
public ISQLServerMessageHandler setServerMessageHandler(ISQLServerMessageHandler messageHandler) {
return wrappedConnection.setServerMessageHandler(messageHandler);
return wrappedConnection.setServerMessageHandler(messageHandler);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ static String getErrString(String errCode) {
}

public SQLServerException(SQLServerError sqlServerError) {
super(sqlServerError.getErrorMessage(),
generateStateCode(null, sqlServerError.getErrorNumber(), sqlServerError.getErrorState()),
sqlServerError.getErrorNumber(),
null);
super(sqlServerError.getErrorMessage(),
generateStateCode(null, sqlServerError.getErrorNumber(), sqlServerError.getErrorState()),
sqlServerError.getErrorNumber(), null);

this.sqlServerError = sqlServerError;
}
}

/**
* Constructs a new SQLServerException.
Expand Down Expand Up @@ -278,10 +277,10 @@ static void makeFromDatabaseError(SQLServerConnection con, Object obj, String er
String state2 = generateStateCode(con, srvError.getErrorNumber(), srvError.getErrorState());

SQLServerException chainException = new SQLServerException(obj,
SQLServerException.checkAndAppendClientConnId(srvError.getErrorMessage(), con),
state2, srvError, bStack);
SQLServerException.checkAndAppendClientConnId(srvError.getErrorMessage(), con), state2,
srvError, bStack);
chainException.setDriverErrorCode(DRIVER_ERROR_FROM_DATABASE);

theException.setNextException(chainException);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,32 +1707,32 @@ boolean onInfo(TDSReader tdsReader) throws SQLServerException {
if (16954 == infoMessage.msg.getErrorNumber())
executedSqlDirectly = true;


// Call the message handler to see what that think of the message
// - discard
// - upgrade to Error
// - or simply pass on
ISQLServerMessageHandler msgHandler = ((ISQLServerConnection)getConnection()).getServerMessageHandler();
ISQLServerMessageHandler msgHandler = ((ISQLServerConnection) getConnection())
.getServerMessageHandler();
if (msgHandler != null) {

// Let the message handler decide if the error should be unchanged, up/down-graded or ignored
ISQLServerMessage srvMessage = msgHandler.messageHandler(infoMessage);

// Ignored
if (srvMessage == null) {
return true;
return true;
}

// The message handler changed it to an "Error Message"
if (srvMessage.isErrorMessage()) {
// Set/Add the error message to the "super"
addDatabaseError( (SQLServerError)srvMessage );
addDatabaseError((SQLServerError) srvMessage);
return true;
}

// Still a "info message", just set infoMessage and the code in the below section will create the Warnings
if (srvMessage.isInfoMessage()) {
infoMessage = (SQLServerInfoMessage)srvMessage;
infoMessage = (SQLServerInfoMessage) srvMessage;
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@

import java.sql.SQLWarning;


/**
* Holds information about SQL Server messages that is considered as Informational Messages (normally if SQL Server Severity is at 10)
* <p>
* Instead of just holding the SQL Server message (like a normal SQLWarning, it also holds all the
* Instead of just holding the SQL Server message (like a normal SQLWarning, it also holds all the
* SQL Servers extended information, like: ErrorSeverity, ServerName, ProcName etc
* <p>
* This enables client to print out extra information about the message.<br>
* Like: In what procedure was the message produced.
*/
public class SQLServerWarning
extends SQLWarning
{
public class SQLServerWarning extends SQLWarning {
private static final long serialVersionUID = -5212432397705929142L;

/** SQL server error */
private SQLServerError sqlServerError;

/*
* Create a SQLWarning from an SQLServerError object
*/
public SQLServerWarning(SQLServerError sqlServerError) {
super(sqlServerError.getErrorMessage(),
SQLServerException.generateStateCode(null, sqlServerError.getErrorNumber(), sqlServerError.getErrorState()),
sqlServerError.getErrorNumber(),
null);
super(sqlServerError.getErrorMessage(), SQLServerException.generateStateCode(null,
sqlServerError.getErrorNumber(), sqlServerError.getErrorState()), sqlServerError.getErrorNumber(),
null);

this.sqlServerError = sqlServerError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.transaction.xa.Xid;



/**
* Implements Transaction id used to recover transactions.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ protected Object[][] getContents() {
{"R_invalidClientSecret", "AADSTS7000215: Invalid client secret provided"},
{"R_invalidCertFields",
"Error reading certificate, please verify the location of the certificate.signed fields invalid"},
{"R_invalidAADAuth",
"Failed to authenticate the user {0} in Active Directory (Authentication={1})"},
{"R_invalidAADAuth", "Failed to authenticate the user {0} in Active Directory (Authentication={1})"},
{"R_failedValidate", "failed to validate values in $0} "}, {"R_tableNotDropped", "table not dropped. "},
{"R_connectionReset", "Connection reset"}, {"R_unknownException", "Unknown exception"},
{"R_deadConnection", "Dead connection should be invalid"},
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,16 @@ public static void dropTableIfExists(String tableName, java.sql.Statement stmt)
dropObjectIfExists(tableName, "U", stmt);
}

public static void dropTableWithSchemaIfExists(String tableNameWithSchema, java.sql.Statement stmt) throws SQLException {
stmt.execute("IF OBJECT_ID('" + tableNameWithSchema + "', 'U') IS NOT NULL DROP TABLE " + tableNameWithSchema + ";");
public static void dropTableWithSchemaIfExists(String tableNameWithSchema,
java.sql.Statement stmt) throws SQLException {
stmt.execute(
"IF OBJECT_ID('" + tableNameWithSchema + "', 'U') IS NOT NULL DROP TABLE " + tableNameWithSchema + ";");
}


public static void dropProcedureWithSchemaIfExists(String procedureWithSchema, java.sql.Statement stmt) throws SQLException {
stmt.execute("IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'"
+ procedureWithSchema + "') AND type in (N'P', N'PC')) DROP PROCEDURE " + procedureWithSchema + ";");
public static void dropProcedureWithSchemaIfExists(String procedureWithSchema,
java.sql.Statement stmt) throws SQLException {
stmt.execute("IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" + procedureWithSchema
+ "') AND type in (N'P', N'PC')) DROP PROCEDURE " + procedureWithSchema + ";");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public void testEscapeColumnDelimitersCSV() throws Exception {
expectedEscaped[8] = new String[] {"1997", "Ford", "E350", "Super@ \"luxurious\" truck", ""};
expectedEscaped[9] = new String[] {"1997", "Ford", "E350", "E63", ""};
expectedEscaped[10] = new String[] {"1997", "Ford", "E350", " Super luxurious truck ", ""};
expectedEscaped[11] = new String[] {"1997", "F\r\no\r\nr\r\nd", "E350", "\"Super\" \"luxurious\" \"truck\"", ""};
expectedEscaped[11] = new String[] {"1997", "F\r\no\r\nr\r\nd", "E350", "\"Super\" \"luxurious\" \"truck\"",
""};

try (Connection con = getConnection(); Statement stmt = con.createStatement();
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,18 +1160,21 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {

try (Statement stmt = connection.createStatement()) {
stmt.execute("IF OBJECT_ID(N'" + table + "') IS NOT NULL DROP TABLE " + table);
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("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 + "'");
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 + "', @rmtuser=N'" + remoteUser + "', @rmtpassword=N'" + remotePassword + "'");
stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @rmtuser=N'" + remoteUser
+ "', @rmtpassword=N'" + remotePassword + "'");
stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc', true;");
stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;");
}
Expand All @@ -1183,11 +1186,14 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {
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;");
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;");
}

try (CallableStatement cstmt = connection.prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) {
try (CallableStatement cstmt = connection
.prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) {
int sum = 11;
int param0 = 1;
int param1 = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,15 +1002,14 @@ public void shouldEscapeSchemaName() throws SQLException {
try (Statement stmt = connection.createStatement()) {
stmt.execute("CREATE SCHEMA " + schema);
stmt.execute("CREATE TABLE " + tableNameWithSchema + " (id UNIQUEIDENTIFIER, name NVARCHAR(400));");
stmt.execute("CREATE PROCEDURE " + sprocWithSchema + "(@id UNIQUEIDENTIFIER, @name VARCHAR(400)) AS " +
"BEGIN SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION UPDATE "
stmt.execute("CREATE PROCEDURE " + sprocWithSchema + "(@id UNIQUEIDENTIFIER, @name VARCHAR(400)) AS "
+ "BEGIN SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION UPDATE "
+ tableNameWithSchema + " SET name = @name WHERE id = @id COMMIT END");
}

try (Connection con = getConnection()) {
DatabaseMetaData md = con.getMetaData();
try (ResultSet procedures = md.getProcedures(
null, escapedSchema, "updateresource")) {
try (ResultSet procedures = md.getProcedures(null, escapedSchema, "updateresource")) {
if (!procedures.next()) {
fail("Escaped schema pattern did not succeed. No results found.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.microsoft.sqlserver.testframework.Constants;


/*
* This test is for testing the serialisation of String as microsoft.sql.Types.GUID
*/
Expand All @@ -49,8 +51,7 @@ public void testGuid() throws Exception {
// Create the test table
TestUtils.dropTableIfExists(escapedTableName, stmt);

String query = "create table " + escapedTableName
+ " (uuid uniqueidentifier, id int IDENTITY primary key)";
String query = "create table " + escapedTableName + " (uuid uniqueidentifier, id int IDENTITY primary key)";
stmt.executeUpdate(query);

UUID uuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ public void testPreparedStatementShouldNotUseWrongHandleAfterReconnect() throws
}
}


@Test
public void testUnprocessedResponseCountSuccessfulIdleConnectionRecovery() throws SQLException {
try (SQLServerConnection con = (SQLServerConnection) ResiliencyUtils.getConnection(connectionString)) {
Expand Down

0 comments on commit c898a27

Please sign in to comment.