Sqlite QUOTE function is not supported
nareshkbohra opened this issue · comments
I am trying to setup django with client but as django uses QUOTE function, this is being interpreted as invalid column type.
Small repro is here:
import libsql_experimental as libsql
conn = libsql.connect('test.db', sync_url='http://db.local:8080', auth_token='1234')
cursor = conn.cursor()
# Drop user table if it exists
cursor.execute("DROP TABLE IF EXISTS user;")
cursor.execute("CREATE TABLE user (name TEXT, address TEXT);")
# Insert data into user TABLE
cursor.execute("INSERT INTO user VALUES ('John', 'Doe');")
# Select name from user table using QUOTE function
res = cursor.execute("SELECT QUOTE(name) FROM user;")
for i in res.fetchall():
print(i)
Same thing work in sqlite3:
$ sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE user (name TEXT, address TEXT);
sqlite> INSERT INTO user VALUES ('John', 'Doe');
sqlite> SELECT QUOTE(name) FROM user;
'John'
Same thing do work if you are running query directly on connection.
Edit: This is also failing, had an issue with script.
The issue is not that sqlite quote functions aren't supported. This is evident from the fact that cursor.execute("SELECT QUOTE(name) FROM user;")
is not failing. The issue is with the fetchall
function. Specifically, fetchall tries to deserialize each value of a row based on the column_type
seen in the response. The problem with that is, according to HRANA protocol, column_type
will be null, if the column is not a table column but the result of some expression (possibly on the table column).
The fix for this is rather than using the column_type, get the libsql::Value
and deserialize directly based on it's type.
Also worth noting is that, this issue is only seen in case of remote db connections and not with in-memory or local replica connections.