-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.gsc
executable file
·128 lines (113 loc) · 2.55 KB
/
mysql.gsc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
MAKING LIFE EASY
*/
make_global_mysql(host, user, pass, db, port)
{
/*
the game-resetting is cleaning "level"
but "game" stays the same
main / Callback_StartGameType does both get recalled
*/
if (isDefined(game["mysql"]))
level.mysql = game["mysql"]; // for in-map-restart
/* if the server goes down, then its not reconnecting even after map :S
so better connect/disconnect... every map
else if (getcvar("mysql_handle") != "")
level.mysql = int(getcvar("mysql_handle")); // for map-restart
*/
// thought about a static pointer in c, where i could use to store mallocs()
// getStaticPointer() and setStaticPointer(value)
if (isDefined(level.mysql))
{
printf("Reusing MySQL-Connection: handle=%\n", level.mysql);
return;
}
mysql = mysql_init();
//iprintln("mysql="+mysql);
ret = mysql_real_connect(mysql, host, user, pass, db, port);
if (!ret)
{
printf("errno=% error=''%''", mysql_errno(mysql), mysql_error(mysql));
mysql_close(mysql);
return;
}
printf("MySQL-Connection created: handle=%\n", mysql);
// ok, now make it global!
level.mysql = mysql;
game["mysql"] = mysql;
//setcvar("mysql_handle", mysql);
}
delete_global_mysql()
{
mysql_close(level.mysql);
printf("MySQL-Connection deleted: handle=%\n", level.mysql);
//level.mysql = undefined;
}
/*
C INTERFACE
*/
// LET THE PREPARED STATEMENTS COME TO LIVE! 13.05.2012
mysql_stmt_init(mysql)
{
return closer(150, mysql);
}
mysql_stmt_close(mysql_stmt)
{
return closer(151, mysql_stmt);
}
/*
printf("stmt->stmt_id = %d\n", stmt->stmt_id);
printf("stmt->prefetch_rows = %d\n", stmt->prefetch_rows);
printf("stmt->param_count = %d\n", stmt->param_count);
printf("stmt->field_count = %d\n", stmt->field_count);
*/
mysql_stmt_get_stmt_id(mysql_stmt)
{
return closer(152, mysql_stmt);
}
mysql_stmt_get_prefetch_rows(mysql_stmt)
{
return closer(153, mysql_stmt);
}
mysql_stmt_get_param_count(mysql_stmt)
{
return closer(154, mysql_stmt);
}
mysql_stmt_get_field_count(mysql_stmt)
{
return closer(155, mysql_stmt);
}
mysql_stmt_prepare(mysql_stmt, sql, len)
{
return closer(156, mysql_stmt, sql, len);
}
/*
mysql_constant_MYSQL_TYPE_LONG()
{
return 123;
}
mysql_struct_MYSQL_BIND_a()
{
return 4;
}
*/
mysql_stmt_bind_param(mysql_stmt, param)
{
return closer(157, mysql_stmt, param);
}
mysql_stmt_bind_result(mysql_stmt, result)
{
return closer(158, mysql_stmt, result);
}
mysql_stmt_execute(mysql_stmt)
{
return closer(159, mysql_stmt);
}
mysql_stmt_store_result(mysql_stmt)
{
return closer(160, mysql_stmt);
}
mysql_stmt_fetch(mysql_stmt)
{
return closer(161, mysql_stmt);
}