-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi Result support #66
Comments
Hi @emilsjolander, thanks for reporting this! |
I actually got them working by following the instructions in the last comment of this thread https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/raVDmAzkZ5U adding
to line 209 in packets.go |
@julienschmidt I can't really say what this does to the driver - e.g. when you really have multiple results per query, how do you get the next one with the current api? Can you determine if there's only one result returned by a stored procedure? My guess would be we can't include this, but I just don't know. Maybe yet another dsn switch for those who really need it? |
well i kinda knew it wasn't a fix, but i needed to quickly get a project for a school working ^^ |
Still, thanks @emilsjolander! Can you provide some code? Maybe we'll add it to the tests, we'll have to check/discuss this. |
I know about this issue. Does it work with There is no way to determine how many results the procedure produces. The |
Hi @emilsjolander, can you please test Juliens suggestion and get back to us? |
Did this issue fixed? I got same error when call procedure with code
The third parameter is output parameter, so I change code to following
I got another error "check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @sp_var_p2 = ?; " |
Go does not support multiple results in |
changed code to clientFlags := uint32( clientProtocol41 | clientSecureConn | clientLongPassword | clientTransactions | clientMultiStatements | clientMultiResults | // https://github.com/go-sql-driver/mysql/issues/66 clientLocalFiles, ) 1: it works CALL sp_query ( ?, ?, ? ); CREATE PROCEDURE `sp_query`(IN p1 INT, IN p2 varchar(100), p3 NUMERIC(10,4)) BEGIN SELECT p1, p2, p3; END 2: it works CALL sp_exec ( ?, ?, ? ); CREATE PROCEDURE `sp_exec`(IN p1 INT, IN p2 varchar(100), p3 NUMERIC(10,4)) BEGIN set p1 = 123; set p2 = "p2"; set p3 = 3.14; END 3: it dones't work SET @p2 = ?; CALL sp_exec_inout ( ?, @p2, @p3 ); SELECT @p2, @p3; CREATE PROCEDURE `sp_exec_inout`(IN p1 INT, INOUT p2 varchar(100), OUT p3 NUMERIC(10,4)) BEGIN set p1 = 123; set p2 = "p2"; set p3 = 3.14; END |
Does it need |
Any updates on this? I just used clientMultiStatements in the clientFlags and it works fine. I use this in https://github.com/mattes/migrate where usually just one SQL file with n sql commands is being executed. |
It's actually not working ok. Multiple
|
I have asked about returning result from stored procedure in #282 . But as @julienschmidt had answerd that adding As i want to call sp from go-sql-driver i want to ask how it is possible ? |
The driver does not support stored procedures because the Go api in |
Is there any movement on this issue as i really need to execute multiple statements. I'm not really fused about return multiple results as i'm just creating databases from SQL dumps. If this is not being implemented why not expose the |
I'm in a similar boat to you right now I'm reading the SQL from files on disk for the purposes of DB migrations and don't want to unnecessarily have separate files for each CREATE TABLE for example. So currently I'm working round the issue by ensuring each of my statements ends with a semi-colon and splitting on this in code using something similar to below. statement := "CREATE TABLE vendor(id INT); CREATE TABLE product(id INT);"
for _, s := range strings.Split(statement, ";") {
trimmed := strings.TrimSpace(s)
if len(trimmed) > 0 {
_, err := db.Exec(trimmed)
_ = err
}
} |
That is one solution if you have control over the SQL dumps. In my case the dumps contain SQL like this: DELIMITER $$
CREATE DEFINER=`gary`@`localhost` FUNCTION `hello_world`() RETURNS text CHARSET utf8 COLLATE utf8_bin
BEGIN
RETURN 'Hello World';
END$$
DELIMITER ; So splitting on semi-colons with result in errors. In the end i used this library: https://github.com/ziutek/mymysql which supports multi-statements while not adhering to the stdlib interface. |
I have just tried to use stored procedures statements (adding |
I think that i have reached a good point. |
@Idhor, facing the same problem still after cloning from your repo. Could you please brief a bit about with an small example. |
@hansiemithun var id int
country := "Italy"
row := db.QueryRow("CALL GetCountryId(?)", country)
if err := row.Scan(&id); err != nil {
return 0, err
} |
I have been able to consistently reproduce issue #314 by attempting to used the Use the following params to see the error in action: You need to preset a couple of stored procedures (see docs) and basically limit the # of connections to force them to be reused by the next query and the issue appears. I strongly suggest running this or a similar test before considering any such hack production ready, though @Idhor 's work looks the most promising. |
I think it would be good to at least enable the clientMultiStatements or clientMultiResults through the dsn params. this way, it will be an optional flag just like the interpolate params. UPDATE: |
- packets.go: flag clientMultiResults, update status when receiving an EOF packet, discard additional results on readRow when EOF is reached - statement.go: currently a nil rows.mc is used as an eof, don’t set it if there are no columns to avoid that Next() waits indefinitely - rows.go: discard additional results on close and avoid panic on Columns()
is this issue resolved? fix has been merged and availble? i am working in big web project and need to implement most in stored procedure. please someone confirm the fix is available. Thanks |
See #339. It seems to provide a working fix but it has not been merged yet. |
Thanks.is there any other work around to make it work other than cloning and editing source code and building, we dont want to use third party edited code. integration. Any help much appreciated. |
Hello guys, I know it's been a while since the 1st and last comment. As GO as been evolving, I think a lot of people are waiting for MySQL Stored Procedure Output with IN, INOUT parameters as mentionned @sdming in his 3rd example. So, is it impossible to do?, feasible? PS: I read this http://go-database-sql.org/surprises.html |
I don't have never used stored procedure/function. I don't have any interest. This is issue tracker, not user forum. |
The rudeness here is impressive! |
@PaluMacil You must read this article. Which project do you want to use?
|
I am getting the following error when calling on my stored procedure
I am calling on my stored procedure with this code
The text was updated successfully, but these errors were encountered: