do_mysql 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -42,7 +42,44 @@ end
42
42
  # Specs
43
43
 
44
44
  desc 'Run specifications'
45
- Spec::Rake::SpecTask.new(:spec => [ :compile ]) do |t|
46
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
47
- t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + 'spec/**/*_spec.rb')
45
+ Spec::Rake::SpecTask.new(:spec) do |t|
46
+ t.spec_opts << '--format' << 'specdoc' << '--colour'
47
+ t.spec_opts << '--loadby' << 'random'
48
+ t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb')
49
+
50
+ begin
51
+ t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
52
+ t.rcov_opts << '--exclude' << 'spec'
53
+ t.rcov_opts << '--text-summary'
54
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
55
+ rescue Exception
56
+ # rcov not installed
57
+ end
48
58
  end
59
+
60
+ namespace :ci do
61
+
62
+ task :prepare do
63
+ rm_rf ROOT + "ci"
64
+ mkdir_p ROOT + "ci"
65
+ mkdir_p ROOT + "ci/doc"
66
+ mkdir_p ROOT + "ci/cyclomatic"
67
+ mkdir_p ROOT + "ci/token"
68
+ end
69
+
70
+ task :publish do
71
+ out = ENV['CC_BUILD_ARTIFACTS'] || "out"
72
+ mkdir_p out unless File.directory? out
73
+
74
+ mv "ci/rspec_report.html", "#{out}/rspec_report.html"
75
+ mv "ci/coverage", "#{out}/coverage"
76
+ end
77
+
78
+ task :spec => :prepare do
79
+ Rake::Task[:spec].invoke
80
+ mv ROOT + "coverage", ROOT + "ci/coverage"
81
+ end
82
+
83
+ end
84
+
85
+ task :ci => ["ci:spec"]
data/buildfile CHANGED
@@ -18,7 +18,7 @@ define 'do_mysql' do
18
18
  define 'ext-java' do
19
19
  package :jar
20
20
 
21
- jdbc_support_jar = file('../../do_jdbc-support/lib/do_jdbc_internal.jar')
21
+ jdbc_support_jar = file('../../do_jdbc/lib/do_jdbc_internal.jar')
22
22
  jdbc_support = artifact('data_objects:jdbc:jar:1.0').from(jdbc_support_jar)
23
23
 
24
24
  compile.with JDBC_SUPPORT
@@ -4,6 +4,7 @@
4
4
  #include <math.h>
5
5
  #include <ctype.h>
6
6
  #include <time.h>
7
+ #include <my_global.h>
7
8
  #include <mysql.h>
8
9
  #include <errmsg.h>
9
10
  #include <mysqld_error.h>
@@ -16,6 +17,14 @@
16
17
  #define CHECK_AND_RAISE(mysql_result_value) if (0 != mysql_result_value) { raise_mysql_error(connection, db, mysql_result_value); }
17
18
  #define PUTS(string) rb_funcall(rb_mKernel, rb_intern("puts"), 1, RUBY_STRING(string))
18
19
 
20
+ #ifndef RSTRING_PTR
21
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
22
+ #endif
23
+
24
+ #ifndef RSTRING_LEN
25
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
26
+ #endif
27
+
19
28
  #ifdef _WIN32
20
29
  #define do_int64 signed __int64
21
30
  #else
@@ -451,6 +460,9 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
451
460
  // mysql_ssl_set(db, key, cert, ca, capath, cipher)
452
461
  // }
453
462
 
463
+ my_bool reconnect = 1;
464
+ mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect);
465
+
454
466
  result = (MYSQL *)mysql_real_connect(
455
467
  db,
456
468
  host,
@@ -590,11 +602,50 @@ static VALUE build_query_from_args(VALUE klass, int count, VALUE *args) {
590
602
  return query;
591
603
  }
592
604
 
605
+ static MYSQL_RES* cCommand_execute_async(VALUE self, MYSQL* db, VALUE query) {
606
+ int socket_fd;
607
+ int retval;
608
+ fd_set rset;
609
+ char* str = RSTRING_PTR(query);
610
+ int len = RSTRING_LEN(query);
611
+
612
+ VALUE connection = rb_iv_get(self, "@connection");
613
+
614
+ retval = mysql_send_query(db, str, len);
615
+ data_objects_debug(query);
616
+ CHECK_AND_RAISE(retval);
617
+
618
+ socket_fd = db->net.fd;
619
+
620
+ for(;;) {
621
+ FD_ZERO(&rset);
622
+ FD_SET(socket_fd, &rset);
623
+
624
+ retval = rb_thread_select(socket_fd + 1, &rset, NULL, NULL, NULL);
625
+
626
+ if (retval < 0) {
627
+ rb_sys_fail(0);
628
+ }
629
+
630
+ if (retval == 0) {
631
+ continue;
632
+ }
633
+
634
+ if (db->status == MYSQL_STATUS_READY) {
635
+ break;
636
+ }
637
+ }
638
+
639
+ retval = mysql_read_query_result(db);
640
+ CHECK_AND_RAISE(retval);
641
+
642
+ return mysql_store_result(db);
643
+ }
644
+
593
645
  static VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) {
594
646
  VALUE query;
595
647
 
596
648
  MYSQL_RES *response = 0;
597
- int query_result = 0;
598
649
 
599
650
  my_ulonglong affected_rows;
600
651
  VALUE connection = rb_iv_get(self, "@connection");
@@ -605,12 +656,8 @@ static VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) {
605
656
  MYSQL *db = DATA_PTR(mysql_connection);
606
657
  query = build_query_from_args(self, argc, argv);
607
658
 
608
- data_objects_debug(query);
659
+ response = cCommand_execute_async(self, db, query);
609
660
 
610
- query_result = mysql_query(db, StringValuePtr(query));
611
- CHECK_AND_RAISE(query_result);
612
-
613
- response = (MYSQL_RES *)mysql_store_result(db);
614
661
  affected_rows = mysql_affected_rows(db);
615
662
  mysql_free_result(response);
616
663
 
@@ -624,7 +671,6 @@ static VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
624
671
  VALUE query, reader;
625
672
  VALUE field_names, field_types;
626
673
 
627
- int query_result = 0;
628
674
  int field_count;
629
675
  int i;
630
676
 
@@ -640,12 +686,8 @@ static VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
640
686
  MYSQL_FIELD *field;
641
687
 
642
688
  query = build_query_from_args(self, argc, argv);
643
- data_objects_debug(query);
644
-
645
- query_result = mysql_query(db, StringValuePtr(query));
646
- CHECK_AND_RAISE(query_result);
647
689
 
648
- response = (MYSQL_RES *)mysql_use_result(db);
690
+ response = cCommand_execute_async(self, db, query);
649
691
 
650
692
  if (!response) {
651
693
  return Qnil;
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'data_objects'
3
- require 'do_jdbc-support' if RUBY_PLATFORM =~ /java/ # generic, shared JDBC support code
4
3
  require 'do_mysql_ext' # the C/Java extension for this DO driver
5
4
  require 'do_mysql/transaction'
6
5
 
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Mysql
3
- VERSION = "0.9.5"
3
+ VERSION = "0.9.6"
4
4
  end
5
5
  end
@@ -26,6 +26,23 @@ describe DataObjects::Mysql do
26
26
  connection.close
27
27
  end
28
28
 
29
+ it "should be able to send querues asynchronuously in parallel" do
30
+ threads = []
31
+
32
+ start = Time.now
33
+ 4.times do |i|
34
+ threads << Thread.new do
35
+ connection = DataObjects::Connection.new("mysql://root@127.0.0.1:3306/do_mysql_test")
36
+ command = connection.create_command("SELECT sleep(1)")
37
+ result = command.execute_non_query
38
+ end
39
+ end
40
+
41
+ threads.each{|t| t.join }
42
+ finish = Time.now
43
+ (finish - start).should < 2
44
+ end
45
+
29
46
  #
30
47
  # I comment this out partly to raise the issue for discussion. Socket files are afaik not supported under windows. Does this
31
48
  # mean that we should test for it on unix boxes but not on windows boxes? Or does it mean that it should not be speced at all?
@@ -115,9 +132,9 @@ describe DataObjects::Mysql::Connection do
115
132
 
116
133
  it "should delete itself from the pool" do
117
134
  pool = @connection.instance_variable_get(:@__pool)
118
- count = pool.reserved_count
135
+ count = pool.size
119
136
  lambda { @connection.create_command("INSERT INTO non_exista (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
120
- Extlib::Pooling.pools.detect { |p| p == pool }.instance_variable_get(:@reserved_count).should == count-1
137
+ Extlib::Pooling.pools.detect { |p| p == pool }.size.should == count-1
121
138
  end
122
139
 
123
140
  it "should not raise an error error executing a non query on a closed connection" do
@@ -16,8 +16,8 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_
16
16
  require 'data_objects'
17
17
 
18
18
  if JRUBY
19
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc-support', 'lib'))
20
- require 'do_jdbc-support'
19
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
20
+ require 'do_jdbc'
21
21
  end
22
22
 
23
23
  # put the pre-compiled extension in the path to be found
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Bauer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-26 00:00:00 -05:00
12
+ date: 2008-10-12 00:00:00 -06: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.5
23
+ version: 0.9.6
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe