Skip to content

Commit 9c9c667

Browse files
committed
Avoid overriding BASE package
1 parent bebbb80 commit 9c9c667

File tree

4 files changed

+56
-138
lines changed

4 files changed

+56
-138
lines changed

src/MySQL.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module MySQL
44
include("config.jl")
55
include("types.jl")
66
include("api.jl")
7-
include("dbi.jl")
7+
include("handy.jl")
88

99
export MySQL5
1010
export MySQLDatabaseHandle

src/dbi.jl

-135
This file was deleted.

src/handy.jl

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Handy wrappers to functions defined in api.jl.
2+
3+
"""
4+
A handy function that wraps mysql_init and mysql_real_connect. Also does error
5+
checking on the pointers returned by init and real_connect.
6+
"""
7+
function mysql_connect(host::String,
8+
user::String,
9+
passwd::String,
10+
db::String,
11+
port::Integer = 0,
12+
unix_socket::Any = C_NULL,
13+
client_flag::Integer = 0)
14+
15+
mysqlptr::Ptr{Cuchar} = C_NULL
16+
mysqlptr = mysql_init(mysqlptr)
17+
18+
if mysqlptr == C_NULL
19+
error("Failed to initialize MySQL database")
20+
end
21+
22+
mysqlptr = mysql_real_connect(mysqlptr,
23+
host,
24+
user,
25+
passwd,
26+
db,
27+
convert(Cint, port),
28+
unix_socket,
29+
convert(Uint64, client_flag))
30+
31+
if mysqlptr == C_NULL
32+
error("Failed to connect to MySQL database")
33+
end
34+
35+
return MySQLDatabaseHandle(mysqlptr, 0)
36+
end
37+
38+
"""
39+
Wrapper over mysql_real_connect with CLIENT_MULTI_STATEMENTS passed
40+
as client flag options.
41+
"""
42+
function mysql_connect(hostName::String, userName::String, password::String, db::String)
43+
return mysql_connect(hostName, userName, password, db, 0,
44+
C_NULL, MySQL.CLIENT_MULTI_STATEMENTS)
45+
end
46+
47+
"""
48+
Wrapper over mysql_close. Must be called to close the connection opened by
49+
MySQL.mysql_connect.
50+
"""
51+
function mysql_disconnect(db::MySQLDatabaseHandle)
52+
mysql_close(db.ptr)
53+
end

test/test.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function show_as_dataframe()
8181
end
8282

8383
function run_test()
84-
global con = MySQL.connect(HOST, USER, PASSWD, DBNAME)
84+
global con = MySQL.mysql_connect(HOST, USER, PASSWD, DBNAME)
8585
create_table()
8686

8787
insert_values()
@@ -95,7 +95,7 @@ function run_test()
9595
# show_as_dataframe()
9696

9797
drop_table()
98-
MySQL.disconnect(con)
98+
MySQL.mysql_disconnect(con)
9999
end
100100

101101
run_test()

0 commit comments

Comments
 (0)