@@ -361,6 +361,7 @@ void Scr_MySQL_Fetch_Row_f()
361361 Plugin_Scr_MakeArray ();
362362
363363 int i ;
364+ mysql_field_seek (g_mysql_res [handle ], 0 );
364365 for (i = 0 ; i < col_count ; ++ i )
365366 {
366367 /* A little help here? I don't actually understand data representation
@@ -400,26 +401,25 @@ void Scr_MySQL_Fetch_Rows_f()
400401 Scr_MySQL_CheckCall (handle );
401402
402403 unsigned int col_count = mysql_num_fields (g_mysql_res [handle ]);
403- int row = mysql_num_rows (g_mysql_res [handle ]);
404404
405405 // do this no matter what.
406406 Plugin_Scr_MakeArray ();
407407
408- if (row != 0 )
408+ if (mysql_num_rows ( g_mysql_res [ handle ]) != 0 ) /* Rows are exist */
409409 {
410410 int i = 0 ;
411411
412412 //int keyArrayIndex[col_count]; // NO, NO and... NO
413413 //char* keyArray[col_count]; // When you do that, in this world one T-Max cries somewhere!
414414 // First answer: http://stackoverflow.com/questions/5377411/non-const-declaration-of-array
415415
416- int * keyArrayIndex = calloc (col_count , sizeof (int ));
416+ /* int* keyArrayIndex = calloc(col_count, sizeof(int));
417417 MYSQL_FIELD* field;
418418 while((field = mysql_fetch_field(g_mysql_res[handle])) != NULL)
419419 {
420420 keyArrayIndex[i] = Plugin_Scr_AllocString(field->name);
421421 ++i;
422- }
422+ }*/
423423
424424 MYSQL_ROW rows ;
425425 /*if( row == 1 ) // only one row? custom handling to only return a single dimensional array.
@@ -435,13 +435,18 @@ void Scr_MySQL_Fetch_Rows_f()
435435 while ((rows = mysql_fetch_row (g_mysql_res [handle ])) != NULL )
436436 {
437437 Plugin_Scr_MakeArray ();
438- for (i = 0 ; i < col_count ; ++ i ) {
438+
439+ mysql_field_seek (g_mysql_res [handle ], 0 );
440+ for (i = 0 ; i < col_count ; ++ i )
441+ {
439442 Plugin_Scr_AddString (rows [i ]);
440- Plugin_Scr_AddArrayKey (keyArrayIndex [i ]);
443+
444+ MYSQL_FIELD * field = mysql_fetch_field (g_mysql_res [handle ]);
445+ Plugin_Scr_AddArrayKey (Plugin_Scr_AllocString (field -> name ));
441446 }
442447 Plugin_Scr_AddArray ();
443448 }
444449 //}
445- free (keyArrayIndex );
450+ // free(keyArrayIndex);
446451 }
447452}
0 commit comments