mysql2 0.4.2 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfe50d56c4b02379320402f6c9a50e1c004855b1
4
- data.tar.gz: 495a7a40b1a1fc006e8f3816b0b215c8a82f4585
3
+ metadata.gz: 75b3d925930b92cf7b1a36fa196d334e245919ac
4
+ data.tar.gz: 2bbe0a78b156f8c5b59643c4d57a7ce19b764bcc
5
5
  SHA512:
6
- metadata.gz: 076e0ae48e790418cc2272bf14f3f93859b751452eeaaefd43537a22266bf5cab6d443645b06d2e3bcaab3be2768e65bc5b699bb5e100e10e5a35911d4e96c33
7
- data.tar.gz: b921cb3b96ef7428db4870ca82719a52b7921d24fed356ba6765ff1890a98ae8c0c1351e8c158fa098d8652aebf4b958ec1cb3eeb46ff2e8c2b9e58d69dde1d7
6
+ metadata.gz: 602f336b5ed83421862b9dec36a9ddbd477dcbacc3ef16d58d5252072dba0bc7f7a955000482414eda1d104bda72ded87f3f4c795f8b4b4d36999bc6ee171e4b
7
+ data.tar.gz: 20281fda66cf4595edc05ac6a933d5f641c2f9f87771e8ace1e9de00902ecea54ddbc2d1b743c3dbd97b48c795d0ad32f9ab785e5848a4f3de92c7ddebeef659
data/README.md CHANGED
@@ -85,6 +85,9 @@ You may use MacPorts, Homebrew, or a native MySQL installer package. The most
85
85
  common paths will be automatically searched. If you want to select a specific
86
86
  MySQL directory, use the `--with-mysql-dir` or `--with-mysql-config` options above.
87
87
 
88
+ If you have not done so already, you will need to install the XCode select tools by running
89
+ `xcode-select --install`.
90
+
88
91
  ### Windows
89
92
  Make sure that you have Ruby and the DevKit compilers installed. We recommend
90
93
  the [Ruby Installer](http://rubyinstaller.org) distribution.
@@ -109,7 +112,7 @@ Connect to a database:
109
112
  ``` ruby
110
113
  # this takes a hash of options, almost all of which map directly
111
114
  # to the familiar database.yml in rails
112
- # See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html
115
+ # See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Mysql2Adapter.html
113
116
  client = Mysql2::Client.new(:host => "localhost", :username => "root")
114
117
  ```
115
118
 
@@ -164,8 +167,8 @@ by the query like this:
164
167
  ``` ruby
165
168
  headers = results.fields # <= that's an array of field names, in order
166
169
  results.each(:as => :array) do |row|
167
- # Each row is an array, ordered the same as the query results
168
- # An otter's den is called a "holt" or "couch"
170
+ # Each row is an array, ordered the same as the query results
171
+ # An otter's den is called a "holt" or "couch"
169
172
  end
170
173
  ```
171
174
 
@@ -203,12 +206,25 @@ Mysql2::Client.new(
203
206
  :reconnect = true/false,
204
207
  :local_infile = true/false,
205
208
  :secure_auth = true/false,
209
+ :ssl_mode = :disabled / :preferred / :required / :verify_ca / :verify_identity,
206
210
  :default_file = '/path/to/my.cfg',
207
211
  :default_group = 'my.cfg section',
208
212
  :init_command => sql
209
213
  )
210
214
  ```
211
215
 
216
+ ### Connecting to MySQL on localhost and elsewhere
217
+
218
+ The underlying MySQL client library uses the `:host` parameter to determine the
219
+ type of connection to make, with special interpretation you should be aware of:
220
+
221
+ * An empty value or `"localhost"` will attempt a local connection:
222
+ * On Unix, connect to the default local socket path. (To set a custom socket
223
+ path, use the `:socket` parameter).
224
+ * On Windows, connect using a shared-memory connection, if enabled, or TCP.
225
+ * A value of `"."` on Windows specifies a named-pipe connection.
226
+ * An IPv4 or IPv6 address will result in a TCP connection.
227
+ * Any other value will be looked up as a hostname for a TCP connection.
212
228
 
213
229
  ### SSL options
214
230
 
@@ -231,47 +247,6 @@ Mysql2::Client.new(
231
247
  )
232
248
  ```
233
249
 
234
- ### Multiple result sets
235
-
236
- You can also retrieve multiple result sets. For this to work you need to
237
- connect with flags `Mysql2::Client::MULTI_STATEMENTS`. Multiple result sets can
238
- be used with stored procedures that return more than one result set, and for
239
- bundling several SQL statements into a single call to `client.query`.
240
-
241
- ``` ruby
242
- client = Mysql2::Client.new(:host => "localhost", :username => "root", :flags => Mysql2::Client::MULTI_STATEMENTS)
243
- result = client.query('CALL sp_customer_list( 25, 10 )')
244
- # result now contains the first result set
245
- while client.next_result
246
- result = client.store_result
247
- # result now contains the next result set
248
- end
249
- ```
250
-
251
- Repeated calls to `client.next_result` will return true, false, or raise an
252
- exception if the respective query erred. When `client.next_result` returns true,
253
- call `client.store_result` to retrieve a result object. Exceptions are not
254
- raised until `client.next_result` is called to find the status of the respective
255
- query. Subsequent queries are not executed if an earlier query raised an
256
- exception. Subsequent calls to `client.next_result` will return false.
257
-
258
- ``` ruby
259
- result = client.query('SELECT 1; SELECT 2; SELECT A; SELECT 3')
260
- p result.first
261
-
262
- while client.next_result
263
- result = client.store_result
264
- p result.first
265
- end
266
- ```
267
-
268
- Yields:
269
- ```
270
- {"1"=>1}
271
- {"2"=>2}
272
- next_result: Unknown column 'A' in 'field list' (Mysql2::Error)
273
- ```
274
-
275
250
  ### Secure auth
276
251
 
277
252
  Starting wih MySQL 5.6.5, secure_auth is enabled by default on servers (it was disabled by default prior to this).
@@ -328,6 +303,47 @@ It is useful if you want to provide session options which survive reconnection.
328
303
  Mysql2::Client.new(:init_command => "SET @@SESSION.sql_mode = 'STRICT_ALL_TABLES'")
329
304
  ```
330
305
 
306
+ ### Multiple result sets
307
+
308
+ You can also retrieve multiple result sets. For this to work you need to
309
+ connect with flags `Mysql2::Client::MULTI_STATEMENTS`. Multiple result sets can
310
+ be used with stored procedures that return more than one result set, and for
311
+ bundling several SQL statements into a single call to `client.query`.
312
+
313
+ ``` ruby
314
+ client = Mysql2::Client.new(:host => "localhost", :username => "root", :flags => Mysql2::Client::MULTI_STATEMENTS)
315
+ result = client.query('CALL sp_customer_list( 25, 10 )')
316
+ # result now contains the first result set
317
+ while client.next_result
318
+ result = client.store_result
319
+ # result now contains the next result set
320
+ end
321
+ ```
322
+
323
+ Repeated calls to `client.next_result` will return true, false, or raise an
324
+ exception if the respective query erred. When `client.next_result` returns true,
325
+ call `client.store_result` to retrieve a result object. Exceptions are not
326
+ raised until `client.next_result` is called to find the status of the respective
327
+ query. Subsequent queries are not executed if an earlier query raised an
328
+ exception. Subsequent calls to `client.next_result` will return false.
329
+
330
+ ``` ruby
331
+ result = client.query('SELECT 1; SELECT 2; SELECT A; SELECT 3')
332
+ p result.first
333
+
334
+ while client.next_result
335
+ result = client.store_result
336
+ p result.first
337
+ end
338
+ ```
339
+
340
+ Yields:
341
+ ```
342
+ {"1"=>1}
343
+ {"2"=>2}
344
+ next_result: Unknown column 'A' in 'field list' (Mysql2::Error)
345
+ ```
346
+
331
347
  ## Cascading config
332
348
 
333
349
  The default config hash is at:
@@ -398,6 +414,15 @@ client = Mysql2::Client.new
398
414
  result = client.query("SELECT * FROM table_with_boolean_field", :cast_booleans => true)
399
415
  ```
400
416
 
417
+ Keep in mind that this works only with fields and not with computed values, e.g. this result will contain `1`, not `true`:
418
+
419
+ ``` ruby
420
+ client = Mysql2::Client.new
421
+ result = client.query("SELECT true", :cast_booleans => true)
422
+ ```
423
+
424
+ CAST function wouldn't help here as there's no way to cast to TINYINT(1). Apparently the only way to solve this is to use a stored procedure with return type set to TINYINT(1).
425
+
401
426
  ### Skipping casting
402
427
 
403
428
  Mysql2 casting is fast, but not as fast as not casting data. In rare cases where typecasting is not needed, it will be faster to disable it by providing :cast => false. (Note that :cast => false overrides :cast_booleans => true.)
@@ -484,20 +509,21 @@ As for field values themselves, I'm workin on it - but expect that soon.
484
509
 
485
510
  This gem is tested with the following Ruby versions on Linux and Mac OS X:
486
511
 
487
- * Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x
512
+ * Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x
488
513
  * Ruby Enterprise Edition (based on MRI 1.8.7)
489
- * Rubinius 2.x
514
+ * Rubinius 2.x and 3.x do work but may fail under some workloads
490
515
 
491
516
  This gem is tested with the following MySQL and MariaDB versions:
492
517
 
493
- * MySQL 5.5, 5.7
518
+ * MySQL 5.5, 5.6, 5.7, 8.0
494
519
  * MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
495
- * MariaDB 5.5, 10.0
520
+ * MariaDB 5.5, 10.0, 10.1
496
521
 
497
- ### Active Record
522
+ ### Ruby on Rails / Active Record
498
523
 
499
- * mysql2 0.2.x includes an Active Record driver compatible with AR 2.3 and 3.0
500
- * mysql2 0.3.x does not include an AR driver because it is included in AR 3.1 and above
524
+ * mysql2 0.4.x works with Rails / Active Record 4.2.5 - 5.0 and higher.
525
+ * mysql2 0.3.x works with Rails / Active Record 3.1, 3.2, 4.x, 5.0.
526
+ * mysql2 0.2.x works with Rails / Active Record 2.3 - 3.0.
501
527
 
502
528
  ### Asynchronous Active Record
503
529