Skip to content

Commit e20f85d

Browse files
mcmcgrath13quinnj
authored andcommitted
enable multi-statement execute (#110)
* enable multi-statement execute * update README
1 parent e35d13a commit e20f85d

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ Contributions are very welcome, as are feature requests and suggestions. Please
4242
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
4343
[docs-stable-url]: https://JuliaData.github.io/MySQL.jl/stable
4444

45-
[travis-img]: https://travis-ci.org/JuliaData/MySQL.jl.svg?branch=master
46-
[travis-url]: https://travis-ci.org/JuliaData/MySQL.jl
45+
[travis-img]: https://travis-ci.org/JuliaDatabases/MySQL.jl.svg?branch=master
46+
[travis-url]: https://travis-ci.org/JuliaDatabases/MySQL.jl
4747

48-
[codecov-img]: https://codecov.io/gh/JuliaData/MySQL.jl/branch/master/graph/badge.svg
49-
[codecov-url]: https://codecov.io/gh/JuliaData/MySQL.jl
48+
[codecov-img]: https://codecov.io/gh/JuliaDatabases/MySQL.jl/branch/master/graph/badge.svg
49+
[codecov-url]: https://codecov.io/gh/JuliaDatabases/MySQL.jl
5050

51-
[issues-url]: https://github.com/JuliaData/MySQL.jl/issues
51+
[issues-url]: https://github.com/JuliaDatabases/MySQL.jl/issues
5252

5353
[pkg-0.6-img]: http://pkg.julialang.org/badges/MySQL_0.6.svg
5454
[pkg-0.6-url]: http://pkg.julialang.org/?pkg=MySQL
@@ -205,4 +205,3 @@ end
205205
MySQL.disconnect(conn)
206206

207207
```
208-

src/MySQL.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ execute an sql statement without returning results (useful for DDL statements, u
9191
"""
9292
function execute!(conn::Connection, sql::String)
9393
conn.ptr == C_NULL && throw(MySQLInterfaceError("`MySQL.execute!` called with NULL connection."))
94-
API.mysql_query(conn.ptr, sql) == 0 || throw(MySQLInternalError(conn))
95-
return Int(API.mysql_affected_rows(conn.ptr))
94+
status = API.mysql_query(conn.ptr, sql)
95+
status == 0 || throw(MySQLInternalError(conn))
96+
res = 0
97+
while status == 0
98+
res += Int(API.mysql_affected_rows(conn.ptr))
99+
status = API.mysql_next_result(conn.ptr)
100+
end
101+
return res
96102
end
97103

98104
"""

test/runtests.jl

+12
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,15 @@ Data.stream!(values, stmt)
107107
res = MySQL.query(conn, "select * from Employee")
108108
@test length(res) == 10
109109
@test length(res[1]) == 9
110+
111+
# test multi-statement execution
112+
MySQL.execute!(conn, """DROP DATABASE if exists mysqltest2;
113+
CREATE DATABASE mysqltest2;
114+
USE mysqltest2;
115+
CREATE TABLE test (a varchar(20), b integer);
116+
INSERT INTO test (a,b) value ("test",123);""")
117+
118+
res = MySQL.query(conn, """select * from test;""")
119+
120+
@test res.a[1] == "test"
121+
@test res.b[1] == 123

0 commit comments

Comments
 (0)