Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day everyone !

i have a mysql stored procedure that should loop through an arbitrary array of strings (so to speak). here's it:
SQL
CREATE PROCEDURE StupidProcedure (INOUT Stringarray VARCHAR(100), IN msg VARCHAR (100) )

BEGIN

         /*Table loop variable*/
          DECLARE indx INT;
          DECLARE len INT;
          DECLARE valu INT;

          SET @indx = 0;
          SET @len = 0;

          WHILE LOCATE(',', @Stringarray , @indx + 1) > 0 DO
              SET @len = LOCATE(',', @Stringarray , @indx + 1) - @indx;
              SET @valu = SUBSTRING(@Stringarray , @indx, @len);

              SELECT CONCAT(@msg, @valu) INTO msg;      /* For Debugging purpose*/

              SET @indx = LOCATE(',', @Stringarray , @indx + @len) + 1; /*increment loop*/

           END WHILE; 
                 
END
Now, i needed to be sure that concatenated @msg has received all data in @Stringarray after the loop. Using php, i simply did this:
$StupidArray = "Boys, are, not, smiling, at, all,";
 

if (!$db->query(" SET @msg = ''; SET @Stringarray = '\' $StupidArray '\'; " ) || !$db->query(" CALL StupidProcedure (@Stringarray, @msg)") ){
                
                echo "CALL to StupidProcedure failed:".print_r($db->errorInfo()); 
                
  }else{
        $res = $db->query("SELECT @msg as _p_out");
        $row = $res->fetch();
        print_r($row['_p_out']);
}
What i got in return was 'all', the last is $StupidArray. what am i doing wroing ? OR is it my loop thats failing ?

thanks. 
Posted
Updated 16-Jun-15 6:04am
v2
Comments
virusstorm 16-Jun-15 12:03pm    
I'm having a hard time understanding your problem, but if I'm reading everything correctly, the variable @msg doesn't have all the data from @Stringarray.

If that is correct, I believe simply changing this:
SELECT CONCAT(@msg, @valu) INTO msg;
To this:
SET @msg = CONCAT(@msg, @valu);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900