@@ -66,7 +66,7 @@ files are. For example, if you unzipped the connector to c:\mysql-connector-c-6.
66
66
the gem like this:
67
67
68
68
gem install mysql2 -- --with-mysql-dir=c:\mysql-connector-c-6.1.1-win32
69
-
69
+
70
70
Finally, you must copy libmysql.dll from the lib subdirectory of your MySQL or MySQL connector directory into
71
71
your ruby\bin directory. In the above example, libmysql.dll would be located at
72
72
c:\mysql-connector-c-6.1.1-win32\lib .
@@ -182,20 +182,45 @@ Mysql2::Client.new(
182
182
183
183
### Multiple result sets
184
184
185
- You can also retrieve multiple result sets. For this to work you need to connect with
186
- flags ` Mysql2::Client::MULTI_STATEMENTS ` . Using multiple result sets is normally used
187
- when calling stored procedures that return more than one result set
185
+ You can also retrieve multiple result sets. For this to work you need to
186
+ connect with flags ` Mysql2::Client::MULTI_STATEMENTS ` . Multiple result sets can
187
+ be used with stored procedures that return more than one result set, and for
188
+ bundling several SQL statements into a single call to ` client.query ` .
188
189
189
190
``` ruby
190
- client = Mysql2 ::Client .new (:host => " localhost" , :username => " root" , :flags => Mysql2 ::Client ::MULTI_STATEMENTS )
191
- result = client.query( ' CALL sp_customer_list( 25, 10 )' )
191
+ client = Mysql2 ::Client .new (:host => " localhost" , :username => " root" , :flags => Mysql2 ::Client ::MULTI_STATEMENTS )
192
+ result = client.query(' CALL sp_customer_list( 25, 10 )' )
192
193
# result now contains the first result set
193
- while ( client.next_result)
194
- result = client.store_result
195
- # result now contains the next result set
194
+ while client.next_result
195
+ result = client.store_result
196
+ # result now contains the next result set
197
+ end
198
+ ```
199
+
200
+ Repeated calls to ` client.next_result ` will return true, false, or raise an
201
+ exception if the respective query erred. When ` client.next_result ` returns true,
202
+ call ` client.store_result ` to retieve a result object. Exceptions are not
203
+ raised until ` client.next_result ` is called to find the status of the respective
204
+ query. Subsequent queries are not executed if an earlier query raised an
205
+ exception.
206
+
207
+ ``` ruby
208
+ result = client.query(' SELECT 1; SELECT 2; SELECT A; SELECT 3' )
209
+ p result.first
210
+
211
+ while client.next_result
212
+ result = client.store_result
213
+ p result.first
196
214
end
197
215
```
198
216
217
+ Yields:
218
+ ```
219
+ {"1"=>1}
220
+ {"2"=>2}
221
+ next_result: Unknown column 'A' in 'field list' (Mysql2::Error)
222
+ ```
223
+
199
224
See https://gist.github.com/1367987 for using MULTI_STATEMENTS with Active Record.
200
225
201
226
### Secure auth
0 commit comments