Skip to content

Commit

Permalink
Removed Exception Test (#669)
Browse files Browse the repository at this point in the history
* Added more information to error messages

To help debug an irreproducable/random mismatch error if it occurs in the future.

* Fix for the issue when using setMaxRows() with SHOWPLAN ON (#666)

* Dont throw exception for colmetadata token

* Adding a comment

* Update comment

* Adding a warning message

* remove ignoreLengthPrefixedToken

* Fix for uncaught/unhandled exception (#664)

* Added more information to error messages

To help debug an irreproducable/random mismatch error if it occurs in the future.

* Revert "Added information to error message"

This reverts commit 25301e6.

* Fix for #659

Added error handling logic for special cases.

* Read message length

Read the message length instead of reading until terminating character

* Unsigned byte update

Message length is an unsigned byte, converting before using.

* Removed clunky hex conversions

convert the byte straight to an int and use existing constants instead of making new ones

* Narrowed trigger conditions

fixed an issue where column names who had the hex token 'AA' would cause an error to be thrown.

* Spacing fixes

* Added test case

* spacing adjustment

* Edited test drop procedures

Changed IF EXISTS DROP commands to be compatible with sql server 2008

* github spacing misalignment fixes

* Changed test condition

now only runs on compatible database or higher

* Removed error check

Removed a previous implementation in favor of one that changes the TDS parser

* tdsreader change

* removing test for now

* enabled tests

* github spacing fix

* removed array import

* removed "arrays" instead of "array"

* spacing changes

* Use Socket instead of SocketChannel when multiSubnetFailover=true (#662)

* Upped SQL Server requirement to 2017

* Removing Exception Test

Implement a more generic and compatible test in the future

* Removed imports

Used in removed test
  • Loading branch information
rene-ye committed Apr 6, 2018
1 parent 07e391e commit 501f2b8
Showing 1 changed file with 0 additions and 57 deletions.
Expand Up @@ -7,24 +7,19 @@
*/
package com.microsoft.sqlserver.jdbc.exception;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.UnsupportedEncodingException;
import java.net.SocketTimeoutException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord;
import com.microsoft.sqlserver.jdbc.SQLServerConnection;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.Utils;

Expand Down Expand Up @@ -98,56 +93,4 @@ private void createWaitForDelayPreocedure(SQLServerConnection conn) throws SQLEx
String sql = "CREATE PROCEDURE " + waitForDelaySPName + " AS" + " BEGIN" + " WAITFOR DELAY '00:00:" + waitForDelaySeconds + "';" + " END";
conn.createStatement().execute(sql);
}

@Test
public void testResultSetErrorSearch() throws Exception {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);

String dropTable_sql = "DROP TABLE IF EXISTS TEST659;";
String dropProc_sql = "DROP PROCEDURE IF EXISTS proc_insert_masse_TEST;";
String createTable_sql = "CREATE TABLE TEST659 (ID INT IDENTITY NOT NULL," +
"FIELD1 VARCHAR (255) NOT NULL," +
"FIELD2 VARCHAR (255) NOT NULL);";
String createProc_sql = "CREATE PROCEDURE proc_insert_masse_TEST @json NVARCHAR(MAX) "
+ "AS "
+ "BEGIN TRANSACTION "
+ "BEGIN TRY "
+ "SET NOCOUNT ON; "
+ "MERGE INTO TEST659 AS target "
+ "USING "
+ "(SELECT * FROM OPENJSON(@json) "
+ "WITH (FIELD1 VARCHAR(255) 'strict $.FIELD1')) "
+ "AS src "
+ "ON (1 = 0) "
+ "WHEN NOT MATCHED THEN "
+ "INSERT (FIELD1) VALUES (src.FIELD1) "
+ "OUTPUT inserted.ID; "
+ "COMMIT TRANSACTION; "
+ "END TRY "
+ "BEGIN CATCH "
+ "DECLARE @errorMessage NVARCHAR(4000) = ERROR_MESSAGE(); "
+ "ROLLBACK TRANSACTION; "
+ "RAISERROR('Error occured during the insert: %s', 16, 1, @errorMessage); "
+ "END CATCH;";
String proc_sql = "EXECUTE [dbo].proc_insert_masse_TEST N'[{\"FIELD1\" : \"TEST\"}]';";

Connection conn = ds.getConnection();
if (conn.getMetaData().getDatabaseMajorVersion() >= 13)
{
Statement stmt = conn.createStatement();
stmt.execute(dropTable_sql);
stmt.execute(createTable_sql);
stmt.execute(dropProc_sql);
stmt.execute(createProc_sql);
stmt.execute(proc_sql);
ResultSet rs = stmt.getResultSet();
try {
rs.next();
fail("No exceptions caught.");
} catch (SQLException e) {
assertTrue(e.getMessage().contains("Error occured during the insert:"), "Unexpected Error Message: " + e.getMessage());
}
}
}
}

0 comments on commit 501f2b8

Please sign in to comment.