MySQL.jl icon indicating copy to clipboard operation
MySQL.jl copied to clipboard

Named Parameters Does not Work for prepare() function

Open mattcbro opened this issue 2 years ago • 0 comments

So I have a simple test table that looks like this:

+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | YES  |     | <null>  |       |
| pname | varchar(255) | YES  |     | <null>  |       |
+-------+--------------+------+-----+---------+-------+

I connect to the database successfully and then try to insert some values using named arguments such as this,

stmt = DBInterface.prepare(conn,"insert into test values(:id, :pname) ;")

This results in the error:

julia> stmt = DBInterface.prepare(conn,"insert into test values(:id, :pname) ;")
ERROR: (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':id, :pname)' at line 1
Stacktrace:
 [1] prepare
   @ ~/.julia/packages/MySQL/tCDUl/src/api/papi.jl:4 [inlined]
 [2] prepare(conn::MySQL.Connection, sql::String; mysql_date_and_time::Bool)
   @ MySQL ~/.julia/packages/MySQL/tCDUl/src/prepare.jl:48
 [3] prepare(conn::MySQL.Connection, sql::String)
   @ MySQL ~/.julia/packages/MySQL/tCDUl/src/prepare.jl:45
 [4] top-level scope
   @ /data/projects/Stocks/testsql.jl:17

If I use positional arguments it works fine. However positional arguments can't handle more complicated queries wherein a given argument must appear multiple times within the query.

Is this an issue within DBInterface or MySQL?

mattcbro avatar Jul 24 '23 00:07 mattcbro