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

Correctly calculate string length based on encoded length #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atf1206
Copy link

@atf1206 atf1206 commented Apr 9, 2023

The current implementation calculates the length of the string to send by simply using len() on the string. However, the correct calculation (that kdb expects) is the length of the encoded string.

In latin-1 and ascii, these two are the same. However for extended characters such as those in the utf-8 char-set, a single character in a python string may be 2 or more encoded characters. Since QConnection now supports passing alternate encoding parameters, e.g. utf-8, this should be supported here as well -- otherwise qPython reports an error when trying to send extended chars.

E.g.:
qcon = qpython.qconnection.QConnection(host = Host, port = Port, username = User, password = Pass, encoding = 'UTF-8')

This PR replicates the one from exxeleron#77

In addition, this change has been in use in sublime-q since 2020.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: atf1206 / name: Andrew (ac89e65)

@alvin-c-shih
Copy link

Would be good to have unit tests for this.

Seems to cover the general case, but I think there's an edge case for a string with a single encoded character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants