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

Fix for issue when attempting to insert an empty or null value on encrypted column #632

Merged
merged 7 commits into from
Mar 7, 2018
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ private void setTypeDefinition(DTV dtv) {
* specific type info, otherwise generic type info can be used as before.
*/
if (0 == valueLength) {
param.typeDefinition = "varbinary";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varbinary(1)";
valueLength++;
}
else {
param.typeDefinition = "varbinary(" + valueLength + ")";
Expand Down Expand Up @@ -721,7 +723,9 @@ private void setTypeDefinition(DTV dtv) {
* specific type info, otherwise generic type info can be used as before.
*/
if (0 == valueLength) {
param.typeDefinition = "varchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
}
else {
param.typeDefinition = "varchar(" + valueLength + ")";
Expand All @@ -745,7 +749,9 @@ private void setTypeDefinition(DTV dtv) {
if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
|| (jdbcTypeSetByUser == JDBCType.LONGVARCHAR))) {
if (0 == valueLength) {
param.typeDefinition = "varchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
}
else if (DataTypes.SHORT_VARTYPE_MAX_BYTES < valueLength) {
param.typeDefinition = VARCHAR_MAX;
Expand All @@ -761,7 +767,9 @@ else if (DataTypes.SHORT_VARTYPE_MAX_BYTES < valueLength) {
else if ((null != jdbcTypeSetByUser)
&& (jdbcTypeSetByUser == JDBCType.NVARCHAR || jdbcTypeSetByUser == JDBCType.LONGNVARCHAR)) {
if (0 == valueLength) {
param.typeDefinition = "nvarchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
}
else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
param.typeDefinition = NVARCHAR_MAX;
Expand All @@ -776,7 +784,9 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
}
else { // used if setNull() is called with java.sql.Types.NCHAR
if (0 == valueLength) {
param.typeDefinition = "nvarchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
}
else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
Expand Down Expand Up @@ -813,7 +823,9 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
|| (JDBCType.LONGVARCHAR == jdbcTypeSetByUser))) {
if (0 == valueLength) {
param.typeDefinition = "varchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
}
else {
param.typeDefinition = "varchar(" + valueLength + ")";
Expand All @@ -830,7 +842,9 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR) || (jdbcTypeSetByUser == JDBCType.NCHAR)
|| (JDBCType.LONGNVARCHAR == jdbcTypeSetByUser))) {
if (0 == valueLength) {
param.typeDefinition = "nvarchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
}
else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
Expand All @@ -846,7 +860,9 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
}
else { // used if setNull() is called with java.sql.Types.NCHAR
if (0 == valueLength) {
param.typeDefinition = "nvarchar";
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
}
else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
Expand Down