Home > other >  Use golang xorm call mysql stored procedures problem
Use golang xorm call mysql stored procedures problem

Time:10-11

Program now do you need to call stored procedures of database, database operation I used xorm, calling a stored procedure has three input parameters (a, b, c) and two output parameters (out_1, out_2), I now need to the two output parameter values, but checked online method didn't work out, see online method has the following two kinds:
1. The res, err:=engine. The Exec (SQL, parameters... ) - this method tried, but the exec return res available LastInsertId () and RowsAffected () two results, but not what I want
2. The queryString, err: MySQL=(.) the queryString (" call user. Query_student (? ,? @ 1, @ 2, @ 3, 6) @ 4, 5, @ @ ", "Jerry", 1)
if err ! Nil={
The Println (" err: "err)
}

For k, v:=range the queryString [0] {
FMT. Printf (" columns, % v - value: % v \ n ", k, v)
}

- this way I also tried, but return the queryString is nil, can't again to get k, v

Try again today, found the method 2 in the storage process without a database operation, only under the condition of the query can be used, but I add records to the need to perform operations such as in the process, as long as after adding the insert into statement is, the returned the queryString are nil,

To ask the great spirit is there any other useful method?

PS: the last use stored procedures with the SELECT out_1, out_2;

CodePudding user response:

Try to source? To get what you want

CodePudding user response:

Rows, err:=engine. The DB (a). The Query (" stored procedures ", parameters)
Defer func () {
Err:=rows. The Close ()
if err ! Nil={
.
}
} ()
Rows. Next ()
//the results
Err=rows. Scan (& amp; X, & amp; Y)
  • Related