do_mysql 0.9.10.1 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.9.11 2009-01-19
2
+ * Improvements
3
+ * Ruby 1.9 support
4
+ * Fixes
5
+ * Reconnecting now works properly
6
+
1
7
  == 0.9.9 2008-11-27
2
8
  * Improvements
3
9
  * Added initial support for Ruby 1.9 [John Harrison]
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007 Yehuda Katz
1
+ Copyright (c) 2007, 2008, 2009 Yehuda Katz, Dirkjan Bussink
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Manifest.txt CHANGED
@@ -4,7 +4,6 @@ LICENSE
4
4
  Manifest.txt
5
5
  README.txt
6
6
  Rakefile
7
- TODO
8
7
  buildfile
9
8
  ext-java/src/main/java/DoMysqlExtService.java
10
9
  ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java
data/Rakefile CHANGED
@@ -9,8 +9,8 @@ JRUBY = RUBY_PLATFORM =~ /java/
9
9
  WINDOWS = Gem.win_platform?
10
10
  SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
11
11
 
12
- AUTHOR = "Scott Bauer"
13
- EMAIL = "bauer.mail@gmail.com"
12
+ AUTHOR = "Dirkjan Bussink"
13
+ EMAIL = "d.bussink@gmail.com"
14
14
  GEM_NAME = "do_mysql"
15
15
  GEM_VERSION = DataObjects::Mysql::VERSION
16
16
  GEM_DEPENDENCIES = if JRUBY
@@ -18,33 +18,54 @@ GEM_DEPENDENCIES = if JRUBY
18
18
  else
19
19
  [["data_objects", GEM_VERSION]]
20
20
  end
21
- GEM_CLEAN = ['**/*.{o,so,bundle,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}', 'ext/Makefile']
22
- GEM_EXTRAS = { :has_rdoc => false, :extensions => 'ext/do_mysql_ext/extconf.rb' }
21
+ GEM_CLEAN = ['**/*.{o,so,bundle,jar,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}',
22
+ 'ext/Makefile', 'ext-java/target']
23
+ GEM_EXTRAS = if JRUBY
24
+ {
25
+ :has_rdoc => false,
26
+ :platform => 'java'
27
+ }
28
+ else
29
+ {
30
+ :has_rdoc => false,
31
+ :extensions => 'ext/do_mysql_ext/extconf.rb'
32
+ }
33
+ end
23
34
 
24
35
  PROJECT_NAME = "dorb"
25
36
  PROJECT_URL = "http://rubyforge.org/projects/dorb"
26
37
  PROJECT_DESCRIPTION = PROJECT_SUMMARY = "A DataObject.rb driver for MySQL"
27
38
 
28
- JAVA_DRIVER = true
29
-
30
39
 
31
40
  # RCov is run by default, except on the JRuby platform, or if NO_RCOV env is true
32
41
  RUN_RCOV = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
33
42
 
34
43
  if (tasks_dir = ROOT.parent + 'tasks').directory?
35
44
  require tasks_dir + 'hoe'
45
+ require tasks_dir + 'ext_helper_java'
46
+
47
+ setup_java_extension "#{GEM_NAME}_ext", HOE.spec
48
+ end
49
+
50
+ if JRUBY
51
+ HOE.spec.files += ['lib/do_mysql_ext.jar']
52
+ HOE.spec.require_paths = Dir['lib']
36
53
  end
37
54
 
38
55
  # compile the extension
39
- begin
40
- gem('rake-compiler')
41
- require 'rake/extensiontask'
42
- Rake::ExtensionTask.new('do_mysql_ext', HOE.spec)
43
- rescue LoadError
44
- warn "To cross-compile, install rake-compiler (gem install rake-compiler)"
45
- if tasks_dir.directory?
46
- require tasks_dir + 'ext_helper'
47
- setup_extension('do_mysql_ext', HOE.spec)
56
+ if JRUBY
57
+ Rake::Task['compile:jruby'].invoke
58
+ else
59
+ begin
60
+ gem('rake-compiler')
61
+ require 'rake/extensiontask'
62
+ Rake::ExtensionTask.new('do_mysql_ext', HOE.spec)
63
+ rescue LoadError
64
+ warn "To cross-compile, install rake-compiler (gem install rake-compiler)"
65
+ if tasks_dir.directory?
66
+ require tasks_dir + 'ext_helper'
67
+ setup_c_extension('do_mysql_ext', HOE.spec)
68
+ end
48
69
  end
49
70
  end
50
71
 
@@ -70,7 +91,7 @@ desc 'Run specifications'
70
91
  Spec::Rake::SpecTask.new(:spec) do |t|
71
92
  t.spec_opts << '--format' << 'specdoc' << '--colour'
72
93
  t.spec_opts << '--loadby' << 'random'
73
- t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb')
94
+ t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
74
95
 
75
96
  begin
76
97
  t.rcov = RUN_RCOV
data/buildfile CHANGED
@@ -1,26 +1,27 @@
1
- # Apache Buildr buildfile for do_derby
1
+ # Apache Buildr buildfile for do_mysql
2
2
  # see http://incubator.apache.org/buildr/ for more information on Apache Buildr
3
3
  require 'buildr'
4
4
  require 'pathname'
5
5
 
6
6
  VERSION_NUMBER = '1.0'
7
7
  JDBC_SUPPORT = ['data_objects:jdbc:jar:1.0']
8
+ TARGET_DIR = 'pkg/classes'
8
9
  repositories.remote << 'http://www.ibiblio.org/maven2/'
9
10
 
10
11
  define 'do_mysql' do
11
12
  project.version = VERSION_NUMBER
12
13
  project.group = 'data_objects.rb'
13
14
 
14
- manifest['Copyright'] = 'Alex Coles (C) 2008'
15
+ manifest['Copyright'] = 'Alex Coles (C) 2008-2009'
15
16
 
16
17
  compile.using :target => '1.5', :lint => 'all', :deprecation => 'true'
17
18
 
18
19
  define 'ext-java' do
19
- package :jar
20
+ package(:jar).clean.include(TARGET_DIR)
20
21
 
21
22
  jdbc_support_jar = file('../../do_jdbc/lib/do_jdbc_internal.jar')
22
23
  jdbc_support = artifact('data_objects:jdbc:jar:1.0').from(jdbc_support_jar)
23
24
 
24
- compile.with JDBC_SUPPORT
25
+ compile.into(TARGET_DIR).with(JDBC_SUPPORT)
25
26
  end
26
27
  end
@@ -43,6 +43,7 @@ static ID ID_NEW;
43
43
  static ID ID_NEW_RATIONAL;
44
44
  static ID ID_NEW_DATE;
45
45
  static ID ID_CONST_GET;
46
+ static ID ID_RATIONAL;
46
47
  static ID ID_UTC;
47
48
  static ID ID_ESCAPE_SQL;
48
49
  static ID ID_STRFTIME;
@@ -61,9 +62,6 @@ static VALUE cDO_Reader;
61
62
  // References to Ruby classes that we'll need
62
63
  static VALUE rb_cDate;
63
64
  static VALUE rb_cDateTime;
64
- #ifndef RUBY_19_COMPATIBILITY
65
- static VALUE rb_cRational;
66
- #endif
67
65
  static VALUE rb_cBigDecimal;
68
66
 
69
67
  // Classes that we'll build in Init
@@ -158,7 +156,7 @@ static int jd_from_date(int year, int month, int day) {
158
156
  static VALUE seconds_to_offset(long seconds_offset) {
159
157
  do_int64 num = seconds_offset, den = 86400;
160
158
  reduce(&num, &den);
161
- return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
159
+ return rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den));
162
160
  }
163
161
 
164
162
  static VALUE timezone_to_offset(int hour_offset, int minute_offset) {
@@ -181,7 +179,7 @@ static VALUE parse_date(const char *date) {
181
179
 
182
180
  // Math from Date.jd_to_ajd
183
181
  ajd = jd * 2 - 1;
184
- rational = rb_funcall(rb_cRational, ID_NEW_RATIONAL, 2, INT2NUM(ajd), INT2NUM(2));
182
+ rational = rb_funcall(rb_mKernel, ID_RATIONAL, 2, INT2NUM(ajd), INT2NUM(2));
185
183
  return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
186
184
  }
187
185
 
@@ -293,19 +291,19 @@ static VALUE parse_date_time(const char *date) {
293
291
 
294
292
  reduce(&num, &den);
295
293
 
296
- ajd = rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ull2inum(num), rb_ull2inum(den));
294
+ ajd = rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ull2inum(num), rb_ull2inum(den));
297
295
  offset = timezone_to_offset(hour_offset, minute_offset);
298
296
 
299
297
  return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
300
298
  }
301
299
 
302
300
  // Convert C-string to a Ruby instance of Ruby type "type"
303
- static VALUE typecast(const char* value, unsigned long length, char* type) {
301
+ static VALUE typecast(const char* value, unsigned long length, const char* type) {
304
302
  if (NULL == value)
305
303
  return Qnil;
306
304
 
307
305
  if ( strcmp(type, "Class") == 0) {
308
- return rb_funcall(mDO, rb_intern("find_const"), 1, TAINTED_STRING(value, length));
306
+ return rb_funcall(rb_cObject, rb_intern("full_const_get"), 1, TAINTED_STRING(value, length));
309
307
  } else if ( strcmp(type, "Integer") == 0 || strcmp(type, "Fixnum") == 0 || strcmp(type, "Bignum") == 0 ) {
310
308
  return rb_cstr2inum(value, 10);
311
309
  } else if (0 == strcmp("String", type)) {
@@ -391,9 +389,8 @@ static MYSQL_RES* cCommand_execute_async(VALUE self, MYSQL* db, VALUE query) {
391
389
 
392
390
  VALUE connection = rb_iv_get(self, "@connection");
393
391
 
394
- retval = mysql_ping(db);
395
- if(retval == CR_SERVER_GONE_ERROR) {
396
- CHECK_AND_RAISE(retval, "Mysql server has gone away. \
392
+ if(mysql_ping(db) && mysql_errno(db) == CR_SERVER_GONE_ERROR) {
393
+ CHECK_AND_RAISE(mysql_errno(db), "Mysql server has gone away. \
397
394
  Please report this issue to the Datamapper project. \
398
395
  Specify your at least your MySQL version when filing a ticket");
399
396
  }
@@ -496,9 +493,6 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
496
493
  // mysql_ssl_set(db, key, cert, ca, capath, cipher)
497
494
  // }
498
495
 
499
- my_bool reconnect = 1;
500
- mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect);
501
-
502
496
  result = (MYSQL *)mysql_real_connect(
503
497
  db,
504
498
  host,
@@ -514,6 +508,9 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
514
508
  raise_mysql_error(Qnil, db, -1, NULL);
515
509
  }
516
510
 
511
+ my_bool reconnect = 1;
512
+ mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect);
513
+
517
514
  // Set the connections character set
518
515
  encoding_error = mysql_set_character_set(db, encoding);
519
516
  if (0 != encoding_error) {
@@ -763,7 +760,7 @@ static VALUE cReader_next(VALUE self) {
763
760
  unsigned long *lengths;
764
761
 
765
762
  int i;
766
- char *field_type;
763
+ const char *field_type;
767
764
 
768
765
  if (Qnil == reader_container)
769
766
  return Qfalse;
@@ -806,6 +803,14 @@ static VALUE cReader_fields(VALUE self) {
806
803
  return rb_iv_get(self, "@fields");
807
804
  }
808
805
 
806
+ static VALUE cReader_field_count(VALUE self) {
807
+ return rb_iv_get(self, "@field_count");
808
+ }
809
+
810
+ static VALUE cReader_row_count(VALUE self) {
811
+ return rb_iv_get(self, "@row_count");
812
+ }
813
+
809
814
  void Init_do_mysql_ext() {
810
815
  rb_require("bigdecimal");
811
816
  rb_require("date");
@@ -817,13 +822,13 @@ void Init_do_mysql_ext() {
817
822
  ID_TO_S = rb_intern("to_s");
818
823
  ID_TO_TIME = rb_intern("to_time");
819
824
  ID_NEW = rb_intern("new");
820
- ID_NEW_RATIONAL = rb_intern("new!");
821
825
  #ifdef RUBY_LESS_THAN_186
822
826
  ID_NEW_DATE = rb_intern("new0");
823
827
  #else
824
828
  ID_NEW_DATE = rb_intern("new!");
825
829
  #endif
826
830
  ID_CONST_GET = rb_intern("const_get");
831
+ ID_RATIONAL = rb_intern("Rational");
827
832
  ID_UTC = rb_intern("utc");
828
833
  ID_ESCAPE_SQL = rb_intern("escape_sql");
829
834
  ID_STRFTIME = rb_intern("strftime");
@@ -834,7 +839,6 @@ void Init_do_mysql_ext() {
834
839
  // Store references to a few helpful clases that aren't in Ruby Core
835
840
  rb_cDate = RUBY_CLASS("Date");
836
841
  rb_cDateTime = RUBY_CLASS("DateTime");
837
- rb_cRational = RUBY_CLASS("Rational");
838
842
  rb_cBigDecimal = RUBY_CLASS("BigDecimal");
839
843
 
840
844
  // Get references to the DataObjects module and its classes
@@ -875,4 +879,6 @@ void Init_do_mysql_ext() {
875
879
  rb_define_method(cReader, "next!", cReader_next, 0);
876
880
  rb_define_method(cReader, "values", cReader_values, 0);
877
881
  rb_define_method(cReader, "fields", cReader_fields, 0);
882
+ rb_define_method(cReader, "field_count", cReader_field_count, 0);
883
+ rb_define_method(cReader, "row_count", cReader_row_count, 0);
878
884
  }
@@ -66,8 +66,6 @@ $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
66
66
 
67
67
  if RUBY_VERSION < '1.8.6'
68
68
  $CFLAGS << ' -DRUBY_LESS_THAN_186'
69
- elsif RUBY_VERSION >= '1.9.0'
70
- $CFLAGS << ' -DRUBY_19_COMPATIBILITY'
71
69
  end
72
70
 
73
71
  create_makefile('do_mysql_ext')
data/lib/do_mysql.rb CHANGED
@@ -7,7 +7,7 @@ if RUBY_PLATFORM =~ /java/
7
7
  require 'jdbc/mysql' # the JDBC driver, packaged as a gem
8
8
  end
9
9
 
10
- require File.expand_path(File.join(File.dirname(__FILE__), 'do_mysql_ext'))
10
+ require 'do_mysql_ext'
11
11
  require File.expand_path(File.join(File.dirname(__FILE__), 'do_mysql', 'version'))
12
12
  require File.expand_path(File.join(File.dirname(__FILE__), 'do_mysql', 'transaction'))
13
13
 
@@ -27,7 +27,7 @@ if RUBY_PLATFORM =~ /java/
27
27
  def using_socket?
28
28
  @using_socket
29
29
  end
30
-
30
+
31
31
  def character_set
32
32
  # JDBC API does not provide an easy way to get the current character set
33
33
  # For now, we code the character_set used as utf8
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = "0.9.10.1"
3
+ VERSION = "0.9.11"
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'pathname'
2
4
  require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
5
 
@@ -157,11 +159,21 @@ describe DataObjects::Mysql::Reader do
157
159
 
158
160
  it "should return the proper number of fields" do
159
161
  id = insert("INSERT INTO users (name) VALUES ('Billy Bob')")
162
+
160
163
  select("SELECT id, name, fired_at FROM users WHERE id = ?", nil, id) do |reader|
161
164
  reader.fields.size.should == 3
162
165
  end
163
166
  end
164
167
 
168
+ it "should return proper number of rows and fields using row_count and field_count" do
169
+ pending "Neither do_jdbc nor C-extension return row_count correctly at the moment"
170
+ command = @connection.create_command("SELECT * FROM widgets WHERE id = (SELECT max(id) FROM widgets)")
171
+ reader = command.execute_reader
172
+ reader.field_count.should == 21
173
+ reader.row_count.should == 1
174
+ reader.close
175
+ end
176
+
165
177
  it "should raise an exception if .values is called after reading all available rows" do
166
178
 
167
179
  select("SELECT * FROM widgets LIMIT 2") do |reader|
@@ -180,6 +192,7 @@ describe DataObjects::Mysql::Reader do
180
192
  ]
181
193
  # do_jdbc rewrites "?" as "(?,?)"
182
194
  # to correspond to the JDBC API
195
+
183
196
  select("SELECT * FROM users WHERE id IN ?", nil, ids) do |reader|
184
197
  # select already calls next once for us
185
198
  reader.next!.should == true
@@ -210,10 +223,19 @@ describe DataObjects::Mysql::Reader do
210
223
  end
211
224
  end
212
225
 
226
+ it "should correctly work with default utf8 character set" do
227
+ name = "Билли Боб"
228
+ id = insert("INSERT INTO users (name) VALUES ('#{name}')")
229
+
230
+ select("SELECT name from users WHERE id = ?", [String], id) do |reader|
231
+ reader.values[0].should == name
232
+ end
233
+ end
234
+
213
235
  describe "Date, Time, and DateTime" do
214
236
 
215
237
  it "should return nil when the time is 0" do
216
-
238
+ pending "We need to introduce something like Proxy for typeasting where each SQL type will have _rules_ of casting" if JRUBY
217
239
  # skip the test if the strict dates/times setting is turned on
218
240
  strict_time = select("SHOW VARIABLES LIKE 'sql_mode'") do |reader|
219
241
  reader.values.last.split(',').any? do |mode|
@@ -233,9 +255,11 @@ describe DataObjects::Mysql::Reader do
233
255
  it "should return DateTimes using the current locale's Time Zone" do
234
256
  date = DateTime.now
235
257
  id = insert("INSERT INTO users (name, fired_at) VALUES (?, ?)", 'Sam', date)
258
+
236
259
  select("SELECT fired_at FROM users WHERE id = ?", [DateTime], id) do |reader|
237
260
  reader.values.last.to_s.should == date.to_s
238
261
  end
262
+
239
263
  exec("DELETE FROM users WHERE id = ?", id)
240
264
  end
241
265
 
data/spec/spec_helper.rb CHANGED
@@ -28,7 +28,7 @@ require 'do_mysql'
28
28
  log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
29
29
  FileUtils.mkdir_p(File.dirname(log_path))
30
30
 
31
- DataObjects::Mysql.logger = DataObjects::Logger.new(log_path, 0)
31
+ DataObjects::Mysql.logger = DataObjects::Logger.new(log_path, :debug)
32
32
 
33
33
  at_exit { DataObjects.logger.flush }
34
34
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10.1
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
- - Scott Bauer
7
+ - Dirkjan Bussink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-05 00:00:00 +01:00
12
+ date: 2009-01-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.10.1
23
+ version: 0.9.11
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -34,7 +34,7 @@ dependencies:
34
34
  version:
35
35
  description: A DataObject.rb driver for MySQL
36
36
  email:
37
- - bauer.mail@gmail.com
37
+ - d.bussink@gmail.com
38
38
  executables: []
39
39
 
40
40
  extensions:
@@ -50,7 +50,6 @@ files:
50
50
  - Manifest.txt
51
51
  - README.txt
52
52
  - Rakefile
53
- - TODO
54
53
  - buildfile
55
54
  - ext-java/src/main/java/DoMysqlExtService.java
56
55
  - ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java
data/TODO DELETED
@@ -1,4 +0,0 @@
1
- TODO
2
- ====
3
-
4
- * Add JDBC-based version of this driver.