-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDBC - Clause Output and Exception #659
Comments
Hi @DVD27, we have been able to reproduce the issue and are currently working on a fix. It is worth noting that the Exception does not occur when the statement is executed, but when the ResultSet is accessed. If this doesn't sound right, please feel free to follow up on the issue and describe the desired behavior. |
Added error handling logic for special cases.
mssql-jdbc-issue659-jars.zip |
Now I have the error when I retrieve the resultset of my request but... when I try to do an other request before on the same connection I have this error :
For exemple I execute this request :
And after this :
|
Ok, it's possible I have do some error in my code, I will see later. if (rowCount == BEFORE_FIRST_ROW && columns.length == 1) {
lookForErrors();
} But this doesn't work at all when we use this procedure : CREATE OR ALTER PROCEDURE [dbo].proc_insert_masse_TEST @json NVARCHAR(MAX)
AS
BEGIN TRANSACTION
BEGIN TRY
SET NOCOUNT ON;
MERGE INTO TEST 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, inserted.FIELD1;
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; Because now we have 2 columns, and we could imagine have n columns. We have an other problem when we use also this proecdure : CREATE OR ALTER PROCEDURE [dbo].proc_insert_masse_TEST @json NVARCHAR(MAX)
AS
BEGIN TRANSACTION
BEGIN TRY
SET NOCOUNT ON;
MERGE INTO TEST AS target
USING (
SELECT *
FROM OPENJSON(@json)
WITH (
FIELD1 VARCHAR(255) 'strict $.FIELD1',
FIELD2 VARCHAR(255) 'lax $.FIELD2'
)
) AS src
ON (1 = 0)
WHEN NOT MATCHED THEN
INSERT (FIELD1, FIELD2)
VALUES (src.FIELD1, src.FIELD2)
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; If we execute this code : Finally, we think that should be preferable to have the error when we execute the statement but if I understand correctly your code it's seem difficult to do this. |
Hi @DVD27, the column/row check condition was a workaround to filter out bizarre table names which contained the error token. I see now that it's not the way to go and will get back to you in the near future with a more robust fix which will address these new cases. |
Hi @DVD27, I've updated the PR with changes. I'll attach jars for testing below. |
It's better. First, I doesn't have anymore this error : "The server failed to resume the transaction. Desc:4500000001." The only thing which can be strange it's to have the error during the retrieve of result. Thank you very much for you work and your speed anwser. |
* 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
* 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 microsoft#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
* 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
Closing issue since PR is merged and will be part of 6.5.1 preview release. |
* 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 * Change in preperation for 6.5.1 preview release * Removed SNAPSHOT from POM * Added missing link * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md
Driver version or jar name
Version 6.4
SQL Server version
Microsoft SQL Server 2016 (SP1-CU6) (KB4037354) - 13.0.4457.0 (X64)
Nov 8 2017 17:32:23
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)
Client operating system
Windows 7
Java/JVM version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Table schema
Problem description
The JDBC driver return an empty result when an error occured.
Expected behavior and actual behavior
When we use this procedure, we should have an error because the column FIELD2 cannot be null.
Repro code
-- Example 1 : should say that the column FIELD2 cannot be null
EXECUTE [dbo].proc_insert_masse_TEST N'[{"FIELD1" : "TEST"}]';
-- Example 2 : Should say that one field is absent
EXECUTE [dbo].proc_insert_masse_TEST N'[{}]';
Note : When we use this example in MSSQL Management tools we have the excepted result, this is why we think that is an issue.
The text was updated successfully, but these errors were encountered: