Note that there are some explanatory texts on larger screens.

plurals
  1. POcall and get return value from stored mysql function using a mysql prepared command by c#
    primarykey
    data
    text
    <p>I believe my first post was not clear enough so I rewrite, here it is:</p> <p>I have a stored function in MySql. I want to call this stored function via Prearped MySqlCommand. I create a mysql command which can call stored function and prepare it. Aftwerwards I set my parameter values and call this stored function. Function works without error, but I just cannt get return value. How can I have my return value?</p> <p>This is not a performance issue, I have an implemantation which prepares all statements at startup. Now I wanna add these functiality to stored procedured and functions.</p> <hr> <p>Here is my stored function:</p> <pre><code>FUNCTION `RenameCharacter`(pUserKey varchar(50), pPlayerId int, pCharacterId int, pCharacterName varchar(50)) RETURNS int(11) </code></pre> <p>In order to call a mysql stored function, first I create a mysqlcommand:</p> <pre><code>commandString = new MBCommandString(); commandString.commandName = "RenameCharacter"; commandString.commandString = "RenameCharacter"; /*@"Update characters set name = ?3 where characterId = ?2 and playerId = (Select playerId from players where lastKey = ?1)";*/ commandString.parameters = new MySqlParameter[5]; commandString.parameters[1] = new MySqlParameter("pUserKey", MySqlDbType.VarChar); commandString.parameters[2] = new MySqlParameter("pPlayerId", MySqlDbType.Int32); commandString.parameters[3] = new MySqlParameter("pCharacterId", MySqlDbType.Int32); commandString.parameters[4] = new MySqlParameter("pCharacterName", MySqlDbType.VarChar); commandString.parameters[0] = new MySqlParameter("@returnValue", MySqlDbType.Int32); commandString.parameters[0].Direction = ParameterDirection.ReturnValue; commandString.type = MBCommandType.MBCT_Function; commandList.Add(commandString); </code></pre> <p>Then I prepare it:</p> <pre><code>MBCommand cmd = new MBCommand(); cmd.command = new MySqlCommand(cs.commandString, connection); cmd.command.Parameters.AddRange(cs.parameters); if (cs.type == MBCommandType.MBCT_Function) { cmd.command.CommandType = CommandType.StoredProcedure; } cmd.command.Prepare(); cmd.type = cs.type; commands.Add(cs.commandName, cmd); </code></pre> <p>And I call it using a class c#, function works but I cannot get the return value:</p> <pre><code>string key = reader.ReadString(); int playerId = reader.ReadInt32(); int characterId = reader.ReadInt32(); string characterNewName = reader.ReadString(); MBExecuteSingle execute = new MBExecuteSingle(); execute.commandName = "RenameCharacter"; execute.values = new object[5]; execute.values[1] = key; execute.values[2] = playerId; execute.values[3] = characterId; execute.values[4] = characterNewName; execute.values[0] = new Int32(); execute.values[0] = 4; //dummy initial value </code></pre> <p>What's missing why I cannot have return value? Thank you all..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload