Jump to content

Recommended Posts

Take a look at this example:

std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = 1"));

if (msg->Get()->uiNumRows == 0)
{
	return 0;
}

int coins = 0;

MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
str_to_number(coins, row[0]);
Link to comment
https://metin2.dev/topic/5081-cmysql_select-quest-function/#findComment-32041
Share on other sites

 

Take a look at this example:

std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = 1"));

if (msg->Get()->uiNumRows == 0)
{
	return 0;
}

int coins = 0;

MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
str_to_number(coins, row[0]);
char szQuery[512];
snprintf(szQuery,sizeof(szQuery),"SELECT coins FROM account WHERE id = %u",ch->GetAID());
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery,SQL_ACCOUNT));

if(pMsg->Get()->uiNumRows > 0)
{
	int iCoins = 0;
	MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
	str_to_number(iCoins,row[0]);
}

Kind Regards

Zerelth ~ Ellie

Do not be sorry, be better.

Link to comment
https://metin2.dev/topic/5081-cmysql_select-quest-function/#findComment-32042
Share on other sites

 

 

Take a look at this example:

std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = 1"));

if (msg->Get()->uiNumRows == 0)
{
	return 0;
}

int coins = 0;

MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
str_to_number(coins, row[0]);

char szQuery[512];
snprintf(szQuery,sizeof(szQuery),"SELECT coins FROM account WHERE id = %u",ch->GetAID());
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery,SQL_ACCOUNT));

if(pMsg->Get()->uiNumRows > 0)
{
	int iCoins = 0;
	MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
	str_to_number(iCoins,row[0]);
}

Kind Regards

Zerelth ~ Ellie

 

 

Your point?

Link to comment
https://metin2.dev/topic/5081-cmysql_select-quest-function/#findComment-32044
Share on other sites

 

 

 

Take a look at this example:

std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = 1"));

if (msg->Get()->uiNumRows == 0)
{
	return 0;
}

int coins = 0;

MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
str_to_number(coins, row[0]);

char szQuery[512];
snprintf(szQuery,sizeof(szQuery),"SELECT coins FROM account WHERE id = %u",ch->GetAID());
std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery,SQL_ACCOUNT));

if(pMsg->Get()->uiNumRows > 0)
{
	int iCoins = 0;
	MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
	str_to_number(iCoins,row[0]);
}

Kind Regards

Zerelth ~ Ellie

 

 

Your point?

 

 

Second way :)

Do not be sorry, be better.

Link to comment
https://metin2.dev/topic/5081-cmysql_select-quest-function/#findComment-32045
Share on other sites

  • Premium

Sure It's possible.

// Get the current character
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

// Something wen't wrong, character does not exist
if (!ch)
{
	// Push back -1 to the quest, which means there was an error
	lua_pushnumber(L, -1);
	return 1;
}

// Character don't have desc
if (!ch->GetDesc())
{
	// Push back -1 to the quest, which means there was an error
	lua_pushnumber(L, -1);
	return 1;
}

// Execute the query
std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("SELECT something FROM account.account WHERE id = %lu", ch->GetDesc()->GetAccountTable().id));

// Something was wrong with the query
if (msg->Get()->uiNumRows <= 0 || msg->uiSQLErrno != 0)
{
	// Push back -1 to the quest, which means there was an error
	lua_pushnumber(L, -1);
	return 1;
}

// Create a new lua table
lua_newtable(L);

// Row will contains the current line of data
MYSQL_ROW row;

// Lua indexing starts from 1, so the first index of the array should be 1
int idx   = 1;
// value contains the data of current field
int value = 0;
// While we have available data
while ((row = mysql_fetch_row(msg->Get()->pSQLResult)))
{
	if (!row[0])
		continue;

	// Push the index to the table
	lua_pushnumber(L, idx);
	// Convert the data of the field to number
	str_to_number(value, row[0]);
	// Push the data to the table
	lua_pushnumber(L, value);
	// We are pushing back a one dimensional array, so set the index of the table to -3
	lua_settable(L, -3);
	// Add +1 to the index
	idx++;
}

return 1;
  • Love 1
Link to comment
https://metin2.dev/topic/5081-cmysql_select-quest-function/#findComment-32052
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.