|
| 1 | +if get(ENV, "MYSQLJL_BOOTSTRAPPED", "false") != "true" |
| 2 | + using Pkg |
| 3 | + |
| 4 | + jll_pkg_version(v::String) = VersionNumber(occursin("+", v) ? v : string(v, "+0")) |
| 5 | + |
| 6 | + Pkg.activate(; temp=true) |
| 7 | + Pkg.develop(PackageSpec(path=dirname(@__DIR__))) |
| 8 | + Pkg.add([ |
| 9 | + PackageSpec(name="DBInterface"), |
| 10 | + PackageSpec(name="Tables"), |
| 11 | + ]) |
| 12 | + |
| 13 | + jll_version = get(ENV, "MYSQLJL_JLL_VERSION", "default") |
| 14 | + if jll_version != "default" |
| 15 | + Pkg.add(PackageSpec(name="MariaDB_Connector_C_jll", version=jll_pkg_version(jll_version))) |
| 16 | + else |
| 17 | + Pkg.add(PackageSpec(name="MariaDB_Connector_C_jll")) |
| 18 | + end |
| 19 | + |
| 20 | + Pkg.instantiate() |
| 21 | + Pkg.status() |
| 22 | + |
| 23 | + ENV["MYSQLJL_BOOTSTRAPPED"] = "true" |
| 24 | + include(@__FILE__) |
| 25 | + exit() |
| 26 | +end |
| 27 | + |
| 28 | +using DBInterface |
| 29 | +using Libdl |
| 30 | +using MariaDB_Connector_C_jll |
| 31 | +using MySQL |
| 32 | +using Random |
| 33 | +using Tables |
| 34 | + |
| 35 | +function logline(xs...) |
| 36 | + println(xs...) |
| 37 | + flush(stdout) |
| 38 | + return nothing |
| 39 | +end |
| 40 | + |
| 41 | +function connect_root(; db=nothing) |
| 42 | + host = get(ENV, "MYSQLJL_HOST", "127.0.0.1") |
| 43 | + port = parse(Int, get(ENV, "MYSQLJL_PORT", "3306")) |
| 44 | + user = get(ENV, "MYSQLJL_USER", "root") |
| 45 | + password = get(ENV, "MYSQLJL_PASSWORD", "root") |
| 46 | + |
| 47 | + if db === nothing |
| 48 | + return DBInterface.connect(MySQL.Connection, host, user, password; port=port, connect_timeout=10) |
| 49 | + else |
| 50 | + return DBInterface.connect(MySQL.Connection, host, user, password; db=db, port=port, connect_timeout=10) |
| 51 | + end |
| 52 | +end |
| 53 | + |
| 54 | +function placeholders(n::Integer) |
| 55 | + return join(fill("?", n), ",") |
| 56 | +end |
| 57 | + |
| 58 | +function query_for(shape::Symbol, n::Integer) |
| 59 | + marks = placeholders(n) |
| 60 | + if shape === :table |
| 61 | + return "SELECT id FROM myTable WHERE id IN ($marks)" |
| 62 | + elseif shape === :constant |
| 63 | + return "SELECT 1 AS id WHERE 1 IN ($marks)" |
| 64 | + elseif shape === :echo |
| 65 | + return "SELECT $marks" |
| 66 | + else |
| 67 | + error("unknown query shape: $shape") |
| 68 | + end |
| 69 | +end |
| 70 | + |
| 71 | +function consume(cursor) |
| 72 | + rows = 0 |
| 73 | + for _ in cursor |
| 74 | + rows += 1 |
| 75 | + end |
| 76 | + return rows |
| 77 | +end |
| 78 | + |
| 79 | +function run_case(conn, name::String, shape::Symbol, params; mysql_store_result::Bool=true) |
| 80 | + n = length(params) |
| 81 | + query = query_for(shape, n) |
| 82 | + logline("BEGIN name=", name, |
| 83 | + " shape=", shape, |
| 84 | + " n=", n, |
| 85 | + " eltype=", eltype(params), |
| 86 | + " mysql_store_result=", mysql_store_result) |
| 87 | + logline("QUERY ", query) |
| 88 | + logline("FIRST_VALUES ", collect(Iterators.take(params, min(n, 5)))) |
| 89 | + |
| 90 | + stmt = DBInterface.prepare(conn, query) |
| 91 | + logline("PREPARED nparams=", stmt.nparams, " nfields=", stmt.nfields) |
| 92 | + |
| 93 | + cursor = DBInterface.execute(stmt, params; mysql_store_result=mysql_store_result) |
| 94 | + rows = consume(cursor) |
| 95 | + logline("DONE name=", name, " rows=", rows) |
| 96 | + |
| 97 | + DBInterface.close!(stmt) |
| 98 | + return nothing |
| 99 | +end |
| 100 | + |
| 101 | +function prepare_database() |
| 102 | + conn = connect_root() |
| 103 | + try |
| 104 | + version = DBInterface.execute(conn, "SELECT VERSION() AS version") |> Tables.columntable |
| 105 | + logline("SERVER_VERSION ", only(version.version)) |
| 106 | + |
| 107 | + DBInterface.execute(conn, "DROP DATABASE IF EXISTS issue236") |
| 108 | + DBInterface.execute(conn, "CREATE DATABASE issue236") |
| 109 | + finally |
| 110 | + DBInterface.close!(conn) |
| 111 | + end |
| 112 | + |
| 113 | + conn = connect_root(db="issue236") |
| 114 | + DBInterface.execute(conn, "CREATE TABLE myTable (id BIGINT UNSIGNED NOT NULL PRIMARY KEY)") |
| 115 | + |
| 116 | + stmt = DBInterface.prepare(conn, "INSERT INTO myTable (id) VALUES (?)") |
| 117 | + try |
| 118 | + for id in UInt64(1):UInt64(512) |
| 119 | + DBInterface.execute(stmt, id) |
| 120 | + end |
| 121 | + finally |
| 122 | + DBInterface.close!(stmt) |
| 123 | + end |
| 124 | + return conn |
| 125 | +end |
| 126 | + |
| 127 | +function main() |
| 128 | + logline("JULIA_VERSION ", VERSION) |
| 129 | + logline("OS ", Sys.KERNEL, " MACHINE ", Sys.MACHINE) |
| 130 | + logline("WORD_SIZE ", Sys.WORD_SIZE) |
| 131 | + logline("LIBMARIADB ", MariaDB_Connector_C_jll.libmariadb) |
| 132 | + logline("LIBMARIADB_HANDLE ", Libdl.dlopen_e(MariaDB_Connector_C_jll.libmariadb)) |
| 133 | + |
| 134 | + conn = prepare_database() |
| 135 | + try |
| 136 | + Random.seed!(0x236) |
| 137 | + |
| 138 | + for n in (31, 32, 33, 34, 64, 128) |
| 139 | + run_case(conn, "table-small-uint64", :table, UInt64.(1:n)) |
| 140 | + end |
| 141 | + |
| 142 | + for n in (32, 33, 34) |
| 143 | + run_case(conn, "table-small-int64", :table, Int64.(1:n)) |
| 144 | + run_case(conn, "table-random-uint64", :table, rand(UInt64, n)) |
| 145 | + run_case(conn, "constant-small-uint64", :constant, UInt64.(1:n)) |
| 146 | + run_case(conn, "table-small-uint64-unbuffered", :table, UInt64.(1:n); mysql_store_result=false) |
| 147 | + end |
| 148 | + |
| 149 | + run_case(conn, "echo-small-uint64", :echo, UInt64.(1:33)) |
| 150 | + finally |
| 151 | + DBInterface.close!(conn) |
| 152 | + end |
| 153 | + |
| 154 | + logline("ISSUE236_DIAGNOSTIC_COMPLETE") |
| 155 | +end |
| 156 | + |
| 157 | +main() |
0 commit comments