View Single Post
  #1  
Old 07-12-2011, 09:19 AM
Criimson
Hill Giant
 
Join Date: Sep 2006
Posts: 172
Default Reading data from DB

Hello everyone

So I am trying to learn how to read data from the DB and use it as a check in the bot ai.

I looked over other areas where data is being read and I thought I had it, but after trying several different ways I have decided to once again ask for some help.

Here is the code:

Code:
if(IsEffectInSpell(selectedBotSpell.SpellId, SE_Rune)){
			std::string errorMessage;
			char* Query = 0;
			char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
			MYSQL_RES* DatasetResult;
			MYSQL_ROW value;

			if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT values FROM bot_variables WHERE bot_variable = 'auto_rune';", TempErrorMessageBuffer, &DatasetResult))) {
				errorMessage = std::string(TempErrorMessageBuffer);
			}
						
			value = mysql_fetch_row(DatasetResult);
			int iAR = atoi(value[0]);
			if (iAR == 0){
				continue;
			}
		}
The table is very simple.
TABLE : bot_variables
Column 1: bot_variable
Column 2: values
Column 3: notes

I had very little trouble learning how to write to the DB, but extracting the information is giving me problems. From what I can tell the problem is arising from one of two things.
Option 1: values are stored as a text string and I am trying to use it as an int. However, I also tried running a check based on a string using if (sAR == '0'){ and that also didn't work.

Which leads me to think that
Option 2: I am not correctly grasping how
MYSQL_RES* DatasetResult;
MYSQL_ROW value;
mysql_fetch_row(DatasetResult);
works.

Any help would be appreciated. Good thing about programming is once you learn how something works you can do it as long as you keep practicing.

Criimson
Reply With Quote