do_mysql 0.10.2-x86-mingw32 → 0.10.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.10.3 2011-01-30
2
+ * Reworked transactions
3
+ * Fix a DST bug that could cause datetimes in the wrong timezone
4
+
1
5
  ## 0.10.2 2010-05-19
2
6
  * Make sure Text is returned in the proper encoding
3
7
  * Make Encoding.default_internal aware
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ JRUBY = RUBY_PLATFORM =~ /java/
11
11
  IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
12
12
  WINDOWS = Gem.win_platform? || (JRUBY && ENV_JAVA['os.name'] =~ /windows/i)
13
13
  SUDO = WINDOWS ? '' : ('sudo' unless ENV['SUDOLESS'])
14
- BINARY_VERSION = '5.1.46'
14
+ BINARY_VERSION = '5.1.54'
15
15
 
16
16
  CLEAN.include(%w[ {tmp,pkg}/ **/*.{o,so,bundle,jar,log,a,gem,dSYM,obj,pdb,exp,DS_Store,rbc,db} ext/do_mysql/Makefile ext-java/target ])
17
17
 
@@ -38,7 +38,7 @@ begin
38
38
  gem.add_dependency 'data_objects', DataObjects::Mysql::VERSION
39
39
 
40
40
  gem.add_development_dependency 'bacon', '~>1.1'
41
- gem.add_development_dependency 'rake-compiler', '~>0.7'
41
+ gem.add_development_dependency 'rake-compiler', '= 0.7.0'
42
42
 
43
43
  gem.has_rdoc = false
44
44
  gem.rubyforge_project = 'dorb'
@@ -8,9 +8,14 @@
8
8
  #include <errmsg.h>
9
9
  #include <mysqld_error.h>
10
10
 
11
+ #include "mysql_compat.h"
11
12
  #include "compat.h"
12
13
  #include "error.h"
13
14
 
15
+ #ifndef HAVE_CONST_MYSQL_TYPE_STRING
16
+ #define HAVE_OLD_MYSQL_VERSION
17
+ #endif
18
+
14
19
  #define CONST_GET(scope, constant) (rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant)))
15
20
  #define DRIVER_CLASS(klass, parent) (rb_define_class_under(mMysql, klass, parent))
16
21
  #define CHECK_AND_RAISE(mysql_result_value, query) if (0 != mysql_result_value) { raise_error(self, db, query); }
@@ -105,14 +110,18 @@ static VALUE infer_ruby_type(MYSQL_FIELD *field) {
105
110
  return Qnil;
106
111
  case MYSQL_TYPE_TINY:
107
112
  return rb_cTrueClass;
113
+ #ifdef HAVE_CONST_MYSQL_TYPE_BIT
108
114
  case MYSQL_TYPE_BIT:
115
+ #endif
109
116
  case MYSQL_TYPE_SHORT:
110
117
  case MYSQL_TYPE_LONG:
111
118
  case MYSQL_TYPE_INT24:
112
119
  case MYSQL_TYPE_LONGLONG:
113
120
  case MYSQL_TYPE_YEAR:
114
121
  return rb_cInteger;
122
+ #ifdef HAVE_CONST_MYSQL_TYPE_NEWDECIMAL
115
123
  case MYSQL_TYPE_NEWDECIMAL:
124
+ #endif
116
125
  case MYSQL_TYPE_DECIMAL:
117
126
  return rb_cBigDecimal;
118
127
  case MYSQL_TYPE_FLOAT:
@@ -130,11 +139,16 @@ static VALUE infer_ruby_type(MYSQL_FIELD *field) {
130
139
  case MYSQL_TYPE_MEDIUM_BLOB:
131
140
  case MYSQL_TYPE_LONG_BLOB:
132
141
  case MYSQL_TYPE_BLOB:
142
+ #ifdef HAVE_ST_CHARSETNR
133
143
  if(field->charsetnr == 63) {
134
144
  return rb_cByteArray;
135
145
  } else {
136
146
  return rb_cString;
137
147
  }
148
+ #else
149
+ // We assume a string here if we don't have a specific charset
150
+ return rb_cString;
151
+ #endif
138
152
  default:
139
153
  return rb_cString;
140
154
  }
@@ -230,10 +244,10 @@ static VALUE parse_date_time(const char *date) {
230
244
 
231
245
 
232
246
  time_t gmt_offset;
233
- int is_dst;
247
+ int dst_adjustment;
234
248
 
235
249
  time_t rawtime;
236
- struct tm * timeinfo;
250
+ struct tm timeinfo;
237
251
 
238
252
  int tokens_read, max_tokens;
239
253
 
@@ -267,22 +281,48 @@ static VALUE parse_date_time(const char *date) {
267
281
  }
268
282
  // We read the Date and Time, default to the current locale's offset
269
283
 
284
+ tzset();
285
+
270
286
  // Get localtime
271
287
  time(&rawtime);
272
- timeinfo = localtime(&rawtime);
288
+ #ifdef HAVE_LOCALTIME_R
289
+ localtime_r(&rawtime, &timeinfo);
290
+ #else
291
+ timeinfo = *localtime(&rawtime);
292
+ #endif
293
+
294
+ timeinfo.tm_sec = sec;
295
+ timeinfo.tm_min = min;
296
+ timeinfo.tm_hour = hour;
297
+ timeinfo.tm_mday = day;
298
+ timeinfo.tm_mon = month;
299
+ timeinfo.tm_year = year - 1900;
300
+ timeinfo.tm_isdst = -1;
301
+
302
+ // Update tm_isdst
303
+ mktime(&timeinfo);
273
304
 
274
- is_dst = timeinfo->tm_isdst * 3600;
305
+ if (timeinfo.tm_isdst) {
306
+ dst_adjustment = 3600;
307
+ } else {
308
+ dst_adjustment = 0;
309
+ }
275
310
 
276
311
  // Reset to GM Time
277
- timeinfo = gmtime(&rawtime);
312
+ #ifdef HAVE_GMTIME_R
313
+ gmtime_r(&rawtime, &timeinfo);
314
+ #else
315
+ timeinfo = *gmtime(&rawtime);
316
+ #endif
278
317
 
279
- gmt_offset = mktime(timeinfo) - rawtime;
318
+ gmt_offset = rawtime - mktime(&timeinfo);
280
319
 
281
- if ( is_dst > 0 )
282
- gmt_offset -= is_dst;
320
+ if (dst_adjustment) {
321
+ gmt_offset += dst_adjustment;
322
+ }
283
323
 
284
- hour_offset = -((int)gmt_offset / 3600);
285
- minute_offset = -((int)gmt_offset % 3600 / 60);
324
+ hour_offset = ((int)gmt_offset / 3600);
325
+ minute_offset = ((int)gmt_offset % 3600 / 60);
286
326
 
287
327
  } else {
288
328
  // Something went terribly wrong
@@ -389,10 +429,15 @@ static void raise_error(VALUE self, MYSQL *db, VALUE query) {
389
429
 
390
430
  VALUE uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0);
391
431
 
432
+ VALUE sql_state = Qnil;
433
+ #ifdef HAVE_MYSQL_SQLSTATE
434
+ sql_state = rb_str_new2(mysql_sqlstate(db));
435
+ #endif
436
+
392
437
  exception = rb_funcall(CONST_GET(mDO, exception_type), ID_NEW, 5,
393
438
  rb_str_new2(mysql_error_message),
394
439
  INT2NUM(mysql_error_code),
395
- rb_str_new2(mysql_sqlstate(db)),
440
+ sql_state,
396
441
  query,
397
442
  uri);
398
443
  rb_exc_raise(exception);
@@ -450,6 +495,7 @@ static MYSQL_RES* cCommand_execute_async(VALUE self, VALUE connection, MYSQL* db
450
495
  struct timeval start;
451
496
  const char* str = rb_str_ptr_readonly(query);
452
497
  size_t len = rb_str_len(query);
498
+ MYSQL_RES* result;
453
499
 
454
500
  if((retval = mysql_ping(db)) && mysql_errno(db) == CR_SERVER_GONE_ERROR) {
455
501
  full_connect(connection, db);
@@ -485,7 +531,12 @@ static MYSQL_RES* cCommand_execute_async(VALUE self, VALUE connection, MYSQL* db
485
531
  CHECK_AND_RAISE(retval, query);
486
532
  data_objects_debug(connection, query, &start);
487
533
 
488
- return mysql_store_result(db);
534
+ result = mysql_store_result(db);
535
+
536
+ if (!result)
537
+ CHECK_AND_RAISE(mysql_errno(db), query);
538
+
539
+ return result;
489
540
  }
490
541
  #endif
491
542
 
@@ -494,7 +545,7 @@ static void full_connect(VALUE self, MYSQL* db) {
494
545
  // Check to see if we're on the db machine. If so, try to use the socket
495
546
  VALUE r_host, r_user, r_password, r_path, r_query, r_port;
496
547
 
497
- const char *host = "localhost", *user = "root";
548
+ const char *host = "localhost", *user = "root";
498
549
  char *database = NULL, *socket = NULL, *password = NULL, *path = NULL;
499
550
  VALUE encoding = Qnil;
500
551
 
@@ -578,7 +629,7 @@ static void full_connect(VALUE self, MYSQL* db) {
578
629
  raise_error(self, db, Qnil);
579
630
  }
580
631
 
581
- #ifdef HAVE_MYSQL_SSL_SET
632
+ #ifdef HAVE_MYSQL_GET_SSL_CIPHER
582
633
  const char *ssl_cipher_used = mysql_get_ssl_cipher(db);
583
634
 
584
635
  if (NULL != ssl_cipher_used) {
@@ -591,11 +642,20 @@ static void full_connect(VALUE self, MYSQL* db) {
591
642
  mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect);
592
643
  #endif
593
644
 
645
+
646
+ // We only support encoding for MySQL versions providing mysql_set_character_set.
647
+ // Without this function there are potential issues with mysql_real_escape_string
648
+ // since that doesn't take the character set into consideration when setting it
649
+ // using a SET CHARACTER SET query. Since we don't want to stimulate these possible
650
+ // issues we simply ignore it and assume the user has configured this correctly.
651
+
652
+ #ifdef HAVE_MYSQL_SET_CHARACTER_SET
594
653
  // Set the connections character set
595
654
  encoding = rb_iv_get(self, "@encoding");
596
655
 
597
656
  VALUE my_encoding = rb_hash_aref(CONST_GET(mEncoding, "MAP"), encoding);
598
657
  if(my_encoding != Qnil) {
658
+
599
659
  encoding_error = mysql_set_character_set(db, rb_str_ptr_readonly(my_encoding));
600
660
  if (0 != encoding_error) {
601
661
  raise_error(self, db, Qnil);
@@ -614,18 +674,23 @@ static void full_connect(VALUE self, MYSQL* db) {
614
674
  rb_iv_set(self, "@my_encoding", rb_str_new2("utf8"));
615
675
  }
616
676
 
677
+ #endif
678
+
617
679
  // Disable sql_auto_is_null
618
680
  cCommand_execute(Qnil, self, db, rb_str_new2("SET sql_auto_is_null = 0"));
619
681
  // removed NO_AUTO_VALUE_ON_ZERO because of MySQL bug http://bugs.mysql.com/bug.php?id=42270
620
682
  // added NO_BACKSLASH_ESCAPES so that backslashes should not be escaped as in other databases
621
-
622
- //4.x versions do not support certain session parameters
683
+
684
+ // For really anscient MySQL versions we don't attempt any strictness
685
+ #ifdef HAVE_MYSQL_GET_SERVER_VERSION
686
+ //4.x versions do not support certain session parameters
623
687
  if(mysql_get_server_version(db) < 50000 ){
624
688
  cCommand_execute(Qnil, self, db, rb_str_new2("SET SESSION sql_mode = 'ANSI,NO_DIR_IN_CREATE,NO_UNSIGNED_SUBTRACTION'"));
625
689
  }else{
626
690
  cCommand_execute(Qnil, self, db, rb_str_new2("SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'"));
627
691
  }
628
-
692
+ #endif
693
+
629
694
  rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db));
630
695
  }
631
696
 
@@ -990,6 +1055,7 @@ static VALUE cReader_field_count(VALUE self) {
990
1055
 
991
1056
  void Init_do_mysql() {
992
1057
  rb_require("bigdecimal");
1058
+ rb_require("rational");
993
1059
  rb_require("date");
994
1060
  rb_require("data_objects");
995
1061
 
@@ -66,10 +66,21 @@ else
66
66
  find_header('mysql.h', *lib_dirs.flatten.map { |p| p.gsub('/lib', '/include') })
67
67
  end
68
68
 
69
+ have_func('localtime_r')
70
+ have_func('gmtime_r')
71
+
69
72
  unless RUBY_PLATFORM =~ /mswin|mingw/
70
73
  have_header 'mysql.h'
71
- have_func 'mysql_query'
72
- have_func 'mysql_ssl_set'
74
+ have_const 'MYSQL_TYPE_STRING', 'mysql.h'
75
+ have_const 'MYSQL_TYPE_BIT', 'mysql.h'
76
+ have_const 'MYSQL_TYPE_NEWDECIMAL', 'mysql.h'
77
+ have_func 'mysql_query', 'mysql.h'
78
+ have_func 'mysql_ssl_set', 'mysql.h'
79
+ have_func 'mysql_sqlstate', 'mysql.h'
80
+ have_func 'mysql_get_ssl_cipher', 'mysql.h'
81
+ have_func 'mysql_set_character_set', 'mysql.h'
82
+ have_func 'mysql_get_server_version', 'mysql.h'
83
+ have_struct_member 'MYSQL_FIELD', 'charsetnr', 'mysql.h'
73
84
  end
74
85
 
75
86
  $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
@@ -0,0 +1,25 @@
1
+ #ifdef HAVE_OLD_MYSQL_VERSION
2
+ #define MYSQL_TYPE_VAR_STRING FIELD_TYPE_VAR_STRING
3
+ #define MYSQL_TYPE_STRING FIELD_TYPE_STRING
4
+ #define MYSQL_TYPE_NEWDECIMAL FIELD_TYPE_DECIMAL
5
+ #define MYSQL_TYPE_SHORT FIELD_TYPE_SHORT
6
+ #define MYSQL_TYPE_LONG FIELD_TYPE_LONG
7
+ #define MYSQL_TYPE_FLOAT FIELD_TYPE_FLOAT
8
+ #define MYSQL_TYPE_DOUBLE FIELD_TYPE_DOUBLE
9
+ #define MYSQL_TYPE_LONGLONG FIELD_TYPE_LONGLONG
10
+ #define MYSQL_TYPE_INT24 FIELD_TYPE_INT24
11
+ #define MYSQL_TYPE_YEAR FIELD_TYPE_YEAR
12
+ #define MYSQL_TYPE_TINY FIELD_TYPE_TINY
13
+ #define MYSQL_TYPE_TINY_BLOB FIELD_TYPE_TINY_BLOB
14
+ #define MYSQL_TYPE_MEDIUM_BLOB FIELD_TYPE_MEDIUM_BLOB
15
+ #define MYSQL_TYPE_LONG_BLOB FIELD_TYPE_LONG_BLOB
16
+ #define MYSQL_TYPE_BLOB FIELD_TYPE_BLOB
17
+ #define MYSQL_TYPE_DATE FIELD_TYPE_DATE
18
+ #define MYSQL_TYPE_NEWDATE FIELD_TYPE_NEWDATE
19
+ #define MYSQL_TYPE_DATETIME FIELD_TYPE_DATETIME
20
+ #define MYSQL_TYPE_TIME FIELD_TYPE_TIME
21
+ #define MYSQL_TYPE_TIMESTAMP FIELD_TYPE_TIMESTAMP
22
+ #define MYSQL_TYPE_ENUM FIELD_TYPE_ENUM
23
+ #define MYSQL_TYPE_SET FIELD_TYPE_SET
24
+ #define MYSQL_TYPE_NULL FIELD_TYPE_NULL
25
+ #endif
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = '0.10.2'
3
+ VERSION = '0.10.3'
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/error/sql_error_spec'
5
+
6
+ describe 'DataObjects::Mysql raising SQLError' do
7
+ behaves_like 'raising a SQLError'
8
+ end
data/spec/spec_helper.rb CHANGED
@@ -141,6 +141,10 @@ module DataObjectsSpecHelpers
141
141
  update widgets set release_timestamp = NULL where id = 9
142
142
  EOF
143
143
 
144
+ conn.create_command(<<-EOF).execute_non_query
145
+ update widgets set release_datetime = '2008-07-14 00:31:12' where id = 10
146
+ EOF
147
+
144
148
  conn.close
145
149
 
146
150
  end
data/tasks/compile.rake CHANGED
@@ -57,7 +57,7 @@ begin
57
57
  ext.classpath = '../do_jdbc/lib/do_jdbc_internal.jar'
58
58
  ext.java_compiling do |gem|
59
59
  gem.add_dependency 'jdbc-mysql', '>=5.0.4'
60
- gem.add_dependency 'do_jdbc', '0.10.2'
60
+ gem.add_dependency 'do_jdbc', '0.10.3'
61
61
  end
62
62
  end
63
63
  rescue LoadError
data/tasks/release.rake CHANGED
@@ -3,7 +3,7 @@ task :build_all do
3
3
  `rake clean`
4
4
  `rake build`
5
5
  `rake java gem`
6
- `rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1`
6
+ `rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2`
7
7
  end
8
8
 
9
9
  desc 'Release all gems (native, binaries for JRuby and Windows)'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_mysql
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 49
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 10
8
- - 2
9
- version: 0.10.2
9
+ - 3
10
+ version: 0.10.3
10
11
  platform: x86-mingw32
11
12
  authors:
12
13
  - Dirkjan Bussink
@@ -14,30 +15,34 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-19 00:00:00 +02:00
18
+ date: 2011-01-30 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: data_objects
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 49
27
30
  segments:
28
31
  - 0
29
32
  - 10
30
- - 2
31
- version: 0.10.2
33
+ - 3
34
+ version: 0.10.3
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: bacon
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ~>
40
44
  - !ruby/object:Gem::Version
45
+ hash: 13
41
46
  segments:
42
47
  - 1
43
48
  - 1
@@ -48,13 +53,16 @@ dependencies:
48
53
  name: rake-compiler
49
54
  prerelease: false
50
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
- - - ~>
58
+ - - "="
53
59
  - !ruby/object:Gem::Version
60
+ hash: 3
54
61
  segments:
55
62
  - 0
56
63
  - 7
57
- version: "0.7"
64
+ - 0
65
+ version: 0.7.0
58
66
  type: :development
59
67
  version_requirements: *id003
60
68
  description: Implements the DataObjects API for MySQL
@@ -75,6 +83,7 @@ files:
75
83
  - spec/command_spec.rb
76
84
  - spec/connection_spec.rb
77
85
  - spec/encoding_spec.rb
86
+ - spec/error/sql_error_spec.rb
78
87
  - spec/reader_spec.rb
79
88
  - spec/result_spec.rb
80
89
  - spec/spec_helper.rb
@@ -101,6 +110,7 @@ files:
101
110
  - ext/do_mysql/do_mysql.c
102
111
  - ext/do_mysql/compat.h
103
112
  - ext/do_mysql/error.h
113
+ - ext/do_mysql/mysql_compat.h
104
114
  - LICENSE
105
115
  - Rakefile
106
116
  - ChangeLog.markdown
@@ -116,13 +126,13 @@ post_install_message: |+
116
126
  ======================================================================================================
117
127
 
118
128
  You've installed the binary version of do_mysql.
119
- It was built using MySQL version 5.1.46.
129
+ It was built using MySQL version 5.1.54.
120
130
  It's recommended to use the exact same version to avoid potential issues.
121
131
 
122
132
  At the time of building this gem, the necessary DLL files where available
123
133
  in the following download:
124
134
 
125
- http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.1.46-win32.zip/from/pick
135
+ http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.1.54-win32.zip/from/pick
126
136
 
127
137
  You can put the lib\opt\libmysql.dll available in this package in your Ruby bin
128
138
  directory, for example C:\Ruby\bin
@@ -134,23 +144,27 @@ rdoc_options:
134
144
  require_paths:
135
145
  - lib
136
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
137
148
  requirements:
138
149
  - - ">="
139
150
  - !ruby/object:Gem::Version
151
+ hash: 3
140
152
  segments:
141
153
  - 0
142
154
  version: "0"
143
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
144
157
  requirements:
145
158
  - - ">="
146
159
  - !ruby/object:Gem::Version
160
+ hash: 3
147
161
  segments:
148
162
  - 0
149
163
  version: "0"
150
164
  requirements: []
151
165
 
152
166
  rubyforge_project: dorb
153
- rubygems_version: 1.3.6
167
+ rubygems_version: 1.3.7
154
168
  signing_key:
155
169
  specification_version: 3
156
170
  summary: DataObjects MySQL Driver
@@ -158,6 +172,7 @@ test_files:
158
172
  - spec/command_spec.rb
159
173
  - spec/connection_spec.rb
160
174
  - spec/encoding_spec.rb
175
+ - spec/error/sql_error_spec.rb
161
176
  - spec/reader_spec.rb
162
177
  - spec/result_spec.rb
163
178
  - spec/spec_helper.rb