Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"exception error: no function clause matching" when query arguments not matching with execute args #29

Open
jaras opened this issue Jun 28, 2024 · 1 comment

Comments

@jaras
Copy link

jaras commented Jun 28, 2024

When I run the query in the program attached below I get an exception that seems to originate from Erlang.

gleam run
  Compiling psqltest
   Compiled in 0.18s
    Running psqltest.main
exception error: no function clause matching 
                 gleam_pgo_ffi:convert_error(badarg) (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/gleam_pgo_ffi.erl, line 71)
  in function  gleam_pgo_ffi:query/3 (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/gleam_pgo_ffi.erl, line 68)
  in call from gleam@pgo:execute/4 (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/[email protected], line 193)
  in call from psqltest:main/0 (/Users/jaras/code/psqltest/build/dev/erlang/psqltest/_gleam_artefacts/psqltest.erl, line 25)

the issue I found was that token and expires was swapped in the sql statement, when those were swapped back it worked as expected.

import gleam/bit_array
import gleam/dynamic
import gleam/io
import gleam/pgo

pub fn main() {
  let db =
    pgo.connect(
      pgo.Config(
        ..pgo.default_config(),
        host: "localhost",
        database: "gleam_test",
        pool_size: 10,
      ),
    )

  let sql =
    "INSERT INTO sessions (user_id, token, expires) VALUES ($1, $2, $3) RETURNING id"

  let result =
    pgo.execute(
      sql,
      db,
      [
        pgo.int(3),
        pgo.timestamp(#(#(1, 2, 3), #(4, 5, 6))),
        pgo.bytea(bit_array.from_string("token")),
      ],
      dynamic.element(0, dynamic.int),
    )

  io.debug(result)
}
-- auto-generated definition
CREATE TABLE sessions
(
    id      bigserial
        PRIMARY KEY,
    token   bytea                                  NOT NULL
        UNIQUE,
    user_id integer                                NOT NULL,
    expires timestamp WITH TIME ZONE DEFAULT NOW() NOT NULL
);

ALTER TABLE sessions
    OWNER TO dkjanras;

CREATE INDEX sessions_token_index
    ON sessions (token);
@lpil
Copy link
Owner

lpil commented Jul 18, 2024

Thanks for the report! I've been digging into this and I think it's a bug with PGO. I've opened an issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants