Skip to content

MySQL support for multiple result set from Stored Procedures #823

@Codes97

Description

@Codes97

Help us help you

  • I have checked that my issue doesn't exist yet.
  • I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
  • I can always reproduce the issue with the provided description below.

Environment

  • Operating System version: Ubuntu server 16.04 (But I'm pretty sure it happens on every os)
  • Game/AppID (with version if applicable): Counter-Strike: Global offensive (But I'm pretty sure it happens on every game that SourceMod Supports)
  • Current SourceMod version: 1.8.0
  • Current SourceMod snapshot: 6041
  • Current Metamod: Source snapshot: 1.10.7

Description

Like I say in the title, I'm needing the support of get results from MySQL DB Stored Procedures.
I asked first on https://forums.alliedmods.net/showthread.php?p=2595241#post2595241 and asherkin told me the problem is in the driver.

The actual driver supports a single result set per query and CALL always returns multiple so does not work.

In the post, I say I would like to help. But I'm not too familiar with C ++ syntax but I have experience with Java.
If there is something I can do please tell me.

Problematic Code (or Steps to Reproduce)

Stored Procedure:

`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:

 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;

Logs

No logs, just no resultset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions