swift 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.10.0
data/ext/adapter.cc CHANGED
@@ -87,11 +87,16 @@ static VALUE adapter_escape(VALUE self, VALUE value) {
87
87
 
88
88
  // TODO: Change bind_values to an array in the interface? Avoid array -> splat -> array.
89
89
  static VALUE adapter_execute(int argc, VALUE *argv, VALUE self) {
90
- VALUE statement, bind_values, block, rows;
90
+ VALUE statement, bind_values, block, rows, scheme = Qnil;
91
91
 
92
92
  dbi::Handle *handle = adapter_handle(self);
93
93
  rb_scan_args(argc, argv, "1*&", &statement, &bind_values, &block);
94
94
 
95
+ if (TYPE(statement) == T_CLASS) {
96
+ scheme = statement;
97
+ statement = rb_ary_shift(bind_values);
98
+ }
99
+
95
100
  try {
96
101
  Query query;
97
102
  query.sql = CSTRING(statement);
@@ -104,6 +109,8 @@ static VALUE adapter_execute(int argc, VALUE *argv, VALUE self) {
104
109
  rb_raise(eSwiftRuntimeError, "%s", query.error);
105
110
 
106
111
  VALUE result = result_wrap_handle(cSwiftResult, self, handle->conn()->result(), true);
112
+ if (!NIL_P(scheme))
113
+ rb_iv_set(result, "@scheme", scheme);
107
114
  return rb_block_given_p() ? result_each(result) : result;
108
115
  }
109
116
  CATCH_DBI_EXCEPTIONS();
@@ -177,7 +184,7 @@ static VALUE adapter_rollback(int argc, VALUE *argv, VALUE self) {
177
184
 
178
185
  static VALUE adapter_transaction(int argc, VALUE *argv, VALUE self) {
179
186
  int status;
180
- VALUE sp, block;
187
+ VALUE sp, block, block_result = Qnil;
181
188
 
182
189
  dbi::Handle *handle = adapter_handle(self);
183
190
 
@@ -188,7 +195,7 @@ static VALUE adapter_transaction(int argc, VALUE *argv, VALUE self) {
188
195
 
189
196
  try {
190
197
  handle->begin(save_point);
191
- rb_protect(rb_yield, self, &status);
198
+ block_result = rb_protect(rb_yield, self, &status);
192
199
  if (!status && handle->transactions().size() > 0) {
193
200
  handle->commit(save_point);
194
201
  }
@@ -199,7 +206,7 @@ static VALUE adapter_transaction(int argc, VALUE *argv, VALUE self) {
199
206
  }
200
207
  CATCH_DBI_EXCEPTIONS();
201
208
 
202
- return Qtrue;
209
+ return block_result;
203
210
  }
204
211
 
205
212
  static VALUE adapter_write(int argc, VALUE *argv, VALUE self) {
data/swift.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{swift}
8
- s.version = "0.9.1"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shane Hanna", "Bharanee 'Barney' Rathna"]
12
- s.date = %q{2011-02-10}
12
+ s.date = %q{2011-04-04}
13
13
  s.description = %q{A rational rudimentary database abstraction.}
14
14
  s.email = ["shane.hanna@gmail.com", "deepfryed@gmail.com"]
15
15
  s.extensions = ["ext/extconf.rb"]
data/test/test_scheme.rb CHANGED
@@ -57,6 +57,11 @@ describe 'scheme' do
57
57
  Swift.db.migrate! @user
58
58
  end
59
59
 
60
+ it 'should return scheme instance when given scheme in #execute' do
61
+ user = @user.create
62
+ assert_equal 1, Swift.db.execute(@user, 'select * from users').first.id
63
+ end
64
+
60
65
  it 'adapter should destroy valid instance' do
61
66
  user = @user.create
62
67
  assert_equal 1, user.id
@@ -25,6 +25,10 @@ describe 'Adapter' do
25
25
  end
26
26
  end
27
27
 
28
+ it 'should return result from block' do
29
+ assert_equal :foobar, @db.transaction {|db| foobar = 1; foobar = :foobar }
30
+ end
31
+
28
32
  describe 'commits work' do
29
33
  before do
30
34
  @db.execute('delete from users')
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 9
8
- - 1
9
- version: 0.9.1
7
+ - 10
8
+ - 0
9
+ version: 0.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shane Hanna
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-10 00:00:00 +11:00
18
+ date: 2011-04-04 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency