libsql / sqld

LibSQL with extended capabilities like HTTP protocol, replication, and more.
https://libsql.org
901 stars 38 forks source link

Are pragma statements supported in hrana? #391

Closed avinassh closed 1 year ago

avinassh commented 1 year ago

I was playing with Python client and I learned that pragma statements are not working. Same with Go client or the Turso CLI:

_, err = db.ExecContext(ctx, "PRAGMA foreign_keys = OFF")
client.execute("PRAGMA foreign_keys = OFF")

I got the error:

SQL_PARSE_ERROR: SQL string could not be parsed: unsupported statement

# or in Turso CLI:
Error: Failed to execute SQL statement: PRAGMA journal_mode=wal;
unsupported statement
haaawk commented 1 year ago

What version of sqld are you using? foreing_keys should be supported.

haaawk commented 1 year ago

journal_mode is not supported at the moment and probably won't be in the near future.

avinassh commented 1 year ago

What version of sqld are you using? foreing_keys should be supported.

oops, I should have mentioned I am using Turso, not sqld

haaawk commented 1 year ago

What version of sqld are you using? foreing_keys should be supported.

oops, I should have mentioned I am using Turso, not sqld

Try creating a new db of db upgrade you old one. foreing_keys should work. If they don't then it's a bug.

avinassh commented 1 year ago

I upgraded my db and also, created a new one. It didn't work in both cases. I am using Turso CLI (v0.56.0 -- the latest on homebrew)

$ turso db create mario

$ turso db show mario
Name:           mario
URL:            libsql://mario-avinassh.turso.io
ID:             ccd12a52-f0c1-11ed-8b81-668771a97ddc
Locations:      maa

Database Instances:
NAME                        TYPE        LOCATION     VERSION                                                   URL
enabling-american-eagle     primary     maa          The `Basic` HTTP authentication scheme is not allowed     libsql://3d8dd64be49789-mario-avinassh.turso.io

$ turso db shell mario
Connected to mario at libsql://mario-avinassh.turso.io

Welcome to Turso SQL shell!

Type ".quit" to exit the shell, ".tables" to list all tables, and ".schema" to show table schemas.

→  PRAGMA foreign_keys = OFF;
Error: Failed to execute SQL statement: PRAGMA foreign_keys = OFF;
unsupported statement

(not sure why the HTTP auth error)

Also I just realised I am asking Turso specific error here. Please let me know should I close this and ask in discord support forums

CodingDoug commented 1 year ago

Looks like the problem is in sqld. The query analyzer has a typo in the names of the pragmas it allows:

https://github.com/libsql/sqld/blob/de5868f78dc135fb7ff10c5889d0b1a40afefab7/sqld/src/query_analysis.rs#L108-L109C1

It should be "foreign_keys".

haaawk commented 1 year ago

Thanks @CodingDoug. Great catch. And thanks @avinassh for finding that out.