-
Notifications
You must be signed in to change notification settings - Fork 144
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
Resolve the issue of Chinese truncation during varchar insertion #195
Open
zhangyongding
wants to merge
5
commits into
alexbrainman:master
Choose a base branch
from
zhangyongding:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2012 The Go Authors. All rights reserved. | ||
|
||
// Use of this source code is governed by a BSD-style | ||
|
||
// license that can be found in the LICENSE file. | ||
|
||
package odbc | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"unsafe" | ||
) | ||
|
||
func TestBufferLen_IsNull(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
i interface{} | ||
l BufferLen | ||
want bool | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "IsNull ", i: int64(-1), want: true}, | ||
{name: "IsNull ", i: int32(-1), want: true}, | ||
{name: "IsNull ", i: int64(0x00000000ffffffff), want: true}, | ||
|
||
{name: "NotNull ", i: int32(1)}, | ||
{name: "NotNull ", i: int32(0x7fffffff)}, | ||
{name: "NotNull ", i: int64(0x1ffffffff)}, | ||
} | ||
for _, tt := range tests { | ||
switch i := tt.i.(type) { | ||
case int64: | ||
if unsafe.Sizeof(tt.l) != 8 { | ||
continue | ||
} | ||
tt.l = BufferLen(i) | ||
tt.name += fmt.Sprintf("0x%016x", uint64(i)) | ||
case int32: | ||
tt.l = BufferLen(i) | ||
tt.name += fmt.Sprintf("0x%08x", uint32(i)) | ||
} | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.l.IsNull(); got != tt.want { | ||
t.Errorf("BufferLen.IsNull() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that you added test as I requested here #182 (comment) , but I was asking for a different test. Your test does not prove that there is a problem with current code.
Perhaps if you adjust
TestMSSQLTypes
odbc/mssql_test.go
Line 704 in bcbcb68
TestMSSQLTextColumnParamTypes
odbc/mssql_test.go
Line 1271 in bcbcb68
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your test is wrong. For any Unicode values you should be using nvarchar instead of varchar type.
I just added this commit 25af894#diff-fa7d078a77ac77b6c32112f98183f4a221d30d0f460e50456b2ba995efaf0f23R675 with proper tests, and they all pass here.
I will not review your PR, because I don't believe it is required. Nothing is broken.
Alex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue does not occur in all databases, only some databases exist. I think setting the size to p.size is the correct approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a way for me to reproduce the issue, I will look at it again.
I disagree.