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

MariaDB driver should not use prepared statement protocol when oneshot is true #42

Open
joseferben opened this issue Jun 8, 2020 · 5 comments

Comments

@joseferben
Copy link

joseferben commented Jun 8, 2020

First of all, thanks for this great project!

I am running into an issue while running migrations for following query on MariaDB 10.1.41:

let create_uuid_of = connection => {
  module Connection = (val connection: Caqti_lwt.CONNECTION);
  let request =
    Caqti_request.exec(
      ~oneshot=true,
      Caqti_type.unit,
      "
CREATE OR REPLACE
  FUNCTION uuid_of(uuid BINARY(16))
  RETURNS VARCHAR(36)
  RETURN LOWER(CONCAT(
  SUBSTR(HEX(uuid), 1, 8), '-',
  SUBSTR(HEX(uuid), 9, 4), '-',
  SUBSTR(HEX(uuid), 13, 4), '-',
  SUBSTR(HEX(uuid), 17, 4), '-',
  SUBSTR(HEX(uuid), 21)
));
",
    );
  Connection.exec(request, ());
};
Error 1295, This command is not supported in the prepared statement protocol yet

I tried to track down the issue, but I am not sure what the underlying MariaDB library is doing.

In caqti_driver_mariadb.ml:

...
      (match Caqti_request.query_id req with
       | None ->
          let templ = Caqti_request.query req driver_info in
          let query = linear_query_string templ in
          Mdb.prepare db query >>=
...

Even though the query id is None (due to oneshot being true), Mdb.prepare is called. I assume this is using the prepared statement protocol?

@joseferben joseferben changed the title MariaDB driver should not use prepared statement protocol when oneshot = true MariaDB driver should not use prepared statement protocol when oneshot is true Jun 8, 2020
@paurkedal
Copy link
Owner

I didn't realise there were such restrictions. Yes, None means oneshot here, which is implemented in the Caqti driver by creating a prepared statement which is closed after usage. The reason is that the mariadb client library only supports prepared queries. According to the API docs for the Mariadb module:

These bindings are restricted to MariaDB's prepared statement APIs, as they provide support for typed query parameters and results.

which seems reasonable, though in light of the limitations of the prepared statements, it would be good to find a solution for non-prepared statements.

CC @andrenth

@andrenth
Copy link

andrenth commented Jun 9, 2020

Hello

I don't currently have the resources to work on supporting non-prepared statements, but I would gladly accept a PR implementing them.

@paurkedal
Copy link
Owner

I haven't had time either yet, but I hope to make a PR soon, though probably not the coming two weeks.

@apeschar
Copy link

apeschar commented Jul 2, 2022

MariaDB supports all syntax in prepared statements from version 10.6.2 (docs), making this issue irrelevant.

@paurkedal
Copy link
Owner

It may be too early to expect people to upgrade their database servers. At least Ubuntu 20.04 LTS and RHEL 7 and 8, which are still under support, distribute older versions.

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

4 participants