-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmysql_wrapper.d
70 lines (62 loc) · 1.73 KB
/
mysql_wrapper.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module mysql_wrapper;
import mysql;
import std.string;
import std.conv;
MYSQL * mysql_connect_d(MYSQL *mysql, string host,string user, string passwd, string db, uint port, string unix_socket, uint clientflag) {
return mysql_real_connect( mysql, cast(char*) host, cast(char*) user, cast(char*) passwd, cast(char*) db, port,
cast(char*) unix_socket, clientflag);
}
int mysql_query_d(MYSQL *mysql, string q) {
return mysql_query(mysql, cast(char*) q);
}
string[] mysql_fetch_array(MYSQL_RES *result) {
string[] werte;
static MYSQL_ROW row;
uint y,count;
row = mysql_fetch_row(result);
if (row != null) {
count = mysql_num_fields(result);
for ( y = 0; count > y; y++) {
werte ~= to!string(row[y]);
}
} else {
werte = null;
mysql_free_result(result);
}
return werte;
}
string mysql_escape(string str) {
string str_escape;
foreach (char c; str) {
if (c =='\'') {
str_escape ~= "\\'";
} else {
if (c == '\\') {
str_escape~= "\\\\";
} else {
str_escape ~= c;
}
}
}
return str_escape;
}
string[string] mysql_fetch_assoc(MYSQL_RES *result) {
string[string] hash;
static MYSQL_ROW row;
uint y=0;
MYSQL_FIELD *fields;
//MYSQL_FIELD_OFFSET offset;
row = mysql_fetch_row(result);
if (row != null) {
//offset = mysql_field_seek(result,0);
mysql_field_seek(result,0);
while ( (fields = mysql_fetch_field(result)) != null) {
hash[to!string(fields.name)] = cast(string) to!string(row[y]);
y++;
}
} else {
hash = null;
mysql_free_result(result);
}
return hash;
}