pg_typecast 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,19 +4,15 @@
4
4
 
5
5
  == Description
6
6
 
7
- Provides typecasting support for the pg gem. The code is extracted from the swift gem as
8
- a drop-in enhancement for users of the pg gem.
7
+ Provides typecasting support for the pg gem. The code is extracted from
8
+ swift (http://github.com/shanna/swift) as a drop-in enhancement for users of
9
+ pg.
9
10
 
10
11
  == Dependencies
11
12
 
12
13
  * ruby >= 1.9.1
13
14
  * pg >= 0.9.0
14
15
 
15
- == Alternatives
16
-
17
- Swift (http://github.com/shanna/swift) is as fast as the pg gem with typecasting support
18
- and drivers for mysql, postgresql and db2.
19
-
20
16
  == Caveats
21
17
 
22
18
  * This gem overrides the PGresult#each method.
@@ -59,10 +55,6 @@ The following table illustrates the typecasting done from postgresql types to na
59
55
  +--------------------+---------------------------+
60
56
 
61
57
 
62
- == TODO
63
-
64
- * tests.
65
-
66
58
  == License
67
59
 
68
60
  See LICENSE.
data/Rakefile CHANGED
@@ -13,8 +13,20 @@ begin
13
13
  gem.files.reject!{|f| f =~ %r{\.gitignore}}
14
14
 
15
15
  gem.add_dependency 'pg', '>= 0.9.0'
16
+
17
+ gem.required_ruby_version = '>= 1.9.1'
16
18
  end
17
19
  Jeweler::GemcutterTasks.new
18
20
  rescue LoadError
19
21
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
22
  end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ task :test => :check_dependencies
32
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/ext/pg_typecast.c CHANGED
@@ -104,7 +104,7 @@ inline VALUE typecast(const char* data, uint64_t len, int pgtype) {
104
104
  }
105
105
 
106
106
  VALUE result_each(VALUE self) {
107
- int r, c, rows, cols, *types;
107
+ int r, c, rows, cols, *types, failed;
108
108
  PGresult *res;
109
109
  Data_Get_Struct(self, PGresult, res);
110
110
 
@@ -123,7 +123,9 @@ VALUE result_each(VALUE self) {
123
123
  rb_hash_aset(tuple, rb_ary_entry(fields, c),
124
124
  PQgetisnull(res, r, c) ? Qnil : typecast(PQgetvalue(res, r, c), PQgetlength(res, r, c), types[c]));
125
125
  }
126
- rb_yield(tuple);
126
+ rb_protect(rb_yield, tuple, &failed);
127
+ if (failed)
128
+ rb_jump_tag(failed);
127
129
  }
128
130
 
129
131
  free(types);
data/pg_typecast.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pg_typecast}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bharanee Rathna"]
12
- s.date = %q{2010-09-16}
12
+ s.date = %q{2010-09-17}
13
13
  s.description = %q{Extensions to pg gem supporting typecasting.}
14
14
  s.email = ["deepfryed@gmail.com"]
15
15
  s.extensions = ["ext/extconf.rb"]
@@ -24,19 +24,26 @@ Gem::Specification.new do |s|
24
24
  "VERSION",
25
25
  "ext/extconf.rb",
26
26
  "ext/pg_typecast.c",
27
- "pg_typecast.gemspec"
27
+ "pg_typecast.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_types.rb"
28
30
  ]
29
31
  s.homepage = %q{http://github.com/deepfryed/pg_typecast}
30
32
  s.rdoc_options = ["--charset=UTF-8"]
31
33
  s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.5}
34
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
35
+ s.rubygems_version = %q{1.3.7}
33
36
  s.summary = %q{Extensions to pg gem supporting typecasting.}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_types.rb"
40
+ ]
34
41
 
35
42
  if s.respond_to? :specification_version then
36
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
44
  s.specification_version = 3
38
45
 
39
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
47
  s.add_runtime_dependency(%q<pg>, [">= 0.9.0"])
41
48
  else
42
49
  s.add_dependency(%q<pg>, [">= 0.9.0"])
data/test/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative '../ext/pg_typecast'
2
+ require 'minitest/unit'
3
+ require 'minitest/spec'
4
+
5
+ MiniTest::Unit.autorun
@@ -0,0 +1,43 @@
1
+ require_relative 'helper'
2
+
3
+ describe 'typecasting' do
4
+ before do
5
+ @db = PGconn.connect 'host=127.0.0.1 dbname=test'
6
+ @db.exec %q{drop table if exists users}
7
+ @db.exec %q{
8
+ create table users(
9
+ id serial,
10
+ name text,
11
+ age integer,
12
+ height float,
13
+ hacker bool,
14
+ slacker bool,
15
+ nil text default null,
16
+ created date not null default now(),
17
+ updated timestamp with time zone not null default now()
18
+ )
19
+ }
20
+
21
+ bind = [ 'jim', 32, 178.71, true, false ]
22
+ @db.exec %q{insert into users(name,age,height,hacker,slacker) values($1, $2, $3, $4, $5)}, bind
23
+ end
24
+
25
+ it 'should typecast correctly' do
26
+ result = @db.exec(%q{select * from users limit 1}).first
27
+ assert_kind_of Integer, result[:id]
28
+ assert_kind_of String, result[:name]
29
+ assert_kind_of Integer, result[:age]
30
+ assert_kind_of Float, result[:height]
31
+ assert_kind_of TrueClass, result[:hacker]
32
+ assert_kind_of FalseClass, result[:slacker]
33
+ assert_kind_of Date, result[:created]
34
+ assert_kind_of Time, result[:updated]
35
+ assert_equal nil, result[:nil]
36
+ end
37
+
38
+ it 'should cascade exceptions in yield' do
39
+ assert_raises(RuntimeError) do
40
+ @db.exec(%q{select * from users limit 1}).each { raise "foo" }
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_typecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Bharanee Rathna
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-09-16 00:00:00 +10:00
18
+ date: 2010-09-17 00:00:00 +10:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: pg
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 0
23
34
  version: 0.9.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description: Extensions to pg gem supporting typecasting.
26
38
  email:
27
39
  - deepfryed@gmail.com
@@ -40,6 +52,8 @@ files:
40
52
  - ext/extconf.rb
41
53
  - ext/pg_typecast.c
42
54
  - pg_typecast.gemspec
55
+ - test/helper.rb
56
+ - test/test_types.rb
43
57
  has_rdoc: true
44
58
  homepage: http://github.com/deepfryed/pg_typecast
45
59
  licenses: []
@@ -50,23 +64,32 @@ rdoc_options:
50
64
  require_paths:
51
65
  - lib
52
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
53
68
  requirements:
54
69
  - - ">="
55
70
  - !ruby/object:Gem::Version
56
- version: "0"
57
- version:
71
+ hash: 49
72
+ segments:
73
+ - 1
74
+ - 9
75
+ - 1
76
+ version: 1.9.1
58
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
59
79
  requirements:
60
80
  - - ">="
61
81
  - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
62
85
  version: "0"
63
- version:
64
86
  requirements: []
65
87
 
66
88
  rubyforge_project:
67
- rubygems_version: 1.3.5
89
+ rubygems_version: 1.3.7
68
90
  signing_key:
69
91
  specification_version: 3
70
92
  summary: Extensions to pg gem supporting typecasting.
71
- test_files: []
72
-
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/test_types.rb