mysql2 0.3.18 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +63 -12
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +170 -175
  8. data/ext/mysql2/client.h +21 -1
  9. data/ext/mysql2/extconf.rb +95 -35
  10. data/ext/mysql2/infile.c +2 -2
  11. data/ext/mysql2/mysql2_ext.c +1 -0
  12. data/ext/mysql2/mysql2_ext.h +5 -6
  13. data/ext/mysql2/mysql_enc_name_to_ruby.h +2 -2
  14. data/ext/mysql2/mysql_enc_to_ruby.h +25 -22
  15. data/ext/mysql2/result.c +494 -132
  16. data/ext/mysql2/result.h +12 -6
  17. data/ext/mysql2/statement.c +494 -0
  18. data/ext/mysql2/statement.h +19 -0
  19. data/lib/mysql2/client.rb +68 -22
  20. data/lib/mysql2/console.rb +1 -1
  21. data/lib/mysql2/em.rb +5 -6
  22. data/lib/mysql2/error.rb +18 -27
  23. data/lib/mysql2/field.rb +3 -0
  24. data/lib/mysql2/statement.rb +17 -0
  25. data/lib/mysql2/version.rb +1 -1
  26. data/lib/mysql2.rb +38 -18
  27. data/spec/em/em_spec.rb +21 -21
  28. data/spec/mysql2/client_spec.rb +393 -351
  29. data/spec/mysql2/error_spec.rb +37 -36
  30. data/spec/mysql2/result_spec.rb +213 -208
  31. data/spec/mysql2/statement_spec.rb +684 -0
  32. data/spec/spec_helper.rb +7 -0
  33. data/spec/ssl/ca-cert.pem +17 -0
  34. data/spec/ssl/ca-key.pem +27 -0
  35. data/spec/ssl/ca.cnf +22 -0
  36. data/spec/ssl/cert.cnf +22 -0
  37. data/spec/ssl/client-cert.pem +17 -0
  38. data/spec/ssl/client-key.pem +27 -0
  39. data/spec/ssl/client-req.pem +15 -0
  40. data/spec/ssl/gen_certs.sh +48 -0
  41. data/spec/ssl/pkcs8-client-key.pem +28 -0
  42. data/spec/ssl/pkcs8-server-key.pem +28 -0
  43. data/spec/ssl/server-cert.pem +17 -0
  44. data/spec/ssl/server-key.pem +27 -0
  45. data/spec/ssl/server-req.pem +15 -0
  46. data/support/mysql_enc_to_ruby.rb +7 -8
  47. data/support/ruby_enc_to_mysql.rb +1 -1
  48. metadata +41 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 791bc0352c6464ca1765498b0babcedfad3c284e
4
- data.tar.gz: 08b44b761494ec18a0c9903fcb67bfe61718b77b
3
+ metadata.gz: bfe50d56c4b02379320402f6c9a50e1c004855b1
4
+ data.tar.gz: 495a7a40b1a1fc006e8f3816b0b215c8a82f4585
5
5
  SHA512:
6
- metadata.gz: 5554897f395a4fcd71e26612ef895da5d3e1d528ef29604380974950f7216783bf7636197d04228c39b471a51863f75c56e9140e05bb79410e1582c64842d0dc
7
- data.tar.gz: afad060a7a899d69b75ca2c44aa69a07c743984fc6897cce825c6d9ec3269bbb3733671243afe7fb33a615e61e4aa8c7b9e7863fa18289578ab29abc8409e2e8
6
+ metadata.gz: 076e0ae48e790418cc2272bf14f3f93859b751452eeaaefd43537a22266bf5cab6d443645b06d2e3bcaab3be2768e65bc5b699bb5e100e10e5a35911d4e96c33
7
+ data.tar.gz: b921cb3b96ef7428db4870ca82719a52b7921d24fed356ba6765ff1890a98ae8c0c1351e8c158fa098d8652aebf4b958ec1cb3eeb46ff2e8c2b9e58d69dde1d7
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ Changes are maintained under [Releases](https://github.com/brianmario/mysql2/releases)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Brian Lopez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -9,12 +9,14 @@ This one is not.
9
9
 
10
10
  It also forces the use of UTF-8 [or binary] for the connection [and all strings in 1.9, unless Encoding.default_internal is set then it'll convert from UTF-8 to that encoding] and uses encoding-aware MySQL API calls where it can.
11
11
 
12
- The API consists of two classes:
12
+ The API consists of three classes:
13
13
 
14
14
  `Mysql2::Client` - your connection to the database.
15
15
 
16
16
  `Mysql2::Result` - returned from issuing a #query on the connection. It includes Enumerable.
17
17
 
18
+ `Mysql2::Statement` - returned from issuing a #prepare on the connection. Execute the statement to get a Result.
19
+
18
20
  ## Installing
19
21
  ### General Instructions
20
22
  ``` sh
@@ -56,6 +58,20 @@ This may be needed if you deploy to a system where these libraries
56
58
  are located somewhere different than on your build system.
57
59
  This overrides any rpath calculated by default or by the options above.
58
60
 
61
+ * `--with-sanitize[=address,cfi,integer,memory,thread,undefined]` -
62
+ Enable sanitizers for Clang / GCC. If no argument is given, try to enable
63
+ all sanitizers or fail if none are available. If a command-separated list of
64
+ specific sanitizers is given, configure will fail unless they all are available.
65
+ Note that the some sanitizers may incur a performance penalty, and the Address
66
+ Sanitizer may require a runtime library.
67
+ To see line numbers in backtraces, declare these environment variables
68
+ (adjust the llvm-symbolizer path as needed for your system):
69
+
70
+ ``` sh
71
+ export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4
72
+ export ASAN_OPTIONS=symbolize=1
73
+ ```
74
+
59
75
  ### Linux and other Unixes
60
76
 
61
77
  You may need to install a package such as `libmysqlclient-dev` or `mysql-devel`;
@@ -153,6 +169,20 @@ results.each(:as => :array) do |row|
153
169
  end
154
170
  ```
155
171
 
172
+ Prepared statements are supported, as well. In a prepared statement, use a `?`
173
+ in place of each value and then execute the statement to retrieve a result set.
174
+ Pass your arguments to the execute method in the same number and order as the
175
+ question marks in the statement.
176
+
177
+ ``` ruby
178
+ statement = @client.prepare("SELECT * FROM users WHERE login_count = ?")
179
+ result1 = statement.execute(1)
180
+ result2 = statement.execute(2)
181
+
182
+ statement = @client.prepare("SELECT * FROM users WHERE last_login >= ? AND location LIKE ?")
183
+ result = statement.execute(1, "CA")
184
+ ```
185
+
156
186
  ## Connection options
157
187
 
158
188
  You may set the following connection options in Mysql2::Client.new(...):
@@ -186,7 +216,8 @@ Setting any of the following options will enable an SSL connection, but only if
186
216
  your MySQL client library and server have been compiled with SSL support.
187
217
  MySQL client library defaults will be used for any parameters that are left out
188
218
  or set to nil. Relative paths are allowed, and may be required by managed
189
- hosting providers such as Heroku.
219
+ hosting providers such as Heroku. Set `:sslverify => true` to require that the
220
+ server presents a valid certificate.
190
221
 
191
222
  ``` ruby
192
223
  Mysql2::Client.new(
@@ -195,7 +226,8 @@ Mysql2::Client.new(
195
226
  :sslcert => '/path/to/client-cert.pem',
196
227
  :sslca => '/path/to/ca-cert.pem',
197
228
  :sslcapath => '/path/to/cacerts',
198
- :sslcipher => 'DHE-RSA-AES256-SHA'
229
+ :sslcipher => 'DHE-RSA-AES256-SHA',
230
+ :sslverify => true,
199
231
  )
200
232
  ```
201
233
 
@@ -240,15 +272,26 @@ Yields:
240
272
  next_result: Unknown column 'A' in 'field list' (Mysql2::Error)
241
273
  ```
242
274
 
243
- See https://gist.github.com/1367987 for using MULTI_STATEMENTS with Active Record.
244
-
245
275
  ### Secure auth
246
276
 
247
277
  Starting wih MySQL 5.6.5, secure_auth is enabled by default on servers (it was disabled by default prior to this).
248
278
  When secure_auth is enabled, the server will refuse a connection if the account password is stored in old pre-MySQL 4.1 format.
249
279
  The MySQL 5.6.5 client library may also refuse to attempt a connection if provided an older format password.
250
- To bypass this restriction in the client, pass the option :secure_auth => false to Mysql2::Client.new().
251
- If using ActiveRecord, your database.yml might look something like this:
280
+ To bypass this restriction in the client, pass the option `:secure_auth => false` to Mysql2::Client.new().
281
+
282
+ ### Flags option parsing
283
+
284
+ The `:flags` parameter accepts an integer, a string, or an array. The integer
285
+ form allows the client to assemble flags from constants defined under
286
+ `Mysql2::Client` such as `Mysql2::Client::FOUND_ROWS`. Use a bitwise `|` (OR)
287
+ to specify several flags.
288
+
289
+ The string form will be split on whitespace and parsed as with the array form:
290
+ Plain flags are added to the default flags, while flags prefixed with `-`
291
+ (minus) are removed from the default flags.
292
+
293
+ This allows easier use with ActiveRecord's database.yml, avoiding the need for magic flag numbers.
294
+ For example, to disable protocol compression, and enable multiple statements and result sets:
252
295
 
253
296
  ``` yaml
254
297
  development:
@@ -259,13 +302,17 @@ development:
259
302
  password: my_password
260
303
  host: 127.0.0.1
261
304
  port: 3306
305
+ flags:
306
+ - -COMPRESS
307
+ - FOUND_ROWS
308
+ - MULTI_STATEMENTS
262
309
  secure_auth: false
263
310
  ```
264
311
 
265
312
  ### Reading a MySQL config file
266
313
 
267
314
  You may read configuration options from a MySQL configuration file by passing
268
- the `:default_file` and `:default_group` paramters. For example:
315
+ the `:default_file` and `:default_group` parameters. For example:
269
316
 
270
317
  ``` ruby
271
318
  Mysql2::Client.new(:default_file => '/user/.my.cnf', :default_group => 'client')
@@ -273,7 +320,7 @@ Mysql2::Client.new(:default_file => '/user/.my.cnf', :default_group => 'client')
273
320
 
274
321
  ### Initial command on connect and reconnect
275
322
 
276
- If you specify the init_command option, the SQL string you provide will be executed after the connection is established.
323
+ If you specify the `:init_command` option, the SQL string you provide will be executed after the connection is established.
277
324
  If `:reconnect` is set to `true`, init_command will also be executed after a successful reconnect.
278
325
  It is useful if you want to provide session options which survive reconnection.
279
326
 
@@ -437,13 +484,13 @@ As for field values themselves, I'm workin on it - but expect that soon.
437
484
 
438
485
  This gem is tested with the following Ruby versions on Linux and Mac OS X:
439
486
 
440
- * Ruby MRI 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.x, 2.2.x (ongoing patch releases)
487
+ * Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x
441
488
  * Ruby Enterprise Edition (based on MRI 1.8.7)
442
489
  * Rubinius 2.x
443
490
 
444
491
  This gem is tested with the following MySQL and MariaDB versions:
445
492
 
446
- * MySQL 5.0, 5.1, 5.5, 5.6, 5.7
493
+ * MySQL 5.5, 5.7
447
494
  * MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
448
495
  * MariaDB 5.5, 10.0
449
496
 
@@ -536,4 +583,8 @@ though.
536
583
  * Yury Korolev (http://github.com/yury) - for TONS of help testing the Active Record adapter
537
584
  * Aaron Patterson (http://github.com/tenderlove) - tons of contributions, suggestions and general badassness
538
585
  * Mike Perham (http://github.com/mperham) - Async Active Record adapter (uses Fibers and EventMachine)
539
- * Aaron Stone (http://github.com/sodabrew) - additional client settings, local files, microsecond time, maintenance support.
586
+ * Aaron Stone (http://github.com/sodabrew) - additional client settings, local files, microsecond time, maintenance support
587
+ * Kouhei Ueno (https://github.com/nyaxt) - for the original work on Prepared Statements way back in 2012
588
+ * John Cant (http://github.com/johncant) - polishing and updating Prepared Statements support
589
+ * Justin Case (http://github.com/justincase) - polishing and updating Prepared Statements support and getting it merged
590
+ * Tamir Duberstein (http://github.com/tamird) - for help with timeouts and all around updates and cleanups
@@ -18,4 +18,4 @@ EM.run do
18
18
  defer2.callback do |result|
19
19
  puts "Result: #{result.to_a.inspect}"
20
20
  end
21
- end
21
+ end
data/examples/threaded.rb CHANGED
@@ -4,17 +4,15 @@ $LOAD_PATH.unshift 'lib'
4
4
  require 'mysql2'
5
5
  require 'timeout'
6
6
 
7
- threads = []
8
7
  # Should never exceed worst case 3.5 secs across all 20 threads
9
8
  Timeout.timeout(3.5) do
10
- 20.times do
11
- threads << Thread.new do
9
+ 20.times.map do
10
+ Thread.new do
12
11
  overhead = rand(3)
13
12
  puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
14
13
  # 3 second overhead per query
15
14
  Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
16
15
  puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
17
16
  end
18
- end
19
- threads.each{|t| t.join }
20
- end
17
+ end.each(&:join)
18
+ end