Skip to content

Commit

Permalink
Handle cases when jTDS returns DataTruncation, fixes TestTinyInt
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Kasko <[email protected]>
  • Loading branch information
staticlibs committed May 5, 2024
1 parent 2d6d288 commit fe7419a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
28 changes: 14 additions & 14 deletions test/JDBC/expected/jtds-TestSimpleErrors.out
Original file line number Diff line number Diff line change
Expand Up @@ -3665,9 +3665,9 @@ begin tran
GO
DECLARE @a tinyint = 1000;
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

declare @err int = @@error; if @err = 0 select 0 else select 1;
GO
Expand Down Expand Up @@ -3727,9 +3727,9 @@ begin tran
GO
DECLARE @a tinyint = 1000;
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

declare @err int = @@error; if @err = 0 select 0 else select 1;
GO
Expand Down Expand Up @@ -3794,9 +3794,9 @@ end
GO
exec simpleErrorProc2
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

~~ROW COUNT: 1~~

Expand Down Expand Up @@ -3858,9 +3858,9 @@ GO
~~START~~
int
1
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

declare @err int = @@error; if @err = 0 select 0 else select 1;
GO
Expand Down Expand Up @@ -3913,9 +3913,9 @@ end
GO
exec simpleErrorProc2
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

~~ROW COUNT: 1~~

Expand Down Expand Up @@ -3977,9 +3977,9 @@ end
GO
exec simpleErrorProc2
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

~~ROW COUNT: 1~~

Expand Down Expand Up @@ -4026,9 +4026,9 @@ INSERT INTO simpleErrorTable VALUES ('Apple', N'red', 1, 'Delhi', N'Sad😞', '
DECLARE @a tinyint = 1000;
INSERT INTO simpleErrorTable(a, b, c, e, f, g) VALUES ('Orange', NULL, 3, N'Happy😀', '1900-02-28 23:59:59.989', 342.5);
GO
~~ERROR (Code: 0)~~
~~ERROR (Code: 220)~~

~~ERROR (Message: Data truncation)~~
~~ERROR (Message: value for domain tinyint violates check constraint "tinyint_check")~~

~~ROW COUNT: 1~~

Expand Down
3 changes: 1 addition & 2 deletions test/JDBC/jtds_jdbc_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
# datatypes
TestInt
TestSmallInt
# Failure: Message: Data truncation
# TestTinyInt
TestTinyInt
TestBigInt
TestBIT
# Failure: discrepancy in jTDS behaviour between MSSQL and Babelfish
Expand Down
7 changes: 7 additions & 0 deletions test/JDBC/src/main/java/com/sqlsamples/HandleException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.BufferedWriter;
import java.io.IOException;
import java.sql.DataTruncation;
import java.sql.SQLException;

import org.postgresql.util.PSQLException;
Expand All @@ -19,6 +20,12 @@ public class HandleException {
static void handleSQLExceptionWithFile(SQLException e, BufferedWriter bw, Logger logger) {
try {
if (outputErrorCode) {

// DataTruncation is used by jTDS for error code 220
if (e instanceof DataTruncation && e.getNextException() != null) {
e = e.getNextException();
}

bw.write("~~ERROR (Code: " + e.getErrorCode() + ")~~");
bw.newLine();
bw.newLine();
Expand Down

0 comments on commit fe7419a

Please sign in to comment.