Skip to content
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

Lost nvarchar parameters. #437

Closed
halfspawn opened this issue Aug 11, 2017 · 6 comments
Closed

Lost nvarchar parameters. #437

halfspawn opened this issue Aug 11, 2017 · 6 comments

Comments

@halfspawn
Copy link

Driver version or jar name

All versions (4.1, build from git source)

SQL Server version

All versions (2008 to 2016)

Client operating system

Windows 10, Centos 7.3

Java/JVM version

java version "1.8.0_141"

Table schema

Please tell us the table schema

Problem description

With sendStringParametersAsUnicode=true (default),
Use of SetNull(position, Types.VARCHAR) on a NVARCHAR output parameter of a stored procedure, bind a varchar variable --> lost of nvarchar character.

Expected behavior and actual behavior

If sendStringParametersAsUnicode=true, act as SetNull(position, Types.NVARCHAR)

Repro code

    String polishchar = "\u0143";
    m_cnx.createStatement().execute(
            "create procedure proc1(@p1 nvarchar(255), @p2 nvarchar(255) output) as select @p2=@p1 return 0");
    cs=m_cnx.prepareCall("{?=call proc1(?,?)}");           
    cs.registerOutParameter (1, Types.INTEGER);
    cs.setString(2,polishchar);
    cs.setNull(3, Types.VARCHAR);
    cs.registerOutParameter (3, Types.VARCHAR);        
    cs.execute();
    String p2=cs.getString(3);
    
    System.out.println("p1="+polishchar+" p2="+p2);

    cs=m_cnx.prepareCall("{?=call proc1(?,?)}");           
    cs.registerOutParameter (1, Types.INTEGER);
    cs.setString(2,polishchar);
    cs.setString(3, ""); 
    cs.registerOutParameter (3, Types.VARCHAR);        
    cs.execute();
    p2=cs.getString(3);
    
    System.out.println("p1="+polishchar+" p2="+p2);
@xiangyushawn
Copy link
Contributor

xiangyushawn commented Aug 11, 2017

Hello @halfspawn thank you very much for providing the repro code. It helps a lot.

I believe if the value is unicode, we need to use setNull(3, Types.NVARCHAR) instead of setNull(3, Types.VARCHAR), that will resolve the issue.

Thank you for the report.

@xiangyushawn
Copy link
Contributor

xiangyushawn commented Aug 11, 2017

Sorry @halfspawn, I think I misunderstood the issue. I didn't realize you meant Types.NVARCHAR and Types.VARCHAR should behave the same when sendStringParametersAsUnicode=true. I will continue investigation and keep you updated. Thank you!

@xiangyushawn
Copy link
Contributor

Hello @halfspawn , thanks for your patience, I am going to create a PR to fix this issue. The repro code you provided is very helpful! Do you mind if we add the repro code into our tests?

@xiangyushawn
Copy link
Contributor

hello @halfspawn PR #445 should be able to fix the issue. It would be great if we could add your repro code into the PR as one of the tests. Thank you :)

@halfspawn
Copy link
Author

halfspawn commented Aug 17, 2017 via email

@xiangyushawn
Copy link
Contributor

Hello @halfspawn, thank you very much for your permission. Your repro code has been added to the test now 😄

@ajlam ajlam closed this as completed Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants