Skip to content

Commit a91105e

Browse files
committed
merged
2 parents 239d68e + 9eb7ca8 commit a91105e

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

bin/win32/cod4x_mysql.dll

-14.4 KB
Binary file not shown.

plugin_main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ MYSQL g_mysql[MYSQL_CONNECTION_COUNT];
2626
MYSQL_RES* g_mysql_res[MYSQL_CONNECTION_COUNT];
2727
qboolean g_mysql_reserved[MYSQL_CONNECTION_COUNT];
2828

29-
//cvar_t *g_mysql_port;
30-
3129
PCL void OnInfoRequest(pluginInfo_t *info)
3230
{
3331
char description[1024] = {'\0'};

script_functions.c

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ extern MYSQL g_mysql[MYSQL_CONNECTION_COUNT];
1515
extern MYSQL_RES* g_mysql_res[MYSQL_CONNECTION_COUNT];
1616
extern qboolean g_mysql_reserved[MYSQL_CONNECTION_COUNT];
1717

18-
//extern cvar_t *g_mysql_port;
19-
2018
/* =================================================================
2119
* Shows script runtime error with crash.
2220
* For use only inside gsc callbacks.
@@ -101,8 +99,8 @@ void Scr_MySQL_Real_Connect_f()
10199
if (argc != 4 && argc != 5)
102100
{
103101
Plugin_Scr_Error("Usage: handle = mysql_real_connect(<str host>, "
104-
"<str user>, <str passwd>, <str db>, "
105-
"[int port=3306]);");
102+
"<str user>, <str passwd>, <str db>, "
103+
"[int port=3306]);");
106104
return;
107105
}
108106

@@ -117,7 +115,7 @@ void Scr_MySQL_Real_Connect_f()
117115
if(port < 0 || port > 65535)
118116
{
119117
Plugin_Scr_ParamError(4, "Incorrect port: must be any integer "
120-
"from 0 to 65535");
118+
"from 0 to 65535");
121119
return;
122120
}
123121
}
@@ -145,24 +143,21 @@ void Scr_MySQL_Real_Connect_f()
145143
return;
146144
}
147145
}
148-
MYSQL* result = mysql_real_connect(&g_mysql[handle], host,
149-
user,
150-
pass,
151-
db,
152-
port, NULL, 0);
146+
MYSQL* result = mysql_real_connect(&g_mysql[handle], host, user, pass,
147+
db, port, NULL, 0);
153148

154149
/* We don't want to crash the server, so we have a check to return nothing to prevent that */
155150
if (result == NULL)
156151
{
157152
Scr_MySQL_Error("MySQL connect error: (%d) %s", mysql_errno(&g_mysql[handle]),
158153
mysql_error(&g_mysql[handle]));
159-
Plugin_Scr_AddUndefined(); // make sure we return undefined so GSC does not shit it's self.
160154
return;
161155
}
162156
g_mysql_reserved[handle] = qtrue;
163157

164158
/* Would you like to reconnect if connection is dropped? */
165-
qboolean reconnect = qtrue; // allows the database to reconnect on a new query etc.
159+
/* Allows the database to reconnect on a new query etc. */
160+
qboolean reconnect = qtrue;
166161

167162
/* Check to see if the mySQL server connection has dropped */
168163
mysql_options(&g_mysql[handle], MYSQL_OPT_RECONNECT, &reconnect);
@@ -364,8 +359,9 @@ void Scr_MySQL_Fetch_Row_f()
364359
mysql_field_seek(g_mysql_res[handle], 0);
365360
for(i = 0; i < col_count; ++i)
366361
{
367-
/* A little help here? I don't actually understand data representation
368-
Integer must be integer, string - string, float - float */
362+
/* A little help here? I don't actually understand data
363+
* representation. Integer must be integer, string - string,
364+
* float - float */
369365
MYSQL_FIELD *field = mysql_fetch_field(g_mysql_res[handle]);
370366
if(field == NULL)
371367
{
@@ -405,51 +401,31 @@ void Scr_MySQL_Fetch_Rows_f()
405401
/* Just rewind it back to start */
406402
mysql_row_seek(g_mysql_res[handle], 0);
407403

408-
// do this no matter what.
404+
/* Do this no matter what */
409405
Plugin_Scr_MakeArray();
410406

411407
if(mysql_num_rows(g_mysql_res[handle]) != 0) /* Rows are exist */
412408
{
413409
int i = 0;
414410

415-
//int keyArrayIndex[col_count]; // NO, NO and... NO
416-
//char* keyArray[col_count]; // When you do that, in this world one T-Max cries somewhere!
417-
// First answer: http://stackoverflow.com/questions/5377411/non-const-declaration-of-array
418-
419-
/*int* keyArrayIndex = calloc(col_count, sizeof(int));
411+
int* keyArrayIndex = calloc(col_count, sizeof(int));
420412
MYSQL_FIELD* field;
421413
while((field = mysql_fetch_field(g_mysql_res[handle])) != NULL)
422414
{
423415
keyArrayIndex[i] = Plugin_Scr_AllocString(field->name);
424416
++i;
425-
}*/
417+
}
426418

427419
MYSQL_ROW rows;
428-
/*if( row == 1 ) // only one row? custom handling to only return a single dimensional array.
420+
while((rows = mysql_fetch_row(g_mysql_res[handle])) != NULL)
429421
{
430-
rows = mysql_fetch_row(g_mysql_res[handle]); // this will only give us one result.
422+
Plugin_Scr_MakeArray();
431423
for (i = 0; i < col_count; ++i) {
432424
Plugin_Scr_AddString(rows[i]);
433425
Plugin_Scr_AddArrayKey(keyArrayIndex[i]);
434426
}
427+
Plugin_Scr_AddArray();
435428
}
436-
else
437-
{*/
438-
while((rows = mysql_fetch_row(g_mysql_res[handle])) != NULL)
439-
{
440-
Plugin_Scr_MakeArray();
441-
442-
mysql_field_seek(g_mysql_res[handle], 0);
443-
for (i = 0; i < col_count; ++i)
444-
{
445-
Plugin_Scr_AddString(rows[i]);
446-
447-
MYSQL_FIELD* field = mysql_fetch_field(g_mysql_res[handle]);
448-
Plugin_Scr_AddArrayKey(Plugin_Scr_AllocString(field->name));
449-
}
450-
Plugin_Scr_AddArray();
451-
}
452-
//}
453-
//free(keyArrayIndex);
429+
free(keyArrayIndex);
454430
}
455431
}

0 commit comments

Comments
 (0)