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
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion is to generate a proper interface to implement #40.
Problem statement
Go-mssqldb sends all
stringparameters asUTF16strings, causing SQL Server to choose poor execution plans when the parameter type is avarchartype.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
UTF8collections by eliminating the client-side conversion of string runes (Go strings are UTF8 natively)Disadvantages
nvarcharandvarcharparameter 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
stringParameterEncodingis not set and the app passes an instance ofParameteror of typestring, go-mssqldb would behave as it does now and convert all string types (varchar, nvarchar) to UTF16 to send.When
stringParameterEncodingis non-empty, go-mssqldb would use the specified value for the encoding ofstringandParameterinstances whoseTypefield specifies avarchartype. If theTypefield specifies annvarchartype, go-mssqldb would encode it as UTF16.Advantages
sqlnamespace.Disadvantages
TypeandValuecombinations 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