Skip to content

db.mysql does not allow retrieving of statement results, related to #17803 #17957

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

Open
einar-hjortdal opened this issue Apr 14, 2023 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@einar-hjortdal
Copy link
Contributor

Describe the bug

This issue blocks the use of prepared statements with MySQL. This effectively forces users to either use query or real_query, which is bad practice.

Unlike with the bare C API, invoking stmt.bind_result_buffer() (mysql_stmt_bind_result()) does not bind the result buffer of the statement. This method requires stmt.bind_res() to be invoked beforehand. This is problematic for several reasons:

  • stmt.bind_res() requires the parametersdataptr and num_fields which can be obtained with the method stmt.get_field_count(). This method is private.
  • These parameters are obtained in the orm implementation using the result obtained with the invocation of stmt.gen_metadata() (mysql_stmt_result_metadata()). Metadata should be optional, but most importantly, a lot of unsafe work is done to obtain these parameters.

Expected Behavior

stmt.bind_result_buffer() binds the result buffer of the statement

Current Behavior

Runtime memory access error

Reproduction Steps

Described here

Possible Solution

I can see 3 options:

  • stmt.bind_result_buffer() should not require invoking stmt.bind_res().
  • Otherwise, stmt.bind_res() should not require unobtainable parameters.
  • Otherwise, and least optimal, stmt.get_field_count() should be public. Users can do unsafe work themselves just to obtain query results. Sketchy and unfriendly.

Additional Information/Context

This has blocked me for months, nobody of the original contributors to the mysql module (particularly the parts contained in stmt.c.v) have stepped in when asked, nor do they seem active as contributors, they have likely abandoned V.

Currently active contributors to the orm module don't seem to know how the db.mysql module works.

V version

Current V version: V 0.3.3 2179db3, timestamp: 2023-04-14 14:42:11 +0300

Environment details (OS name and version, etc.)

V full version: V 0.3.3 ee4150f.2179db3
OS: linux, Linux version 5.14.0-162.23.1.el9_1.x86_64 (mockbuild@pp-el9) (gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2), GNU ld version 2.35.2-24.el9) #1 SMP PREEMPT_DYNAMIC Wed Apr 12 16:23:09 UTC 2023
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz

getwd: /home/coachonko
vexe: /home/coachonko/.local/lib64/v/v
vexe mtime: 2023-04-14 13:20:45

vroot: OK, value: /home/coachonko/.local/lib64/v
VMODULES: OK, value: /home/coachonko/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.31.1
Git vroot status: weekly.2023.15-18-g2179db37
.git/config present: true

CC version: cc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant