Jump to content

Select table value function


Recommended Posts

Hello guys, I wrote a function to select the value from a table field (has default value set to 0)

 

ced7fce503bd3f6c3c17595546d0fef6.png

function check_security()
	local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."")
	return a.security_status[1]
end

the function gives this error in syserr

attempt to index field `security_status' (a nil value)

and this kinda works, but it's not getting the default value of the field (0) - it shows else even if the value in the field is 0

function check_security()
	local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."")
	return security_status
end
if check_security() == 0 then
	say("VALUE 0")
else 
	say("OTHER VALUE")
end

Kind Regards, DaNy3LL

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

int query_select(lua_State* L)
	{
		SQLMsg * pMsg = DBManager::instance().DirectQuery(lua_tostring(L, 1));
		if (pMsg != NULL)
		{
			if (pMsg->Get()->uiNumRows == 0)
			{
				M2_DELETE(pMsg);
				return 0;
			}

			MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
			long long wynik_query = 0;
			str_to_number(wynik_query, row[0]);

			M2_DELETE(pMsg);

			lua_pushnumber(L, wynik_query);

			return 1;
		}
		return 0;
	}

return query_select("select security_code from account.account where id = "..pc.get_account_id()..";")

  • Love 2
Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • 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.