pg 0.15.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/BSDL +2 -2
  5. data/ChangeLog +0 -3022
  6. data/History.rdoc +370 -4
  7. data/Manifest.txt +39 -19
  8. data/README-Windows.rdoc +17 -28
  9. data/README.ja.rdoc +1 -2
  10. data/README.rdoc +113 -14
  11. data/Rakefile +97 -36
  12. data/Rakefile.cross +109 -83
  13. data/ext/errorcodes.def +1032 -0
  14. data/ext/errorcodes.rb +45 -0
  15. data/ext/errorcodes.txt +494 -0
  16. data/ext/extconf.rb +55 -52
  17. data/ext/gvl_wrappers.c +4 -0
  18. data/ext/gvl_wrappers.h +94 -38
  19. data/ext/pg.c +273 -121
  20. data/ext/pg.h +292 -50
  21. data/ext/pg_binary_decoder.c +229 -0
  22. data/ext/pg_binary_encoder.c +163 -0
  23. data/ext/pg_coder.c +561 -0
  24. data/ext/pg_connection.c +1811 -1051
  25. data/ext/pg_copy_coder.c +599 -0
  26. data/ext/pg_errors.c +95 -0
  27. data/ext/pg_record_coder.c +491 -0
  28. data/ext/pg_result.c +917 -203
  29. data/ext/pg_text_decoder.c +987 -0
  30. data/ext/pg_text_encoder.c +814 -0
  31. data/ext/pg_tuple.c +549 -0
  32. data/ext/pg_type_map.c +166 -0
  33. data/ext/pg_type_map_all_strings.c +116 -0
  34. data/ext/pg_type_map_by_class.c +244 -0
  35. data/ext/pg_type_map_by_column.c +313 -0
  36. data/ext/pg_type_map_by_mri_type.c +284 -0
  37. data/ext/pg_type_map_by_oid.c +356 -0
  38. data/ext/pg_type_map_in_ruby.c +299 -0
  39. data/ext/pg_util.c +149 -0
  40. data/ext/pg_util.h +65 -0
  41. data/lib/pg.rb +31 -9
  42. data/lib/pg/basic_type_mapping.rb +522 -0
  43. data/lib/pg/binary_decoder.rb +23 -0
  44. data/lib/pg/coder.rb +104 -0
  45. data/lib/pg/connection.rb +235 -30
  46. data/lib/pg/constants.rb +2 -1
  47. data/lib/pg/exceptions.rb +2 -1
  48. data/lib/pg/result.rb +33 -6
  49. data/lib/pg/text_decoder.rb +46 -0
  50. data/lib/pg/text_encoder.rb +59 -0
  51. data/lib/pg/tuple.rb +30 -0
  52. data/lib/pg/type_map_by_column.rb +16 -0
  53. data/spec/{lib/helpers.rb → helpers.rb} +154 -52
  54. data/spec/pg/basic_type_mapping_spec.rb +630 -0
  55. data/spec/pg/connection_spec.rb +1352 -426
  56. data/spec/pg/connection_sync_spec.rb +41 -0
  57. data/spec/pg/result_spec.rb +508 -105
  58. data/spec/pg/tuple_spec.rb +333 -0
  59. data/spec/pg/type_map_by_class_spec.rb +138 -0
  60. data/spec/pg/type_map_by_column_spec.rb +226 -0
  61. data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
  62. data/spec/pg/type_map_by_oid_spec.rb +149 -0
  63. data/spec/pg/type_map_in_ruby_spec.rb +164 -0
  64. data/spec/pg/type_map_spec.rb +22 -0
  65. data/spec/pg/type_spec.rb +1123 -0
  66. data/spec/pg_spec.rb +35 -16
  67. metadata +163 -84
  68. metadata.gz.sig +0 -0
  69. data/sample/array_insert.rb +0 -20
  70. data/sample/async_api.rb +0 -106
  71. data/sample/async_copyto.rb +0 -39
  72. data/sample/async_mixed.rb +0 -56
  73. data/sample/check_conn.rb +0 -21
  74. data/sample/copyfrom.rb +0 -81
  75. data/sample/copyto.rb +0 -19
  76. data/sample/cursor.rb +0 -21
  77. data/sample/disk_usage_report.rb +0 -186
  78. data/sample/issue-119.rb +0 -94
  79. data/sample/losample.rb +0 -69
  80. data/sample/minimal-testcase.rb +0 -17
  81. data/sample/notify_wait.rb +0 -72
  82. data/sample/pg_statistics.rb +0 -294
  83. data/sample/replication_monitor.rb +0 -231
  84. data/sample/test_binary_values.rb +0 -33
  85. data/sample/wal_shipper.rb +0 -434
  86. data/sample/warehouse_partitions.rb +0 -320
data/README-Windows.rdoc CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  In order to build this extension on MS Windows you will need a couple things.
4
4
 
5
- First, a compiler. For the one click installer this means you should either
6
- use VC++ 6.0 or the compiler that comes with cygwin or mingw if you're
7
- building on that platform.
5
+ First, a compiler. For the one click installer this means you should use
6
+ the DevKit or the compiler that comes with cygwin if you're building on that
7
+ platform.
8
8
 
9
9
  If you've built Ruby yourself, you should use the same compiler to build
10
10
  this library that you used to build Ruby.
@@ -29,39 +29,28 @@ Adjust your path accordingly. BE SURE TO USE THE SHORT PATH NAMES! If you
29
29
  try to use a path with spaces in it, the nmake.exe program will choke.
30
30
 
31
31
 
32
- == Cross compiling for mswin32
32
+ == Building binary 'pg' gems for MS Windows
33
33
 
34
- Using rake-compiler a cross compiled pg gem can be build on a Linux or MacOS X
35
- host for the win32 platform. The generated gem is statically linked against
36
- libpq and libssl. OpenSSL and PostgreSQL are downloaded and compiled from the
37
- sources. There are no runtime dependencies to any but the standard Windows
38
- DLLs.
34
+ Binary gems for windows can be built on Linux, OS-X and even on Windows
35
+ with the help of docker. This is how regular windows gems are built for
36
+ rubygems.org .
39
37
 
40
- Install mingw32 using the instructions in rake-compiler's README.
41
- For Debian/Ubuntu it is <tt>apt-get install gcc-mingw32</tt> .
42
- Use ruby-1.8.7 for the following commands.
38
+ To do this, install boot2docker {on Windows}[https://github.com/boot2docker/windows-installer/releases]
39
+ or {on OS X}[https://github.com/boot2docker/osx-installer/releases] and make
40
+ sure it is started. A native Docker installation is best on Linux.
43
41
 
44
- Download and cross compile ruby 1.8 and 1.9 for win32 with:
42
+ Then run:
45
43
 
46
- rake-compiler cross-ruby VERSION=1.8.7-p352
47
- rake-compiler cross-ruby VERSION=1.9.2-p290
44
+ rake gem:windows
48
45
 
49
- Download and cross compile pg for win32:
50
-
51
- rake cross native gem
52
-
53
- or with custom versions:
54
-
55
- rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2 \
56
- OPENSSL_VERSION=1.0.0e POSTGRESQL_VERSION=9.1.1
57
-
58
- If everything works, there should be pg-VERSION-x86-mingw32.gem in the pkg
59
- directory.
46
+ This will download a docker image suited for building windows gems, and it
47
+ will download and build OpenSSL and PostgreSQL. Finally the gem is built
48
+ containing binaries for all supported ruby versions.
60
49
 
61
50
 
62
51
  == Reporting Problems
63
52
 
64
- If you have any problems you can submit them via
65
- [the project's issue-tracker][bitbucket]. And submit questions, problems, or
53
+ If you have any problems you can submit them via {the project's
54
+ issue-tracker}[https://github.com/ged/ruby-pg/issues]. And submit questions, problems, or
66
55
  solutions, so that it can be improved.
67
56
 
data/README.ja.rdoc CHANGED
@@ -1,7 +1,6 @@
1
1
  = pg
2
2
 
3
- home :: https://bitbucket.org/ged/ruby-pg
4
- mirror :: https://github.com/ged/ruby-pg
3
+ home :: https://github.com/ged/ruby-pg
5
4
  docs :: http://deveiate.org/code/pg
6
5
 
7
6
 
data/README.rdoc CHANGED
@@ -1,15 +1,16 @@
1
1
  = pg
2
2
 
3
- home :: https://bitbucket.org/ged/ruby-pg
4
- mirror :: https://github.com/ged/ruby-pg
3
+ home :: https://github.com/ged/ruby-pg
5
4
  docs :: http://deveiate.org/code/pg
6
5
 
6
+ {<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/ged/ruby-pg">}[https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
7
+
7
8
 
8
9
  == Description
9
10
 
10
11
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
11
12
 
12
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
13
+ It works with {PostgreSQL 9.2 and later}[http://www.postgresql.org/support/versioning/].
13
14
 
14
15
  A small example usage:
15
16
 
@@ -21,7 +22,7 @@ A small example usage:
21
22
  conn = PG.connect( dbname: 'sales' )
22
23
  conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
23
24
  puts " PID | User | Query"
24
- result.each do |row|
25
+ result.each do |row|
25
26
  puts " %7d | %-16s | %s " %
26
27
  row.values_at('procpid', 'usename', 'current_query')
27
28
  end
@@ -29,18 +30,30 @@ A small example usage:
29
30
 
30
31
  == Build Status
31
32
 
32
- {<img src="https://travis-ci.org/ged/ruby-pg.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ged/ruby-pg]
33
+ {<img src="https://travis-ci.org/ged/ruby-pg.svg?branch=master" alt="Build Status Travis-CI" />}[https://travis-ci.org/ged/ruby-pg]
34
+ {<img src="https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg-9j8l3]
33
35
 
34
36
 
35
37
  == Requirements
36
38
 
37
- * Ruby 1.9.3-p392, or 2.0.0-p0.
38
- * PostgreSQL 8.4.x or later (with headers, -dev packages, etc).
39
+ * Ruby 2.2 or newer
40
+ * PostgreSQL 9.2.x or later (with headers, -dev packages, etc).
39
41
 
40
- It may work with earlier versions of Ruby/PostgreSQL as well, but those are
42
+ It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
41
43
  not regularly tested.
42
44
 
43
45
 
46
+ == Versioning
47
+
48
+ We tag and release gems according to the {Semantic Versioning}[http://semver.org/] principle.
49
+
50
+ As a result of this policy, you can (and should) specify a dependency on this gem using the {Pessimistic Version Constraint}[http://guides.rubygems.org/patterns/#pessimistic-version-constraint] with two digits of precision.
51
+
52
+ For example:
53
+
54
+ spec.add_dependency 'pg', '~> 1.0'
55
+
56
+
44
57
  == How To Install
45
58
 
46
59
  Install via RubyGems:
@@ -63,12 +76,99 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
63
76
  {mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
64
77
  want to chat about something.
65
78
 
79
+ If you want to install as a signed gem, the public certs of the gem signers
80
+ can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
81
+ of the repository.
82
+
83
+
84
+ == Type Casts
85
+
86
+ Pg can optionally type cast result values and query parameters in Ruby or
87
+ native C code. This can speed up data transfers to and from the database,
88
+ because String allocations are reduced and conversions in (slower) Ruby code
89
+ can be omitted.
90
+
91
+ Very basic type casting can be enabled by:
92
+
93
+ conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
94
+ # ... this works for result value mapping:
95
+ conn.exec("select 1, now(), '{2,3}'::int[]").values
96
+ # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
97
+
98
+ conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
99
+ # ... and this for param value mapping:
100
+ conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
101
+ # => [["1", "1.2300000000000000E+00", "{2,3}"]]
102
+
103
+ But Pg's type casting is highly customizable. That's why it's divided into
104
+ 2 layers:
105
+
106
+ === Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
107
+
108
+ This is the lower layer, containing encoding classes that convert Ruby
109
+ objects for transmission to the DBMS and decoding classes to convert
110
+ received data back to Ruby objects. The classes are namespaced according
111
+ to their format and direction in PG::TextEncoder, PG::TextDecoder,
112
+ PG::BinaryEncoder and PG::BinaryDecoder.
113
+
114
+ It is possible to assign a type OID, format code (text or binary) and
115
+ optionally a name to an encoder or decoder object. It's also possible
116
+ to build composite types by assigning an element encoder/decoder.
117
+ PG::Coder objects can be used to set up a PG::TypeMap or alternatively
118
+ to convert single values to/from their string representation.
119
+
120
+ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
121
+ * Integer: {TE}[rdoc-ref:PG::TextEncoder::Integer], {TD}[rdoc-ref:PG::TextDecoder::Integer], {BD}[rdoc-ref:PG::BinaryDecoder::Integer] 💡 No links? Switch to {here}[https://deveiate.org/code/pg/README_rdoc.html#label-Type+Casts] 💡
122
+ * BE: {Int2}[rdoc-ref:PG::BinaryEncoder::Int2], {Int4}[rdoc-ref:PG::BinaryEncoder::Int4], {Int8}[rdoc-ref:PG::BinaryEncoder::Int8]
123
+ * Float: {TE}[rdoc-ref:PG::TextEncoder::Float], {TD}[rdoc-ref:PG::TextDecoder::Float], {BD}[rdoc-ref:PG::BinaryDecoder::Float]
124
+ * Numeric: {TE}[rdoc-ref:PG::TextEncoder::Numeric], {TD}[rdoc-ref:PG::TextDecoder::Numeric]
125
+ * Boolean: {TE}[rdoc-ref:PG::TextEncoder::Boolean], {TD}[rdoc-ref:PG::TextDecoder::Boolean], {BE}[rdoc-ref:PG::BinaryEncoder::Boolean], {BD}[rdoc-ref:PG::BinaryDecoder::Boolean]
126
+ * String: {TE}[rdoc-ref:PG::TextEncoder::String], {TD}[rdoc-ref:PG::TextDecoder::String], {BE}[rdoc-ref:PG::BinaryEncoder::String], {BD}[rdoc-ref:PG::BinaryDecoder::String]
127
+ * Bytea: {TE}[rdoc-ref:PG::TextEncoder::Bytea], {TD}[rdoc-ref:PG::TextDecoder::Bytea], {BE}[rdoc-ref:PG::BinaryEncoder::Bytea], {BD}[rdoc-ref:PG::BinaryDecoder::Bytea]
128
+ * Base64: {TE}[rdoc-ref:PG::TextEncoder::ToBase64], {TD}[rdoc-ref:PG::TextDecoder::FromBase64], {BE}[rdoc-ref:PG::BinaryEncoder::FromBase64], {BD}[rdoc-ref:PG::BinaryDecoder::ToBase64]
129
+ * Timestamp:
130
+ * TE: {local}[rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone], {UTC}[rdoc-ref:PG::TextEncoder::TimestampUtc], {with-TZ}[rdoc-ref:PG::TextEncoder::TimestampWithTimeZone]
131
+ * TD: {local}[rdoc-ref:PG::TextDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::TextDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::TextDecoder::TimestampUtcToLocal]
132
+ * BD: {local}[rdoc-ref:PG::BinaryDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::BinaryDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal]
133
+ * Date: {TE}[rdoc-ref:PG::TextEncoder::Date], {TD}[rdoc-ref:PG::TextDecoder::Date]
134
+ * JSON and JSONB: {TE}[rdoc-ref:PG::TextEncoder::JSON], {TD}[rdoc-ref:PG::TextDecoder::JSON]
135
+ * Inet: {TE}[rdoc-ref:PG::TextEncoder::Inet], {TD}[rdoc-ref:PG::TextDecoder::Inet]
136
+ * Array: {TE}[rdoc-ref:PG::TextEncoder::Array], {TD}[rdoc-ref:PG::TextDecoder::Array]
137
+ * Composite Type (also called "Row" or "Record"): {TE}[rdoc-ref:PG::TextEncoder::Record], {TD}[rdoc-ref:PG::TextDecoder::Record]
138
+
139
+ The following text formats can also be encoded although they are not used as column type:
140
+ * COPY input and output data: {TE}[rdoc-ref:PG::TextEncoder::CopyRow], {TD}[rdoc-ref:PG::TextDecoder::CopyRow]
141
+ * Literal for insertion into SQL string: {TE}[rdoc-ref:PG::TextEncoder::QuotedLiteral]
142
+ * SQL-Identifier: {TE}[rdoc-ref:PG::TextEncoder::Identifier], {TD}[rdoc-ref:PG::TextDecoder::Identifier]
143
+
144
+ === PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
145
+
146
+ A TypeMap defines which value will be converted by which encoder/decoder.
147
+ There are different type map strategies, implemented by several derivations
148
+ of this class. They can be chosen and configured according to the particular
149
+ needs for type casting. The default type map is PG::TypeMapAllStrings.
150
+
151
+ A type map can be assigned per connection or per query respectively per
152
+ result set. Type maps can also be used for COPY in and out data streaming.
153
+ See PG::Connection#copy_data .
154
+
155
+ The following base type maps are available:
156
+ * PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
157
+ * PG::TypeMapByClass - selects encoder based on the class of the value to be sent
158
+ * PG::TypeMapByColumn - selects encoder and decoder by column order
159
+ * PG::TypeMapByOid - selects decoder by PostgreSQL type OID
160
+ * PG::TypeMapInRuby - define a custom type map in ruby
161
+
162
+ The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
163
+ * PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
164
+ * PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
165
+ * PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
166
+
66
167
 
67
168
  == Contributing
68
169
 
69
- To report bugs, suggest features, or check out the source with Mercurial,
70
- {check out the project page}[http://bitbucket.org/ged/ruby-pg]. If you prefer
71
- Git, there's also a {Github mirror}[https://github.com/ged/ruby-pg].
170
+ To report bugs, suggest features, or check out the source with Git,
171
+ {check out the project page}[https://github.com/ged/ruby-pg].
72
172
 
73
173
  After checking out the source, run:
74
174
 
@@ -83,7 +183,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
83
183
 
84
184
  == Copying
85
185
 
86
- Copyright (c) 1997-2013 by the authors.
186
+ Copyright (c) 1997-2019 by the authors.
87
187
 
88
188
  * Jeff Davis <ruby-pg@j-davis.com>
89
189
  * Guy Decoux (ts) <decoux@moulon.inra.fr>
@@ -95,7 +195,7 @@ Copyright (c) 1997-2013 by the authors.
95
195
  * Noboru Saitou <noborus@netlab.jp>
96
196
 
97
197
  You may redistribute this software under the same terms as Ruby itself; see
98
- http://www.ruby-lang.org/en/LICENSE.txt or the LICENSE file in the source
198
+ https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
99
199
  for details.
100
200
 
101
201
  Portions of the code are from the PostgreSQL project, and are distributed
@@ -111,4 +211,3 @@ to this library over the years.
111
211
 
112
212
  We are thankful to the people at the ruby-list and ruby-dev mailing lists.
113
213
  And to the people who developed PostgreSQL.
114
-
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rake
1
+ # -*- rake -*-
2
2
 
3
3
  require 'rbconfig'
4
4
  require 'pathname'
@@ -29,15 +29,20 @@ TMPDIR = BASEDIR + 'tmp'
29
29
  DLEXT = RbConfig::CONFIG['DLEXT']
30
30
  EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
31
 
32
+ GEMSPEC = 'pg.gemspec'
33
+
32
34
  TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
33
35
 
34
36
  CLOBBER.include( TEST_DIRECTORY.to_s )
35
37
  CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
38
+ CLEAN.include "lib/*/libpq.dll"
39
+ CLEAN.include "lib/pg_ext.*"
36
40
 
37
41
  # Set up Hoe plugins
38
42
  Hoe.plugin :mercurial
39
43
  Hoe.plugin :signing
40
44
  Hoe.plugin :deveiate
45
+ Hoe.plugin :bundler
41
46
 
42
47
  Hoe.plugins.delete :rubyforge
43
48
  Hoe.plugins.delete :compiler
@@ -52,24 +57,24 @@ $hoespec = Hoe.spec 'pg' do
52
57
  self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
53
58
  self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
54
59
  self.extra_rdoc_files.include( 'ext/*.c' )
60
+ self.license 'BSD-2-Clause'
55
61
 
56
62
  self.developer 'Michael Granger', 'ged@FaerieMUD.org'
63
+ self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
57
64
 
58
- self.dependency 'rake-compiler', '~> 0.8', :developer
59
- self.dependency 'hoe-deveiate', '~> 0.2', :developer
65
+ self.dependency 'rake-compiler', '~> 1.0', :developer
66
+ self.dependency 'rake-compiler-dock', ['~> 1.0'], :developer
67
+ self.dependency 'hoe-deveiate', '~> 0.9', :developer
68
+ self.dependency 'hoe-bundler', '~> 1.0', :developer
69
+ self.dependency 'rspec', '~> 3.5', :developer
70
+ self.dependency 'rdoc', '~> 5.1', :developer
60
71
 
61
- self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
62
72
  self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
63
73
 
64
- self.require_ruby_version( '>= 1.8.7' )
74
+ self.require_ruby_version( '>= 2.2' )
65
75
 
66
76
  self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
67
77
  self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
68
- self.spec_extras[:rdoc_options] = [
69
- '-f', 'fivefish',
70
- '-t', 'pg: The Ruby Interface to PostgreSQL',
71
- '-m', 'README.rdoc',
72
- ]
73
78
 
74
79
  self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
75
80
  end
@@ -77,7 +82,7 @@ end
77
82
  ENV['VERSION'] ||= $hoespec.spec.version.to_s
78
83
 
79
84
  # Tests should pass before checking in
80
- task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
85
+ task 'hg:precheckin' => [ :check_history, :check_manifest, :spec, :gemspec ]
81
86
 
82
87
  # Support for 'rvm specs'
83
88
  task :specs => :spec
@@ -93,7 +98,7 @@ task :test do
93
98
  # the installed gem dir. So we clear the task rake-compiler set up
94
99
  # to break the dependency between :spec and :compile when running under
95
100
  # rubygems-test, and then run :spec.
96
- Rake::Task[ EXT.to_s ].clear
101
+ Rake::Task[ EXT.to_s ].clear if File.exist?(EXT.to_s)
97
102
  Rake::Task[ :spec ].execute
98
103
  end
99
104
 
@@ -102,8 +107,6 @@ task :maint do
102
107
  ENV['MAINTAINER_MODE'] = 'yes'
103
108
  end
104
109
 
105
- ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
106
-
107
110
  # Rake-compiler task
108
111
  Rake::ExtensionTask.new do |ext|
109
112
  ext.name = 'pg_ext'
@@ -112,34 +115,61 @@ Rake::ExtensionTask.new do |ext|
112
115
  ext.lib_dir = 'lib'
113
116
  ext.source_pattern = "*.{c,h}"
114
117
  ext.cross_compile = true
115
- ext.cross_platform = CrossLibraries.map &:for_platform
116
-
117
- ext.cross_config_options += CrossLibraries.map do |lib|
118
- {
119
- lib.for_platform => [
120
- "--with-pg-include=#{lib.static_postgresql_libdir}",
121
- "--with-opt-include=#{lib.static_postgresql_incdir}",
122
- "--with-pg-lib=#{lib.static_postgresql_libdir}",
123
- "--with-opt-lib=#{lib.static_openssl_builddir}",
124
- ]
125
- }
126
- end
118
+ ext.cross_platform = CrossLibraries.map(&:for_platform)
119
+
120
+ ext.cross_config_options += CrossLibraries.map do |lib|
121
+ {
122
+ lib.for_platform => [
123
+ "--enable-windows-cross",
124
+ "--with-pg-include=#{lib.static_postgresql_incdir}",
125
+ "--with-pg-lib=#{lib.static_postgresql_libdir}",
126
+ # libpq-fe.h resides in src/interfaces/libpq/ before make install
127
+ "--with-opt-include=#{lib.static_postgresql_libdir}",
128
+ ]
129
+ }
130
+ end
131
+
132
+ # Add libpq.dll to windows binary gemspec
133
+ ext.cross_compiling do |spec|
134
+ spec.files << "lib/#{spec.platform}/libpq.dll"
135
+ end
136
+ end
137
+
138
+
139
+ # Use the fivefish formatter for docs generated from development checkout
140
+ if File.directory?( '.hg' )
141
+ require 'rdoc/task'
142
+
143
+ Rake::Task[ 'docs' ].clear
144
+ RDoc::Task.new( 'docs' ) do |rdoc|
145
+ rdoc.main = "README.rdoc"
146
+ rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", 'ext/**/*.{c,h}' )
147
+ rdoc.generator = :fivefish
148
+ rdoc.title = "PG: The Ruby PostgreSQL Driver"
149
+ rdoc.rdoc_dir = 'doc'
150
+ end
127
151
  end
128
152
 
129
153
 
130
154
  # Make the ChangeLog update if the repo has changed since it was last built
131
155
  file '.hg/branch' do
132
- abort "You need the Mercurial repo to make packages"
156
+ warn "WARNING: You need the Mercurial repo to update the ChangeLog"
133
157
  end
134
- file 'ChangeLog' => '.hg/branch' do |task|
135
- $stderr.puts "Updating the changelog..."
136
- begin
137
- content = make_changelog()
138
- rescue NameError
139
- abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
140
- end
141
- File.open( task.name, 'w', 0644 ) do |fh|
142
- fh.print( content )
158
+ Rake::Task["ChangeLog"].clear
159
+ file 'ChangeLog' do |task|
160
+ if File.exist?('.hg/branch')
161
+ $stderr.puts "Updating the changelog..."
162
+ begin
163
+ include Hoe::MercurialHelpers
164
+ content = make_changelog()
165
+ rescue NameError
166
+ abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
167
+ end
168
+ File.open( task.name, 'w', 0644 ) do |fh|
169
+ fh.print( content )
170
+ end
171
+ else
172
+ touch 'ChangeLog'
143
173
  end
144
174
  end
145
175
 
@@ -154,3 +184,34 @@ task :cleanup_testing_dbs do
154
184
  Rake::Task[:clean].invoke
155
185
  end
156
186
 
187
+ desc "Update list of server error codes"
188
+ task :update_error_codes do
189
+ URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_12_0"
190
+
191
+ ERRORCODES_TXT = "ext/errorcodes.txt"
192
+ sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
193
+
194
+ ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
195
+ end
196
+
197
+ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
198
+ # trigger compilation of changed errorcodes.def
199
+ touch 'ext/pg_errors.c'
200
+ end
201
+
202
+ task :gemspec => GEMSPEC
203
+ file GEMSPEC => __FILE__
204
+ task GEMSPEC do |task|
205
+ spec = $hoespec.spec
206
+ spec.files.delete( '.gemtest' )
207
+ spec.signing_key = nil
208
+ spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
209
+ spec.cert_chain = [ 'certs/ged.pem' ]
210
+ File.open( task.name, 'w' ) do |fh|
211
+ fh.write( spec.to_ruby )
212
+ end
213
+ end
214
+
215
+ CLOBBER.include( '*.gemspec' )
216
+ task :default => :gemspec
217
+