'How do I insert text into MySQL with Julia?

I'm struggling to get text from an input file into MySQL with Julia.

Using this code:

using CSV
using MySQL

conn = DBInterface.connect(MySQL.Connection, "localhost", "root", "abcdefgh", db="nba")

create_games_table = "CREATE TABLE IF NOT EXISTS games(
        home_team VARCHAR(20)
        );"

DBInterface.execute(conn, create_games_table)

insert_into_games = DBInterface.prepare(conn, "INSERT INTO games VALUES(?)")

file_name = "C:/Myfilename.txt"

csv_reader = CSV.File(file_name; header=[:Date, :Home, :H_pts], delim="\t", dateformat="e u d yyyy")

for row in csv_reader
        @show typeof(row.Home)
        DBInterface.execute(insert_into_games, [row.Home])
end

I get this output:

typeof(row.Home) = String15
ERROR: MethodError: no method matching bind!(::MySQL.API.BindHelper, ::Vector{MySQL.API.MYSQL_BIND}, ::Int64, ::String15)
Closest candidates are:
  bind!(::Any, ::Any, ::Any, ::Missing) at C:\Users\Graham\.julia\packages\MySQL\EgAUf\src\prepare.jl:313
  bind!(::Any, ::Any, ::Any, ::Dates.TimeType) at C:\Users\Graham\.julia\packages\MySQL\EgAUf\src\prepare.jl:334
  bind!(::Any, ::Any, ::Any, ::Union{MySQL.API.Bit, String, DecFP.DecimalFloatingPoint, Vector{UInt8}}) at C:\Users\User\.julia\packages\MySQL\EgAUf\src\prepare.jl:357
  ...
Stacktrace:
 [1] (::MySQL.var"#36#43"{MySQL.Statement, Vector{String15}})(i::Int64)

It seems to be expecting Int input, and sure enough if I change the file input and db columns to Int, it works. But why is it expecting Int input when I'm trying to populate a text field?



Solution 1:[1]

The feature request suggested by Frames Catherine White should now be implemented in the latest release of MySQL.jl. This problem should no longer be an issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shakeshuck