go-libsql
go-libsql copied to clipboard
Exec method does not support queries that return results
Some sqlite pragmas return a value. For example, mmap_size
(running in sqlite shell):
sqlite> pragma mmap_size=1024;
1024
The libsql driver's Exec
method fails with an "Execute returned rows" for such pragmas. In fact, it fails for any query that returns a value (such as select 42
).
I would argue that this is not an expected behavior. It's perfectly normal for an Exec
query to return a value. Other drivers (such as mattn/go-sqlite3
and modernc.org/sqlite
) allow this.
Code to reproduce:
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/tursodatabase/go-libsql"
)
func main() {
db, err := sql.Open("libsql", "file:data.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// You can replace the query with `select 42` to get the same error.
res, err := db.Exec(`pragma mmap_size=1024`)
fmt.Println("res", res)
fmt.Println("err", err)
}
Result:
res <nil>
err failed to execute query pragma mmap_size=1024
error code = 2: Error executing statement: Execute returned rows