FEAT: Adding conn.setencoding() API #172
Open
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.
Work Item / Issue Reference
Summary
This pull request adds support for configurable text encoding in the
Connection
class of themssql_python
package, allowing users to specify how text is encoded when interacting with the database. It introduces new methods for setting and retrieving encoding settings, provides robust validation and error handling, and includes comprehensive tests to ensure correct behavior across a wide range of scenarios.Encoding support and configuration:
setencoding
andgetencoding
methods to theConnection
class, allowing users to configure and retrieve text encoding and C type for SQL statements and parameters. The default encoding is set to'utf-16le'
withSQL_WCHAR
, and robust validation is performed for both encoding and ctype values.setencoding
, raisingProgrammingError
for invalid encodings or ctypes, andInterfaceError
if the connection is closed.Testing and validation:
Documentation and compatibility:
These changes make it easier and safer for users to control how text data is encoded and sent to the database, with clear error reporting and extensive test coverage to ensure reliability.