Implementing variable character encoding for strings #46
shueybubbles
started this conversation in
Ideas
Replies: 2 comments
-
Supplement to the above! In addition to our constants for UTF16 and UTF8 encoding, we could support names of encoders from the charmap package To encode
There are also packages for encoding Asian characters. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This problem gets more important to solve with Always Encrypted coming online (see #129 ). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This discussion is to generate a proper interface to implement #40.
Problem statement
Go-mssqldb sends all
string
parameters asUTF16
strings, causing SQL Server to choose poor execution plans when the parameter type is avarchar
type.Solution options
A connection string parameter to control encoding of all strings
The property name could be
stringParameterEncoding
.Rather than a simple boolean value like JDBC uses, we'd define an enumeration.
Advantages
UTF8
collections by eliminating the client-side conversion of string runes (Go strings are UTF8 natively)Disadvantages
nvarchar
andvarchar
parameter types in the same connection.Define a new data type
To supplement the new connection string parameter, we can allow further customization by defining a new struct that acts like a variant for parameters. It can be rather simple:
We could make the typeXXX constants from types.go public.
When
stringParameterEncoding
is not set and the app passes an instance ofParameter
or of typestring
, go-mssqldb would behave as it does now and convert all string types (varchar, nvarchar) to UTF16 to send.When
stringParameterEncoding
is non-empty, go-mssqldb would use the specified value for the encoding ofstring
andParameter
instances whoseType
field specifies avarchar
type. If theType
field specifies annvarchar
type, go-mssqldb would encode it as UTF16.Advantages
sql
namespace.Disadvantages
Type
andValue
combinations could quickly get huge and difficult to define and document. EG, should we allow a byte array for every possible type for apps that want full control over what's being sent? How can an app writer easily discover the supported go types associated with each value ofParameter.Type
? Should we limit the scope to just strings?I'm interested to hear alternatives!
Beta Was this translation helpful? Give feedback.
All reactions