codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.62k stars 343 forks source link

[Bug] stdlib formatted query with `LIMIT` fails with `unexpected PPARAM` #1229

Closed ldej closed 1 year ago

ldej commented 2 years ago

What happened

I tried to use the standard library and made a SELECT * FROM ... LIMIT $1 query but it fails.

What you expected to happen

I expected it to succeed

How to reproduce it (as minimally and precisely as possible)

package main

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/codenotary/immudb/pkg/stdlib"
)

func main() {
    conn := "immudb://immudb:immudb@localhost:3322/defaultdb?sslmode=disable"

    client, err := sql.Open("immudb", conn)
    if err != nil {
        log.Fatal(err)
    }
    _, err = client.Exec(`CREATE TABLE IF NOT EXISTS test(test INTEGER, PRIMARY KEY test)`)
    if err != nil {
        log.Fatal(err)
    }

    limit := 1

    // This succeeds
    result := client.QueryRow(fmt.Sprintf("SELECT * FROM test LIMIT %d", limit))
    err = result.Err()
    if err != nil {
        log.Fatal(err)
    }

    // This fails with `rpc error: code = Unknown desc = syntax error: unexpected PPARAM, expecting NUMBER at position 27`
    result = client.QueryRow("SELECT * FROM test LIMIT $1", limit)
    err = result.Err()
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("%+v", result)
}

Environment

$ immudb version
immudb 1.2.4
Commit  : 2dcaf09c7d2b76b099a977b8654ca921dad2524e
Built at: Thu, 28 Apr 2022 12:03:31 IST

Go library version: github.com/codenotary/immudb v1.2.4

Additional info (any other context about the problem)

jeroiraz commented 2 years ago

thanks @ldej.

Just checked it, LIMIT value is expecting a numeric value, so it's not currently possible to use a parameter nor an expression.

We'll solve it quite soon