Recently I switched from pymysql to singlestoredb and found that integer column values returned from singlestoredb is corrupted when followed by a string column of a certain length.
I added a minimal reproductive as a test case.
Without this change, the test case fails as follows:
def test_long_string(self):
string = 'a' * 48
self.cur.execute(f"SELECT 1 AS column_1, '{string}' AS column_2")
> self.assertEqual((1, string), self.cur.fetchone())
E AssertionError: Tuples differ: (1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') != (10, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
E
E First differing element 0:
E 1
E 10
E
E - (1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
E + (10, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
E ? +
The root cause is a misuse of stortoll/stotoull, which reads a consecutive numeric characters, so if a length-encoded string follows and the encoded length can be interpreted as numeric characters, they are read as part of integer value incorrectly. (in the test case, 48 == '0 'in ASCII)
By creating a substring with a provided length, the integer value can be read correctly.
Recently I switched from pymysql to singlestoredb and found that integer column values returned from singlestoredb is corrupted when followed by a string column of a certain length.
I added a minimal reproductive as a test case. Without this change, the test case fails as follows:
The root cause is a misuse of
stortoll
/stotoull
, which reads a consecutive numeric characters, so if a length-encoded string follows and the encoded length can be interpreted as numeric characters, they are read as part of integer value incorrectly. (in the test case, 48 == '0 'in ASCII)By creating a substring with a provided length, the integer value can be read correctly.