Raised This Month: $51 Target: $400
 12% 

Getting MySQL Function return


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 05-25-2018 , 12:01   Getting MySQL Function return
Reply With Quote #1

Hi, my doubt is how can I get the return value of a MySQL function and if it's possible.

Thanks!
Santi. is offline
sdz
Senior Member
Join Date: Feb 2012
Old 05-27-2018 , 22:03   Re: Getting MySQL Function return
Reply With Quote #2

look into this https://sm.alliedmods.net/new-api/dbi/DBResultSet
and this https://wiki.alliedmods.net/SQL_(SourceMod_Scripting)
sdz is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 06-03-2018 , 04:06   Re: Getting MySQL Function return
Reply With Quote #3

Thanks, but I'm having problems to get the result of a MySQL Stored Procedure specifically.
Santi. is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 06-03-2018 , 04:14   Re: Getting MySQL Function return
Reply With Quote #4

My SP:
Code:
`sp_load_characters`(steam_id INT)
BEGIN
	SELECT c.id, c.name, c.level, c.reset 
    FROM Players p RIGHT JOIN Characters c ON (p.id = c.idPlayer) 
    WHERE p.steamid = steam_id;
END
Code:
Code:
int steamid = GetSteamAccountID(client);
	
	char error[255];
	Database db = SQL_DefConnect(error, sizeof(error));
	DBStatement hUserStmt = null;
	if (db == null){
		PrintToServer("Could not connect: %s", error);
	}
	
	
	/* Check if we haven't already created the statement */
	if (hUserStmt == null){
		char error2[255];
		hUserStmt = SQL_PrepareQuery(db, "CALL sp_load_characters(?)", error2, sizeof(error2));
		if (hUserStmt == null){
			PrintToServer(error2);
			
			delete hUserStmt;
			delete db;
			
			return Plugin_Handled;
		}
	}
	SQL_BindParamInt(hUserStmt, 0, steamid, false);
	if (!SQL_Execute(hUserStmt)){
		char errorr[255];
		SQL_GetError(hUserStmt, errorr, sizeof(errorr));
		PrintToServer(errorr);
		delete hUserStmt;
		delete db;
		
		return Plugin_Handled;
	}
	
	
	
	int rows = SQL_GetRowCount(query); 
	PrintToServer("%d", rows); //returns 0
	
	delete hUserStmt;
	delete db;
	return Plugin_Handled;
If I run the query on MySQL Workbench it returns the select result. But when I call it from the plugin it returns nothing
Santi. is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-03-2018 , 11:55   Re: Getting MySQL Function return
Reply With Quote #5

SourceMod's MySQL extension only supports a single result set per query - CALL always returns multiple so does not work.
__________________
asherkin is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 06-03-2018 , 17:11   Re: Getting MySQL Function return
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
SourceMod's MySQL extension only supports a single result set per query - CALL always returns multiple so does not work.
Thanks you asherkin.

Will it support multiple resultsets in the future?
Santi. is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-03-2018 , 17:16   Re: Getting MySQL Function return
Reply With Quote #7

If someone wanted to coordinate with one of the devs and submit a PR to implement it, it could happen. Otherwise probably not.
Fyren is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 06-04-2018 , 00:31   Re: Getting MySQL Function return
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
If someone wanted to coordinate with one of the devs and submit a PR to implement it, it could happen. Otherwise probably not.
I would like to help. But Idk who to talk with

Last edited by Santi.; 06-04-2018 at 00:32.
Santi. is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-04-2018 , 02:20   Re: Getting MySQL Function return
Reply With Quote #9

Doing the actual implementation would be writing code in C++. I have no idea if that's within your ability. (It wouldn't be for most SM users; anyone could learn but this wouldn't be a good first project.) If it is, then either find any of the devs on IRC or make an issue on Github.
Fyren is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 06-04-2018 , 10:28   Re: Getting MySQL Function return
Reply With Quote #10

Quote:
Originally Posted by Fyren View Post
Doing the actual implementation would be writing code in C++. I have no idea if that's within your ability. (It wouldn't be for most SM users; anyone could learn but this wouldn't be a good first project.) If it is, then either find any of the devs on IRC or make an issue on Github.
Thanks Fyren, I'll try to resolve this.
Santi. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode