mysql2 0.4.0-x86-mswin32-60 → 0.4.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/examples/eventmachine.rb +1 -1
  3. data/ext/mysql2/client.c +45 -44
  4. data/ext/mysql2/client.h +1 -2
  5. data/ext/mysql2/extconf.rb +59 -37
  6. data/ext/mysql2/infile.c +2 -2
  7. data/ext/mysql2/mysql2_ext.h +4 -6
  8. data/ext/mysql2/mysql_enc_name_to_ruby.h +8 -8
  9. data/ext/mysql2/mysql_enc_to_ruby.h +25 -22
  10. data/ext/mysql2/result.c +4 -16
  11. data/ext/mysql2/result.h +3 -3
  12. data/ext/mysql2/statement.c +79 -42
  13. data/ext/mysql2/statement.h +2 -6
  14. data/lib/mysql2.rb +36 -18
  15. data/lib/mysql2/1.8/mysql2.so +0 -0
  16. data/lib/mysql2/1.9/mysql2.so +0 -0
  17. data/lib/mysql2/2.0/mysql2.so +0 -0
  18. data/lib/mysql2/2.1/mysql2.so +0 -0
  19. data/lib/mysql2/2.2/mysql2.so +0 -0
  20. data/lib/mysql2/client.rb +28 -27
  21. data/lib/mysql2/console.rb +1 -1
  22. data/lib/mysql2/em.rb +5 -6
  23. data/lib/mysql2/error.rb +10 -7
  24. data/lib/mysql2/field.rb +1 -2
  25. data/lib/mysql2/statement.rb +12 -0
  26. data/lib/mysql2/version.rb +1 -1
  27. data/spec/em/em_spec.rb +8 -8
  28. data/spec/mysql2/client_spec.rb +62 -37
  29. data/spec/mysql2/result_spec.rb +48 -48
  30. data/spec/mysql2/statement_spec.rb +143 -57
  31. data/spec/ssl/ca-cert.pem +17 -0
  32. data/spec/ssl/ca-key.pem +27 -0
  33. data/spec/ssl/ca.cnf +22 -0
  34. data/spec/ssl/cert.cnf +22 -0
  35. data/spec/ssl/client-cert.pem +17 -0
  36. data/spec/ssl/client-key.pem +27 -0
  37. data/spec/ssl/client-req.pem +15 -0
  38. data/spec/ssl/gen_certs.sh +48 -0
  39. data/spec/ssl/pkcs8-client-key.pem +28 -0
  40. data/spec/ssl/pkcs8-server-key.pem +28 -0
  41. data/spec/ssl/server-cert.pem +17 -0
  42. data/spec/ssl/server-key.pem +27 -0
  43. data/spec/ssl/server-req.pem +15 -0
  44. data/support/mysql_enc_to_ruby.rb +7 -8
  45. data/support/ruby_enc_to_mysql.rb +1 -1
  46. metadata +28 -2
@@ -1,4 +1,4 @@
1
- /* C code produced by gperf version 3.0.3 */
1
+ /* C code produced by gperf version 3.0.4 */
2
2
  /* Command-line: gperf */
3
3
  /* Computed positions: -k'1,3,$' */
4
4
 
@@ -40,9 +40,9 @@ inline
40
40
  #endif
41
41
  #endif
42
42
  static unsigned int
43
- mysql2_mysql_enc_name_to_rb_hash(str, len)
43
+ mysql2_mysql_enc_name_to_rb_hash (str, len)
44
44
  register const char *str;
45
- register const unsigned int len;
45
+ register unsigned int len;
46
46
  {
47
47
  static const unsigned char asso_values[] =
48
48
  {
@@ -78,14 +78,14 @@ mysql2_mysql_enc_name_to_rb_hash(str, len)
78
78
 
79
79
  #ifdef __GNUC__
80
80
  __inline
81
- #ifdef __GNUC_STDC_INLINE__
81
+ #if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
82
82
  __attribute__ ((__gnu_inline__))
83
83
  #endif
84
84
  #endif
85
85
  const struct mysql2_mysql_enc_name_to_rb_map *
86
- mysql2_mysql_enc_name_to_rb(str, len)
86
+ mysql2_mysql_enc_name_to_rb (str, len)
87
87
  register const char *str;
88
- register const unsigned int len;
88
+ register unsigned int len;
89
89
  {
90
90
  enum
91
91
  {
@@ -154,9 +154,9 @@ mysql2_mysql_enc_name_to_rb(str, len)
154
154
 
155
155
  if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
156
156
  {
157
- register const unsigned int key = mysql2_mysql_enc_name_to_rb_hash(str, len);
157
+ register int key = mysql2_mysql_enc_name_to_rb_hash (str, len);
158
158
 
159
- if (key <= MAX_HASH_VALUE)
159
+ if (key <= MAX_HASH_VALUE && key >= 0)
160
160
  {
161
161
  register const char *s = wordlist[key].name;
162
162
 
@@ -1,4 +1,4 @@
1
- const char *mysql2_mysql_enc_to_rb[] = {
1
+ static const char *mysql2_mysql_enc_to_rb[] = {
2
2
  "Big5",
3
3
  "ISO-8859-2",
4
4
  NULL,
@@ -54,13 +54,13 @@ const char *mysql2_mysql_enc_to_rb[] = {
54
54
  "macRoman",
55
55
  "UTF-16",
56
56
  "UTF-16",
57
- NULL,
57
+ "",
58
58
  "Windows-1256",
59
59
  "Windows-1257",
60
60
  "Windows-1257",
61
61
  "UTF-32",
62
62
  "UTF-32",
63
- NULL,
63
+ "",
64
64
  "ASCII-8BIT",
65
65
  NULL,
66
66
  "US-ASCII",
@@ -119,10 +119,10 @@ const char *mysql2_mysql_enc_to_rb[] = {
119
119
  "UTF-16",
120
120
  "UTF-16",
121
121
  "UTF-16",
122
- NULL,
123
- NULL,
124
- NULL,
125
- NULL,
122
+ "UTF-16",
123
+ "UTF-16",
124
+ "UTF-16",
125
+ "UTF-16",
126
126
  NULL,
127
127
  NULL,
128
128
  NULL,
@@ -146,6 +146,10 @@ const char *mysql2_mysql_enc_to_rb[] = {
146
146
  "UTF-16BE",
147
147
  "UTF-16BE",
148
148
  "UTF-16BE",
149
+ "UTF-16BE",
150
+ "UTF-16BE",
151
+ "UTF-16BE",
152
+ "UTF-16BE",
149
153
  NULL,
150
154
  NULL,
151
155
  NULL,
@@ -153,11 +157,11 @@ const char *mysql2_mysql_enc_to_rb[] = {
153
157
  NULL,
154
158
  NULL,
155
159
  NULL,
156
- NULL,
157
- NULL,
158
- NULL,
159
- NULL,
160
- NULL,
160
+ "UTF-16BE",
161
+ "UTF-32",
162
+ "UTF-32",
163
+ "UTF-32",
164
+ "UTF-32",
161
165
  "UTF-32",
162
166
  "UTF-32",
163
167
  "UTF-32",
@@ -178,10 +182,6 @@ const char *mysql2_mysql_enc_to_rb[] = {
178
182
  "UTF-32",
179
183
  "UTF-32",
180
184
  "UTF-32",
181
- NULL,
182
- NULL,
183
- NULL,
184
- NULL,
185
185
  NULL,
186
186
  NULL,
187
187
  NULL,
@@ -210,6 +210,10 @@ const char *mysql2_mysql_enc_to_rb[] = {
210
210
  "UTF-8",
211
211
  "UTF-8",
212
212
  "UTF-8",
213
+ "UTF-8",
214
+ "UTF-8",
215
+ "UTF-8",
216
+ "UTF-8",
213
217
  NULL,
214
218
  NULL,
215
219
  NULL,
@@ -217,11 +221,11 @@ const char *mysql2_mysql_enc_to_rb[] = {
217
221
  NULL,
218
222
  NULL,
219
223
  NULL,
220
- NULL,
221
- NULL,
222
- NULL,
223
- NULL,
224
- NULL,
224
+ "UTF-8",
225
+ "UTF-8",
226
+ "UTF-8",
227
+ "UTF-8",
228
+ "UTF-8",
225
229
  "UTF-8",
226
230
  "UTF-8",
227
231
  "UTF-8",
@@ -243,4 +247,3 @@ const char *mysql2_mysql_enc_to_rb[] = {
243
247
  "UTF-8",
244
248
  "UTF-8"
245
249
  };
246
-
@@ -1,7 +1,5 @@
1
1
  #include <mysql2_ext.h>
2
2
 
3
- #include <stdint.h>
4
-
5
3
  #include "mysql_enc_to_ruby.h"
6
4
 
7
5
  #ifdef HAVE_RUBY_ENCODING_H
@@ -161,8 +159,7 @@ static void *nogvl_stmt_fetch(void *ptr) {
161
159
  return (void *)r;
162
160
  }
163
161
 
164
-
165
- static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
162
+ static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, int symbolize_keys) {
166
163
  VALUE rb_field;
167
164
  GET_RESULT(self);
168
165
 
@@ -357,11 +354,7 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
357
354
  }
358
355
 
359
356
  if (mysql_stmt_bind_result(wrapper->stmt_wrapper->stmt, wrapper->result_buffers)) {
360
- rb_raise_mysql2_stmt_error2(wrapper->stmt_wrapper->stmt
361
- #ifdef HAVE_RUBY_ENCODING_H
362
- , conn_enc
363
- #endif
364
- );
357
+ rb_raise_mysql2_stmt_error(wrapper->stmt_wrapper);
365
358
  }
366
359
 
367
360
  {
@@ -372,11 +365,7 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
372
365
 
373
366
  case 1:
374
367
  /* error */
375
- rb_raise_mysql2_stmt_error2(wrapper->stmt_wrapper->stmt
376
- #ifdef HAVE_RUBY_ENCODING_H
377
- , conn_enc
378
- #endif
379
- );
368
+ rb_raise_mysql2_stmt_error(wrapper->stmt_wrapper);
380
369
 
381
370
  case MYSQL_NO_DATA:
382
371
  /* no more row */
@@ -510,7 +499,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
510
499
  default:
511
500
  rb_raise(cMysql2Error, "unhandled buffer type: %d",
512
501
  result_buffer->buffer_type);
513
- break;
514
502
  }
515
503
  }
516
504
 
@@ -764,7 +752,7 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
764
752
  wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
765
753
  }
766
754
 
767
- if ((unsigned)RARRAY_LEN(wrapper->fields) != wrapper->numberOfFields) {
755
+ if ((my_ulonglong)RARRAY_LEN(wrapper->fields) != wrapper->numberOfFields) {
768
756
  for (i=0; i<wrapper->numberOfFields; i++) {
769
757
  rb_mysql_result_fetch_field(self, i, symbolizeKeys);
770
758
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef MYSQL2_RESULT_H
2
2
  #define MYSQL2_RESULT_H
3
3
 
4
- void init_mysql2_result();
4
+ void init_mysql2_result(void);
5
5
  VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r, VALUE statement);
6
6
 
7
7
  typedef struct {
@@ -10,8 +10,8 @@ typedef struct {
10
10
  VALUE client;
11
11
  VALUE encoding;
12
12
  VALUE statement;
13
- unsigned int numberOfFields;
14
- unsigned long numberOfRows;
13
+ my_ulonglong numberOfFields;
14
+ my_ulonglong numberOfRows;
15
15
  unsigned long lastRowProcessed;
16
16
  char is_streaming;
17
17
  char streamingComplete;
@@ -2,12 +2,13 @@
2
2
 
3
3
  VALUE cMysql2Statement;
4
4
  extern VALUE mMysql2, cMysql2Error, cBigDecimal, cDateTime, cDate;
5
- static VALUE sym_stream, intern_error_number_eql, intern_sql_state_eql, intern_each;
5
+ static VALUE sym_stream, intern_new_with_args, intern_each;
6
6
  static VALUE intern_usec, intern_sec, intern_min, intern_hour, intern_day, intern_month, intern_year;
7
7
 
8
8
  #define GET_STATEMENT(self) \
9
9
  mysql_stmt_wrapper *stmt_wrapper; \
10
- Data_Get_Struct(self, mysql_stmt_wrapper, stmt_wrapper);
10
+ Data_Get_Struct(self, mysql_stmt_wrapper, stmt_wrapper); \
11
+ if (!stmt_wrapper->stmt) { rb_raise(cMysql2Error, "Invalid statement handle"); }
11
12
 
12
13
 
13
14
  static void rb_mysql_stmt_mark(void * ptr) {
@@ -17,6 +18,15 @@ static void rb_mysql_stmt_mark(void * ptr) {
17
18
  rb_gc_mark(stmt_wrapper->client);
18
19
  }
19
20
 
21
+ static void *nogvl_stmt_close(void * ptr) {
22
+ mysql_stmt_wrapper *stmt_wrapper = (mysql_stmt_wrapper *)ptr;
23
+ if (stmt_wrapper->stmt) {
24
+ mysql_stmt_close(stmt_wrapper->stmt);
25
+ stmt_wrapper->stmt = NULL;
26
+ }
27
+ return NULL;
28
+ }
29
+
20
30
  static void rb_mysql_stmt_free(void * ptr) {
21
31
  mysql_stmt_wrapper* stmt_wrapper = (mysql_stmt_wrapper *)ptr;
22
32
  decr_mysql2_stmt(stmt_wrapper);
@@ -26,20 +36,22 @@ void decr_mysql2_stmt(mysql_stmt_wrapper *stmt_wrapper) {
26
36
  stmt_wrapper->refcount--;
27
37
 
28
38
  if (stmt_wrapper->refcount == 0) {
29
- mysql_stmt_close(stmt_wrapper->stmt);
39
+ nogvl_stmt_close(stmt_wrapper);
30
40
  xfree(stmt_wrapper);
31
41
  }
32
42
  }
33
43
 
34
- VALUE rb_raise_mysql2_stmt_error2(MYSQL_STMT *stmt
35
- #ifdef HAVE_RUBY_ENCODING_H
36
- , rb_encoding *conn_enc
37
- #endif
38
- ) {
39
- VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt));
40
- VALUE rb_sql_state = rb_tainted_str_new2(mysql_stmt_sqlstate(stmt));
41
- VALUE e = rb_exc_new3(cMysql2Error, rb_error_msg);
44
+
45
+ void rb_raise_mysql2_stmt_error(mysql_stmt_wrapper *stmt_wrapper) {
46
+ VALUE e;
47
+ GET_CLIENT(stmt_wrapper->client);
48
+ VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));
49
+ VALUE rb_sql_state = rb_tainted_str_new2(mysql_stmt_sqlstate(stmt_wrapper->stmt));
50
+
42
51
  #ifdef HAVE_RUBY_ENCODING_H
52
+ rb_encoding *conn_enc;
53
+ conn_enc = rb_to_encoding(wrapper->encoding);
54
+
43
55
  rb_encoding *default_internal_enc = rb_default_internal_encoding();
44
56
 
45
57
  rb_enc_associate(rb_error_msg, conn_enc);
@@ -49,30 +61,13 @@ VALUE rb_raise_mysql2_stmt_error2(MYSQL_STMT *stmt
49
61
  rb_sql_state = rb_str_export_to_enc(rb_sql_state, default_internal_enc);
50
62
  }
51
63
  #endif
52
- rb_funcall(e, intern_error_number_eql, 1, UINT2NUM(mysql_stmt_errno(stmt)));
53
- rb_funcall(e, intern_sql_state_eql, 1, rb_sql_state);
54
- rb_exc_raise(e);
55
- return Qnil;
56
- }
57
64
 
58
- static void rb_raise_mysql2_stmt_error(VALUE self) {
59
- #ifdef HAVE_RUBY_ENCODING_H
60
- rb_encoding *conn_enc;
61
- #endif
62
- GET_STATEMENT(self);
63
-
64
- #ifdef HAVE_RUBY_ENCODING_H
65
- {
66
- GET_CLIENT(stmt_wrapper->client);
67
- conn_enc = rb_to_encoding(wrapper->encoding);
68
- }
69
- #endif
70
-
71
- rb_raise_mysql2_stmt_error2(stmt_wrapper->stmt
72
- #ifdef HAVE_RUBY_ENCODING_H
73
- , conn_enc
74
- #endif
75
- );
65
+ e = rb_funcall(cMysql2Error, intern_new_with_args, 4,
66
+ rb_error_msg,
67
+ LONG2FIX(wrapper->server_version),
68
+ UINT2NUM(mysql_stmt_errno(stmt_wrapper->stmt)),
69
+ rb_sql_state);
70
+ rb_exc_raise(e);
76
71
  }
77
72
 
78
73
 
@@ -146,7 +141,7 @@ VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql) {
146
141
  args.sql_len = RSTRING_LEN(sql);
147
142
 
148
143
  if ((VALUE)rb_thread_call_without_gvl(nogvl_prepare_statement, &args, RUBY_UBF_IO, 0) == Qfalse) {
149
- rb_raise_mysql2_stmt_error(rb_stmt);
144
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
150
145
  }
151
146
  }
152
147
 
@@ -335,13 +330,13 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
335
330
  // copies bind_buffers into internal storage
336
331
  if (mysql_stmt_bind_param(stmt, bind_buffers)) {
337
332
  FREE_BINDS;
338
- rb_raise_mysql2_stmt_error(self);
333
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
339
334
  }
340
335
  }
341
336
 
342
337
  if ((VALUE)rb_thread_call_without_gvl(nogvl_execute, stmt, RUBY_UBF_IO, 0) == Qfalse) {
343
338
  FREE_BINDS;
344
- rb_raise_mysql2_stmt_error(self);
339
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
345
340
  }
346
341
 
347
342
  FREE_BINDS;
@@ -352,7 +347,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
352
347
  // either CR_OUT_OF_MEMORY or CR_UNKNOWN_ERROR. both fatal.
353
348
 
354
349
  MARK_CONN_INACTIVE(stmt_wrapper->client);
355
- rb_raise_mysql2_stmt_error(self);
350
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
356
351
  }
357
352
  // no data and no error, so query was not a SELECT
358
353
  return Qnil;
@@ -367,7 +362,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
367
362
  // recieve the whole result set from the server
368
363
  if (rb_thread_call_without_gvl(nogvl_stmt_store_result, stmt, RUBY_UBF_IO, 0) == Qfalse) {
369
364
  mysql_free_result(metadata);
370
- rb_raise_mysql2_stmt_error(self);
365
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
371
366
  }
372
367
  MARK_CONN_INACTIVE(stmt_wrapper->client);
373
368
  }
@@ -430,18 +425,60 @@ static VALUE fields(VALUE self) {
430
425
  return field_list;
431
426
  }
432
427
 
428
+ /* call-seq:
429
+ * stmt.last_id
430
+ *
431
+ * Returns the AUTO_INCREMENT value from the executed INSERT or UPDATE.
432
+ */
433
+ static VALUE rb_mysql_stmt_last_id(VALUE self) {
434
+ GET_STATEMENT(self);
435
+ return ULL2NUM(mysql_stmt_insert_id(stmt_wrapper->stmt));
436
+ }
437
+
438
+ /* call-seq:
439
+ * stmt.affected_rows
440
+ *
441
+ * Returns the number of rows changed, deleted, or inserted.
442
+ */
443
+ static VALUE rb_mysql_stmt_affected_rows(VALUE self) {
444
+ my_ulonglong affected;
445
+ GET_STATEMENT(self);
446
+
447
+ affected = mysql_stmt_affected_rows(stmt_wrapper->stmt);
448
+ if (affected == (my_ulonglong)-1) {
449
+ rb_raise_mysql2_stmt_error(stmt_wrapper);
450
+ }
451
+
452
+ return ULL2NUM(affected);
453
+ }
454
+
455
+ /* call-seq:
456
+ * stmt.close
457
+ *
458
+ * Explicitly closing this will free up server resources immediately rather
459
+ * than waiting for the garbage collector. Useful if you're managing your
460
+ * own prepared statement cache.
461
+ */
462
+ static VALUE rb_mysql_stmt_close(VALUE self) {
463
+ GET_STATEMENT(self);
464
+ rb_thread_call_without_gvl(nogvl_stmt_close, stmt_wrapper, RUBY_UBF_IO, 0);
465
+ return Qnil;
466
+ }
467
+
433
468
  void init_mysql2_statement() {
434
469
  cMysql2Statement = rb_define_class_under(mMysql2, "Statement", rb_cObject);
435
470
 
436
471
  rb_define_method(cMysql2Statement, "param_count", param_count, 0);
437
472
  rb_define_method(cMysql2Statement, "field_count", field_count, 0);
438
- rb_define_method(cMysql2Statement, "execute", execute, -1);
473
+ rb_define_method(cMysql2Statement, "_execute", execute, -1);
439
474
  rb_define_method(cMysql2Statement, "fields", fields, 0);
475
+ rb_define_method(cMysql2Statement, "last_id", rb_mysql_stmt_last_id, 0);
476
+ rb_define_method(cMysql2Statement, "affected_rows", rb_mysql_stmt_affected_rows, 0);
477
+ rb_define_method(cMysql2Statement, "close", rb_mysql_stmt_close, 0);
440
478
 
441
479
  sym_stream = ID2SYM(rb_intern("stream"));
442
480
 
443
- intern_error_number_eql = rb_intern("error_number=");
444
- intern_sql_state_eql = rb_intern("sql_state=");
481
+ intern_new_with_args = rb_intern("new_with_args");
445
482
  intern_each = rb_intern("each");
446
483
 
447
484
  intern_usec = rb_intern("usec");
@@ -9,14 +9,10 @@ typedef struct {
9
9
  int refcount;
10
10
  } mysql_stmt_wrapper;
11
11
 
12
- void init_mysql2_statement();
12
+ void init_mysql2_statement(void);
13
13
  void decr_mysql2_stmt(mysql_stmt_wrapper *stmt_wrapper);
14
14
 
15
15
  VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql);
16
- VALUE rb_raise_mysql2_stmt_error2(MYSQL_STMT *stmt
17
- #ifdef HAVE_RUBY_ENCODING_H
18
- , rb_encoding* conn_enc
19
- #endif
20
- );
16
+ void rb_raise_mysql2_stmt_error(mysql_stmt_wrapper *stmt_wrapper) RB_MYSQL_NORETURN;
21
17
 
22
18
  #endif