<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I got stuck with how we should handle strings in temporal database in respect to Python 2 and 3. Here is some relevant info from stack overflow [1]:</div><div><br></div><div>"If you insert a Python unicode object (or str object in 3.x), the Python sqlite3 library will automatically convert it to UTF-8. But if you insert a str object, it will just assume the string is UTF-8, because Python 2.x "str" doesn't know its encoding"<br></div><div><br></div><div>Regarding getting text from the database, there is some info here [2]:</div><div><br></div><div><div>"[text_factory] Using this attribute you can control what objects are returned for the TEXT data type. By default, this attribute is set to unicode and the sqlite3 module will return Unicode objects for TEXT. If you want to return bytestrings instead, you can set it to str.</div><div>...</div><div>You can also set it to any other callable that accepts a single bytestring parameter and returns the resulting object."</div></div><div><br></div><div>text_factory is currently set to 'str' so with Python 2 we get bytes, with Python 3 unicode.</div><div>I am not sure what do we want:</div><div>1. if we use bytes (input and output), do we use utf-8 encoding or locale specific? That could be problem if you move the database to different computer with different default encoding.</div><div>2. use unicode</div><div>3. ?</div><div><br></div><div>This is for sqlite, I haven't really considered the other db backend.</div><div><br></div><div>Any idea?</div><div><br></div><div>Anna</div><div><br></div><div><br></div><div>[1] <a href="https://stackoverflow.com/questions/2392732/sqlite-python-unicode-and-non-utf-data">https://stackoverflow.com/questions/2392732/sqlite-python-unicode-and-non-utf-data</a></div><div>[2] <a href="https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.text_factory">https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.text_factory</a></div></div></div></div></div></div>