Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release] Error checking Routine for Mysql [*UPDATED 20/4*]

Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
A lot of the errors are caused by database read errors. The program reads the data and assumes it is ok.
If there is an error and no data is returned, you must check for this before trying to use the data.

Here is the error checking I use ( I get very few errors).

I have made a few subtle changes - it does not try to clear stored results if it did not get any and now will return 0 on being unable to read the database. (sorry for use of ( ? : ) construct I could not be bothered to write it out in full =])

copy and paste and replace the original one ( tested ver 7 Titan) all in MySQLM.cpp

Code:
#include "MySQLM.h"
#include <sstream>
#include <string>
using namespace std;

MYSQL MySQL::maple_db;

int MySQL::connectToMySQL(){
	if(!mysql_real_connect(&maple_db, "localhost", "root", "xxxxxx", "xxxxxxx", 3306, NULL, 0)){
		printf(mysql_error(&maple_db));
		return 0;
	}
	return 1;
}

int MySQL::getInt(char* table, int id, char* value){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
	int ret = 0; 
	sprintf_s(query, 255, "SELECT %s FROM %s WHERE ID=%d;",value, table, id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getINT SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		if(mysql_num_fields(mres) > 0){
			string mr = string((char*)mrow[0]);
			istringstream buffer(mr);
			buffer >> ret;
		}
	}
	if (mres != 0) mysql_free_result(mres);
	return ret;
}

int MySQL::getCharactersIDs(int id, int IDs[3]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
    sprintf_s(query, 255, "SELECT ID FROM characters WHERE userid = %d;", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getCharactersIDs SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		for(int i=0; i<mysql_num_rows(mres); i++){
			string mr = string((char*)mrow[0]);
			istringstream buffer(mr);
			buffer >> IDs[i];
			mrow = mysql_fetch_row(mres);
		}
	}
	int ret = (mres == 0 ? 0 : (int)mysql_num_rows(mres));
	if (mres != 0) mysql_free_result(mres);
	return ret;
}

int MySQL::isString(char* table, char* whr, char* wht){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT * FROM %s WHERE %s='%s';",table, whr, wht);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	mrow = (mres == 0 ? 0 : mysql_fetch_row(mres));
	if(mrow){
		mysql_free_result(mres);
		return 1;
	}
	else{
		return 0;
	}
}

void MySQL::getString(char* table, char* whr, char* wht, char* value, char* string){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT %s FROM %s WHERE %s='%s';",value, table, whr, wht);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getSTRING SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		if(mysql_num_rows(mres) > 0){
			strcpy_s(string, 13, (char*)mrow[0]);
		}
	}
	if (mres != 0 ) mysql_free_result(mres);
}
void MySQL::getStringI(char* table, char* whr, int wht, char* value, char* string){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT %s FROM %s WHERE %s = %d;",value, table, whr, wht);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getStringI SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		if(mysql_num_rows(mres) > 0){
			strcpy_s(string, 13, (char*)mrow[0]);
		}
	}
	if (mres != 0) mysql_free_result(mres);
}


void MySQL::setInt(char* table, char* wht, int id, int value){
	char query[255]; 
                sprintf_s(query, 255, "UPDATE %s SET %s = %d WHERE ID = %d;", table, wht, value, id);
	mysql_real_query(&maple_db, query, strlen(query));
}

void MySQL::setString(char* table, char* wht, int id, char* value){
	char query[255]; 
                sprintf_s(query, 255, "UPDATE %s SET %s='%s' where ID = %d;", table, wht, value, id);
	mysql_real_query(&maple_db, query, strlen(query));
}

int MySQL::getUserID(char *username){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
	int ret = 0;
	sprintf_s(query, 255, "SELECT id FROM users WHERE username='%s';",username);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getUserID SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		if(mysql_num_rows(mres) > 0){
			mrow = mysql_fetch_row(mres);
			string mr = string((char*)mrow[0]);
			istringstream buffer(mr);
			buffer >> ret;
		}
	}
	if (mres !=0) mysql_free_result(mres);
	return ret;
}

int MySQL::setChar(int userid){
	char query[255]; 
                sprintf_s(query, 255, "INSERT INTO characters(userid) VALUES(%d);", userid);
	mysql_real_query(&maple_db, query, strlen(query));
	int IDs[3];
	int num = getCharactersIDs(userid, IDs);
	return IDs[num-1];
}

void MySQL::charInfo(char* wht, int id){
	char query[255]; 
    sprintf_s(query, 255, "UPDATE characters SET %s WHERE ID = %d;", wht, id);
	mysql_real_query(&maple_db, query, strlen(query));
}

void MySQL::deleteRow(char* table, int id){
	char query[255]; 
                sprintf_s(query, 255, "DELETE FROM %s WHERE ID = %d;", table, id);
	mysql_real_query(&maple_db, query, strlen(query));

}

void MySQL::insert(char* query){
	mysql_real_query(&maple_db, query, strlen(query));
}

int MySQL::showEquips(int id, int equips[15][2]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
	int ret = 0;
                sprintf_s(query, 255, "SELECT equipid, type FROM equip WHERE (charid = %d AND pos<0);", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in showEquips SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		for(int i=0; i<mysql_num_rows(mres); i++){
			string mr = string((char*)mrow[0]);
			istringstream buffer(mr);
			buffer >> equips[i][0];
			string mr2 = string((char*)mrow[1]);
			istringstream buffer2(mr2);
			buffer2 >> equips[i][1];
			mrow = mysql_fetch_row(mres);
		}
	}
	ret = (mres==0 ? 0 : (int)mysql_num_rows(mres));
	if (mres != 0 ) mysql_free_result(mres);
	return ret;
}

int MySQL::showEquipsIn(int id, int equips[115][21]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT * FROM equip WHERE charid = %d;", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getEquipsIn SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		for(int i=0; i<mysql_num_rows(mres); i++){
			for(int j=0; j<21; j++){
				string mr = string((char*)mrow[j]);
				istringstream buffer(mr);
				buffer >> equips[i][j];
			}
			mrow = mysql_fetch_row(mres);
		}
	}
	int ret = (mres == 0 ? 0 : (int)mysql_num_rows(mres));
	if (mres != 0) mysql_free_result(mres);
	return ret;
}

int MySQL::getItems(int id, int equips[400][4]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT * FROM items WHERE charid = %d;", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getItems SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		//int ret = 0;
		for(int i=0; i<mysql_num_rows(mres); i++){
			for(int j=0; j<5; j++){
				string mr = string((char*)mrow[j]);
				istringstream buffer(mr);
				if(j>1)
					buffer >> equips[i][j-1];
				else if(j!=1)
					buffer >> equips[i][0];
			}
			mrow = mysql_fetch_row(mres);
		}
	}
	int ret = (mres == 0 ? 0 : (int)mysql_num_rows(mres));
	if (mres != 0 ) mysql_free_result(mres);
	return ret;
}
int MySQL::getSkills(int id, int skills[200][2]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
                sprintf_s(query, 255, "SELECT * FROM skills WHERE charid = %d;", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getSkills SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		for(int i=0; i<mysql_num_rows(mres); i++){
			for(int j=1; j<3; j++){
				string mr = string((char*)mrow[j]);
				istringstream buffer(mr);
				buffer >> skills[i][j-1];
			}
			mrow = mysql_fetch_row(mres);
		}
	}
	int ret = (mres == 0 ? 0 : (int)mysql_num_rows(mres));
	if (mres != 0 ) mysql_free_result(mres);
	return ret;
}
void MySQL::getKeys(int id, int keys[90]){
	MYSQL_RES *mres;
	MYSQL_ROW mrow;
	char query[255]; 
	int ret = 0;
                sprintf_s(query, 255, "SELECT * FROM keymap WHERE charid = %d;", id);
	mysql_real_query(&maple_db, query, strlen(query));
	mres = mysql_store_result(&MySQL::maple_db);
	if (mres == 0 ){
		printf_s("\n\rError in getKeys SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
		printf_s("SQL Query is : %s",query);
	}
	else {
		mrow = mysql_fetch_row(mres);
		for(int i=0; i<90; i++){
			string mr = string((char*)mrow[i+1]);
			istringstream buffer(mr);
			buffer >> keys[i];
		}
	}
	if (mres != 0) mysql_free_result(mres);
}
View attachment 52665 <<< zipped file
 
Last edited:
Junior Spellweaver
Joined
Oct 10, 2007
Messages
101
Reaction score
0
Re: [Release] Error checking Routine for Mysql

so what exactly does this do? o-o
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

so what exactly does this do? o-o

It checks that the database has actually returned some data. If it has it uses it, if not it prints a message and does not try to use the data. Which means you dont get access violations reading from memory addresses where pointers have not been set properly.
 
Newbie Spellweaver
Joined
Apr 6, 2008
Messages
15
Reaction score
0
Re: [Release] Error checking Routine for Mysql

This is an amazing modification! You deserve props for this one.
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

You put similar lines in the Mysql routines that read the database.
 
om nom nom.
Loyal Member
Joined
Nov 30, 2007
Messages
299
Reaction score
9
Re: [Release] Error checking Routine for Mysql

I shall test it, when debugging i always come back with this error.

I figured that when people relogin RIGHT after they get kicked or log out, the whole server crashes.

Ohh, lots of errors.

------ Build started: Project: MapleStoryServer, Configuration: Release Win32 ------
Compiling...
MySQLM.cpp
.\MySQLM.cpp(160) : error C2065: 'mr' : undeclared identifier
.\MySQLM.cpp(160) : error C3861: 'ibuffer': identifier not found
.\MySQLM.cpp(161) : error C2065: 'buffer' : undeclared identifier
.\MySQLM.cpp(162) : error C2146: syntax error : missing ')' before identifier 'string'
.\MySQLM.cpp(162) : error C2059: syntax error : ';'
.\MySQLM.cpp(162) : error C2146: syntax error : missing ';' before identifier 'mr2'
.\MySQLM.cpp(162) : error C2275: 'std::string' : illegal use of this type as an expression
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xstring(2210) : see declaration of 'std::string'
.\MySQLM.cpp(162) : error C2065: 'mr2' : undeclared identifier
.\MySQLM.cpp(163) : error C2065: 'mr2' : undeclared identifier
.\MySQLM.cpp(164) : error C2065: 'i' : undeclared identifier
.\MySQLM.cpp(168) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\MySQLM.cpp(168) : error C2065: 'mres' : undeclared identifier
.\MySQLM.cpp(169) : error C2065: 'mres' : undeclared identifier
.\MySQLM.cpp(169) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\MySQLM.cpp(169) : error C2365: 'mysql_free_result' : redefinition; previous definition was 'function'
c:\documents and settings\chris wong\desktop\project khaos\maplestoryserver\mysql.h(529) : see declaration of 'mysql_free_result'
.\MySQLM.cpp(170) : error C2059: syntax error : 'return'
.\MySQLM.cpp(171) : error C2059: syntax error : '}'
.\MySQLM.cpp(171) : error C2143: syntax error : missing ';' before '}'
.\MySQLM.cpp(171) : error C2059: syntax error : '}'
.\MySQLM.cpp(173) : error C2143: syntax error : missing ';' before '{'
.\MySQLM.cpp(173) : error C2447: '{' : missing function header (old-style formal list?)
Drops.cpp
.\Drops.cpp(9) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
Build log was saved at "file://c:\Documents and Settings\Chris Wong\Desktop\Project Khaos\MapleStoryServer\Release\BuildLog.htm"
MapleStoryServer - 21 error(s), 1 warning(s)

Oh, the drops.cpp was my mistake.
But the others =3
 
Newbie Spellweaver
Joined
Apr 6, 2008
Messages
55
Reaction score
0
Re: [Release] Error checking Routine for Mysql

Which REV are you using, Innovative?
 
Junior Spellweaver
Joined
Oct 10, 2007
Messages
101
Reaction score
0
Re: [Release] Error checking Routine for Mysql

i dont see the lines
}
ret = (int)mysql_num_rows(mres);
return ret;
}
in my MySQLM.cpp o_O
 
Master Summoner
Joined
Apr 2, 2008
Messages
538
Reaction score
0
Re: [Release] Error checking Routine for Mysql

so does this pin point the cause of the crash/error or it prevents the crash/errors?
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

i dont see the lines
in my MySQLM.cpp o_O

The lines will be in there - I had to move some of the int ret; to nearer the top of the routines, so they had full scope in the routine.
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

so does this pin point the cause of the crash/error or it prevents the crash/errors?

What it does is reduce the number access violations caused by trying read data that has not been returned by the database.
 
Junior Spellweaver
Joined
Oct 10, 2007
Messages
101
Reaction score
0
Re: [Release] Error checking Routine for Mysql

i think ur script has 1 too many } 's
Code:
int MySQL::showEquips(int id, int equips[15][2]){
    MYSQL_RES *mres;
    MYSQL_ROW mrow;
    char query[255]; 
    int ret = 0;
    sprintf_s(query, 255, "SELECT equipid, type FROM equip WHERE (charid = %d AND pos<0);", id);
    mysql_real_query(&maple_db, query, strlen(query));
    mres = mysql_store_result(&MySQL::maple_db);
    if (mres == 0 ){
        printf_s("\n\rError in showEquips SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
        printf_s("SQL Query is : %s",query);
    }
    else {
        mrow = mysql_fetch_row(mres);
        for(int i=0; ibuffer(mr);
            buffer >> equips[i][0];
            string mr2 = string((char*)mrow[1]);
            istringstream buffer2(mr2);
            buffer2 >> equips[i][1];
            mrow = mysql_fetch_row(mres);
        }
    } <<<<<<[COLOR="Red"] here :O![/COLOR]
    ret = (int)mysql_num_rows(mres);
    mysql_free_result(mres);
    return ret;
}
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

I shall test it, when debugging i always come back with this error.

I figured that when people relogin RIGHT after they get kicked or log out, the whole server crashes.

Ohh, lots of errors.

------ Build started: Project: MapleStoryServer, Configuration: Release Win32 ------
Compiling...
MySQLM.cpp
.\MySQLM.cpp(160) : error C2065: 'mr' : undeclared identifier
.\MySQLM.cpp(160) : error C3861: 'ibuffer': identifier not found
.\MySQLM.cpp(161) : error C2065: 'buffer' : undeclared identifier
.\MySQLM.cpp(162) : error C2146: syntax error : missing ')' before identifier 'string'
.\MySQLM.cpp(162) : error C2059: syntax error : ';'
.\MySQLM.cpp(162) : error C2146: syntax error : missing ';' before identifier 'mr2'
.\MySQLM.cpp(162) : error C2275: 'std::string' : illegal use of this type as an expression
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xstring(2210) : see declaration of 'std::string'
.\MySQLM.cpp(162) : error C2065: 'mr2' : undeclared identifier
.\MySQLM.cpp(163) : error C2065: 'mr2' : undeclared identifier
.\MySQLM.cpp(164) : error C2065: 'i' : undeclared identifier
.\MySQLM.cpp(168) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\MySQLM.cpp(168) : error C2065: 'mres' : undeclared identifier
.\MySQLM.cpp(169) : error C2065: 'mres' : undeclared identifier
.\MySQLM.cpp(169) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\MySQLM.cpp(169) : error C2365: 'mysql_free_result' : redefinition; previous definition was 'function'
c:\documents and settings\chris wong\desktop\project khaos\maplestoryserver\mysql.h(529) : see declaration of 'mysql_free_result'
.\MySQLM.cpp(170) : error C2059: syntax error : 'return'
.\MySQLM.cpp(171) : error C2059: syntax error : '}'
.\MySQLM.cpp(171) : error C2143: syntax error : missing ';' before '}'
.\MySQLM.cpp(171) : error C2059: syntax error : '}'
.\MySQLM.cpp(173) : error C2143: syntax error : missing ';' before '{'
.\MySQLM.cpp(173) : error C2447: '{' : missing function header (old-style formal list?)
Drops.cpp
.\Drops.cpp(9) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
Build log was saved at "file://c:\Documents and Settings\Chris Wong\Desktop\Project Khaos\MapleStoryServer\Release\BuildLog.htm"
MapleStoryServer - 21 error(s), 1 warning(s)

Oh, the drops.cpp was my mistake.
But the others =3

Did you copy the whole thing in ? ,as it was only the red lines that needed adding.
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

i think ur script has 1 too many } 's
Code:
int MySQL::showEquips(int id, int equips[15][2]){
    MYSQL_RES *mres;
    MYSQL_ROW mrow;
    char query[255]; 
    int ret = 0;
    sprintf_s(query, 255, "SELECT equipid, type FROM equip WHERE (charid = %d AND pos<0);", id);
    mysql_real_query(&maple_db, query, strlen(query));
    mres = mysql_store_result(&MySQL::maple_db);
    if (mres == 0 ){
        printf_s("\n\rError in showEquips SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
        printf_s("SQL Query is : %s",query);
    }
    else {
        mrow = mysql_fetch_row(mres);
        for(int i=0; ibuffer(mr);  [COLOR=Red]{[/COLOR]    [COLOR=Red]<<<<< methinks yours has one too few here[/COLOR]
            buffer >> equips[i][0];
            string mr2 = string((char*)mrow[1]);
            istringstream buffer2(mr2);
            buffer2 >> equips[i][1];
            mrow = mysql_fetch_row(mres);
        }
    } <<<<<<[COLOR=Red] here :O![/COLOR]
    ret = (int)mysql_num_rows(mres);
    mysql_free_result(mres);
    return ret;
}


Yours has 1 open brace missing =]
 
Junior Spellweaver
Joined
Oct 10, 2007
Messages
101
Reaction score
0
Re: [Release] Error checking Routine for Mysql

i dont think so :D i copy and pasted your code ;3
 
Experienced Elementalist
Joined
Apr 8, 2008
Messages
203
Reaction score
29
Re: [Release] Error checking Routine for Mysql

for(int i=0; i<mysql_num_rows(mres); i++){

The original line from first post

infact the code around that area in yours looks wrong - there are parts missing.

your code from your post:

mrow = mysql_fetch_row(mres);
for(int i=0; ibuffer(mr);
buffer >> equips[0];
string mr2 = string((char*)mrow[1]);
istringstream buffer2(mr2);
buffer2 >> equips[1];
mrow = mysql_fetch_row(mres);


My original posting:

mrow = mysql_fetch_row(mres);
for(int i=0; i<mysql_num_rows(mres); i++){
string mr = string((char*)mrow[0]);
istringstream buffer(mr);
buffer >> equips[0];
string mr2 = string((char*)mrow[1]);
istringstream buffer2(mr2);
buffer2 >> equips[1];
mrow = mysql_fetch_row(mres);
 
Junior Spellweaver
Joined
Oct 10, 2007
Messages
101
Reaction score
0
Re: [Release] Error checking Routine for Mysql

uhm.. strange but it seems everytime u refresh , the code changes , then changes back o_O
first its
Code:
int MySQL::showEquips(int id, int equips[15][2]){
    MYSQL_RES *mres;
    MYSQL_ROW mrow;
    char query[255]; 
    int ret = 0;   <<<< this line moves in some routines
    sprintf_s(query, 255, "SELECT equipid, type FROM equip WHERE (charid = %d AND pos<0);", id);
    mysql_real_query(&maple_db, query, strlen(query));
    mres = mysql_store_result(&MySQL::maple_db);
    if (mres == 0 ){
        printf_s("\n\rError in showEquips SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
        printf_s("SQL Query is : %s",query);
    }
    else {
        mrow = mysql_fetch_row(mres);
        for(int i=0; i<mysql_num_rows(mres); i++){
            string mr = string((char*)mrow[0]);
            istringstream buffer(mr);
            buffer >> equips[i][0];
            string mr2 = string((char*)mrow[1]);
            istringstream buffer2(mr2);
            buffer2 >> equips[i][1];
            mrow = mysql_fetch_row(mres);
        }
    }
    ret = (int)mysql_num_rows(mres);  <<<add  line if not there
    mysql_free_result(mres);
    return ret;
}

then its
Code:
int MySQL::showEquips(int id, int equips[15][2]){
    MYSQL_RES *mres;
    MYSQL_ROW mrow;
    char query[255]; 
    int ret = 0;   <<<< this line moves in some routines
    sprintf_s(query, 255, "SELECT equipid, type FROM equip WHERE (charid = %d AND pos<0);", id);
    mysql_real_query(&maple_db, query, strlen(query));
    mres = mysql_store_result(&MySQL::maple_db);
    if (mres == 0 ){
        printf_s("\n\rError in showEquips SQL returned no rows (Mysql_error: %s)",mysql_error(&maple_db)); 
        printf_s("SQL Query is : %s",query);
    }
    else {
        mrow = mysql_fetch_row(mres);
        for(int i=0; ibuffer(mr);
            buffer >> equips[i][0];
            string mr2 = string((char*)mrow[1]);
            istringstream buffer2(mr2);
            buffer2 >> equips[i][1];
            mrow = mysql_fetch_row(mres);
        }
    }
    ret = (int)mysql_num_rows(mres);  <<<add  line if not there
    mysql_free_result(mres);
    return ret;
}

first one seems to compile fine tho.
 
Master Summoner
Joined
Apr 2, 2008
Messages
538
Reaction score
0
Re: [Release] Error checking Routine for Mysql

One error:
Code:
c:\documents and settings\compaq_owner\desktop\titanmsver007\maplestoryserver\maplestoryserver\mysqlm.cpp(170) : error C2059: syntax error : '='
 
Back
Top