-
Notifications
You must be signed in to change notification settings - Fork 161
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
Is is possible to set mysql with "clientMultiStatements | clientMultiResults "? #89
Comments
I believe that it is impossible to obtain more than one result set using database/sql. mymysql sets CLIENT_MULTI_STATEMENTS and CLIENT_MULTI_RESULTS options for connection and you can read all results from multi-statement or procedure using mymysql specific interface but you can't do that using database/sql. For current database/sql specification I see only some possible workarounds (eg. specify option to always return N-th result) but any doesn't address this problem for all possible cases. |
I see.... And how to get mymysql's connection from database/sql layer? I saw your example 8, I suppose I have to get the connection "my" at first, but don't know where I can get it from. I'm so sorry to ask you so basic question ..... |
You can't get connection from database/sql. It automatically manages connections and can do what it want with them (eg. close unused connection) so it is bad idea to mes there. You can use both interfaces: import ( You should avoid import thrsafe engine because it replaces default native engine for database/sql too (this doesn't break anything but adds some unnecessary overhead because database/sql doesn't require thread-safety from a driver). Now you can: db1 := mysql.New("tcp", "", "127.0.0.1:3306", user, pass, dbname) db2, err2 := sql.Open("mymysql", "dbname/user/pass") and use db1 and db2 where appropriate: Of course, you should pay attention that db2 represents only one concrete connection, whereas db1 represents some dynamic pool of connections. This doesn't look good and it seems to not be a good programming practice. So it should be limited to some small module that provides database abstraction for other code and can be easy rewritten in the feature. |
Should be: "Of course, you should pay attention that db1 represents only one concrete connection, whereas db2 represents some dynamic pool of connections." And you should import some driver for database/sql (this can be "github.com/ziutek/mymysql/godrv" but you can use other too). |
Thank your instruction! I have connected to the db through database/sql/sql.go,: it will not a mymysql's connection; So my question should be: Is it possible to get a mymysql's connection from an opened sql.DB connection and how? |
Multiple connection isn't any problem. database/sql usually establishes more than one connection. Did you read database/sql documentation? My English is poor. Maybe you didn't understand what I wrote about database/sql connections. If you carefully read database/sql documentation you should understand that there is no way to obtain any connection from pool without hack its code. Even if you hack database/sql to obtain some connection from pool you should do it that way to effectively remove it from pool otherwise it can be unexpectedly closed or you can break it by concurrent use. |
I'm a newbie, :) I learn golang and revel in my leisure time since last month lonely, so I do not understand so many details ..... And you clarify all my doubts, thank you so much; (^^_) |
database/sql do not support multi record set yet;
so everything will failed once after a stored procedure is called;
I found go-sql-driver has already fixed this problem; the solution is to add two option clientMultiStatements | clientMultiResults;
Is there anyway to add such options in mymysql? That will let my project to use stored procedures from database/sql layer.
The text was updated successfully, but these errors were encountered: