Goland using MySQL to return the use of stored procedures
Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Got a lot on the web about Goland using MySQL to return stored procedures with return values, MySQL on golandgit does not support stored procedures in an exec, only one exec, another query to fetch the results, This can not be high concurrency of the case to ensure that the results of the Select is correct, for this experiment a lot of methods, and finally only this method, the specific look at the figure Goland mysql execution stored procedures do not support multiple return sets, with query in multiple return values when the result set code is as follows: rows, _: = db. Query (FMT. Sprintf ("Call Usp_activeaccount ('%s ', '%s ')", "t22ss33t111", "123456")) for rows. Next () {var result stringvar AccountId introws. Scan (&result, &accountid) fmt. PRINTLN (Result) fmt. Println (AccountId)} This is a result set that can be taken, but must be usp_activeaccount this stored procedure select returns only one, not multiple select result sets, depending on my stored procedure: ' Sqlcreate definer= ' root ' @ ' localhost ' PROCEDURE ' usp_activeaccount ' (in userid varchar (+), in password varchar) begin SET @ AccountId =-1; Set @result = ' 0000 '; if @result = ' 0000 ' and exists (select 1 from Tbl_account A where a.accountname = userid) thenset @result = ' 0002 '; end if; if @result = ' 0000 ' then--Start transaction--Beginif NOT EXISTS (select @accountid: = A.accountid from Tbl_account A where A.accountnam e = userid) then--because the go language only supports a select, it can only be solved with exist-select @accountid:= A.accountid from Tbl_account A where a.accountname = userid--if found_rows () = 0 then--Start inserting account information insert into Tbl_a Ccount (Accountname,password) Select USERID,MD5 (password), if row_count () = 1 Thenset @accountid = @ @IDENTITY; Elseset @ result = ' 0003 '; end if;end if;if @result = ' 0000 ' thencommit;elserollback;end if;end if; Select @result, @accountid; end "Supplements also have the kind is to use GO statement directly, is consumes the performance code as follows: DB. Exec (FMT. Sprintf ("Call Usp_login ('%s ', '%s ')", "A1A", "123456")) rows,_:= db. Query ("Select @result, @accountid") defer rows. Close () for rows. Next () {var result stringvar accountid Interr: = rows. Scan (&result, &accountid) if err! = Nil {//fmt. Println ("Ssssssssssssssssssssssssssss")}//fmt. Println (result, AccountId)}*/TX, _:= db. Begin () Tx. Query ("Select A.accountid,")/*_, err: = Tx. Exec (FMT. Sprintf ("Call Usp_login ('%s ', '%s ')", "A1A", "123456"))) if err! = Nil {fmt. Println ("Ssssssssssssssssssssssssssss")}rows,_:= TX. Query ("Select @result, @accountid") defer rows. Close () for rows. Next () {var result stringvarAccountId Interr: = rows. Scan (&result, &accountid) if err! = Nil {fmt. Println ("Ssssssssssssssssssssssssssss")}//fmt. Println (result, AccountId)}*/tx.commit () Performance test table: 10,000 times sql, 8 seconds 423 reads ∙ 1 likes
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service