nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.34k stars 1.46k forks source link

db_sqlite does not support FROM in UPDATE query #19627

Closed Tim-Hartmann closed 2 years ago

Tim-Hartmann commented 2 years ago

When the FROM keyword is used in an update query, a syntax error is produced at runtime.

Example

import std/db_sqlite

let db = open(":memory:", "", "", "")

db.exec(sql"""CREATE TABLE users (id INTEGER, account INTEGER, rich INTEGER)""")
db.exec(sql"""CREATE TABLE accounts (id INTEGER, balance INTEGER)""")

db.exec(sql"BEGIN")
db.exec(sql"INSERT INTO users (id, account, rich) VALUES (1, 1, 0)")
db.exec(sql"INSERT INTO accounts (id, balance) VALUES (1, 0)")
db.exec(sql"COMMIT")

db.exec(sql"BEGIN")
db.exec(sql"""UPDATE users SET rich = ? FROM accounts WHERE users.id = ? and accounts.id = users.account and accounts.balance > ?""", 1,1,0)
db.exec(sql"COMMIT")

Current Output

/home/user/dbtest.nim(16) dbtest
/home/user/.choosenim/toolchains/nim-#devel/lib/impure/db_sqlite.nim(271) exec
/home/user/.choosenim/toolchains/nim-#devel/lib/impure/db_sqlite.nim(198) dbError
Error: unhandled exception: near "FROM": syntax error [DbError]

Expected Output

none

Additional Information

The same query can be executed without issue in sqlitebrowser. When the FROM keyword and related conditions are removed, the nim program runs without errors.

Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-03-19
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 3e83d73f272afe8de85189da7d6d513916cc2efd
active boot switches: -d:release
Araq commented 2 years ago

We don't parse the SQL, the sqlite library does.