pg 0.12.0pre258 → 0.12.0.pre263

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  .gemtest
2
2
  BSD
3
+ ChangeLog
3
4
  Contributors.rdoc
4
5
  GPL
5
6
  History.rdoc
@@ -21,8 +22,10 @@ ext/vc/pg_19/pg_19.vcproj
21
22
  lib/pg.rb
22
23
  misc/openssl-pg-segfault.rb
23
24
  sample/async_api.rb
25
+ sample/async_copyto.rb
24
26
  sample/copyfrom.rb
25
27
  sample/copyto.rb
28
+ sample/cursor.rb
26
29
  sample/losample.rb
27
30
  sample/notify_wait.rb
28
31
  sample/psql.rb
data/Rakefile CHANGED
@@ -29,9 +29,9 @@ TMPDIR = BASEDIR + 'tmp'
29
29
  DLEXT = Config::CONFIG['DLEXT']
30
30
  EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
31
 
32
- TESTING_TMPDIRS = Rake::FileList[ "#{Dir.tmpdir}/tmp_test_*" ]
32
+ TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
33
33
 
34
- CLOBBER.include( *TESTING_TMPDIRS )
34
+ CLOBBER.include( TEST_DIRECTORY )
35
35
  CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
36
36
 
37
37
  # Set up Hoe plugins
@@ -53,6 +53,9 @@ have_func 'lo_create'
53
53
  have_func 'pg_encoding_to_char'
54
54
  have_func 'PQsetClientEncoding'
55
55
 
56
+ have_func 'rb_encdb_alias'
57
+ have_func 'rb_enc_alias'
58
+
56
59
  $defs.push( "-DHAVE_ST_NOTIFY_EXTRA" ) if
57
60
  have_struct_member 'struct pgNotify', 'extra', 'libpq-fe.h'
58
61
 
data/ext/pg.c CHANGED
@@ -9,7 +9,7 @@
9
9
  modified at: Wed Jan 20 16:41:51 1999
10
10
 
11
11
  $Author: ged $
12
- $Date: 2011/10/07 20:24:14 $
12
+ $Date: 2011/12/05 16:59:23 $
13
13
  ************************************************/
14
14
 
15
15
  #include "pg.h"
@@ -3172,12 +3172,12 @@ pgresult_res_status(VALUE self, VALUE status)
3172
3172
 
3173
3173
  /*
3174
3174
  * call-seq:
3175
- * res.result_error_message() -> String
3175
+ * res.error_message() -> String
3176
3176
  *
3177
3177
  * Returns the error message of the command as a string.
3178
3178
  */
3179
3179
  static VALUE
3180
- pgresult_result_error_message(VALUE self)
3180
+ pgresult_error_message(VALUE self)
3181
3181
  {
3182
3182
  VALUE ret = rb_tainted_str_new2(PQresultErrorMessage(get_pgresult(self)));
3183
3183
  ASSOCIATE_INDEX(ret, self);
@@ -3186,7 +3186,7 @@ pgresult_result_error_message(VALUE self)
3186
3186
 
3187
3187
  /*
3188
3188
  * call-seq:
3189
- * res.result_error_field(fieldcode) -> String
3189
+ * res.error_field(fieldcode) -> String
3190
3190
  *
3191
3191
  * Returns the individual field of an error.
3192
3192
  *
@@ -3203,14 +3203,46 @@ pgresult_result_error_message(VALUE self)
3203
3203
  * * +PG_DIAG_SOURCE_FILE+
3204
3204
  * * +PG_DIAG_SOURCE_LINE+
3205
3205
  * * +PG_DIAG_SOURCE_FUNCTION+
3206
+ *
3207
+ * An example:
3208
+ *
3209
+ * begin
3210
+ * conn.exec( "SELECT * FROM nonexistant_table" )
3211
+ * rescue PGError => err
3212
+ * p [
3213
+ * result.error_field( PGresult::PG_DIAG_SEVERITY ),
3214
+ * result.error_field( PGresult::PG_DIAG_SQLSTATE ),
3215
+ * result.error_field( PGresult::PG_DIAG_MESSAGE_PRIMARY ),
3216
+ * result.error_field( PGresult::PG_DIAG_MESSAGE_DETAIL ),
3217
+ * result.error_field( PGresult::PG_DIAG_MESSAGE_HINT ),
3218
+ * result.error_field( PGresult::PG_DIAG_STATEMENT_POSITION ),
3219
+ * result.error_field( PGresult::PG_DIAG_INTERNAL_POSITION ),
3220
+ * result.error_field( PGresult::PG_DIAG_INTERNAL_QUERY ),
3221
+ * result.error_field( PGresult::PG_DIAG_CONTEXT ),
3222
+ * result.error_field( PGresult::PG_DIAG_SOURCE_FILE ),
3223
+ * result.error_field( PGresult::PG_DIAG_SOURCE_LINE ),
3224
+ * result.error_field( PGresult::PG_DIAG_SOURCE_FUNCTION ),
3225
+ * ]
3226
+ * end
3227
+ *
3228
+ * Outputs:
3229
+ *
3230
+ * ["ERROR", "42P01", "relation \"nonexistant_table\" does not exist", nil, nil,
3231
+ * "15", nil, nil, nil, "path/to/parse_relation.c", "857", "parserOpenTable"]
3206
3232
  */
3207
3233
  static VALUE
3208
- pgresult_result_error_field(VALUE self, VALUE field)
3234
+ pgresult_error_field(VALUE self, VALUE field)
3209
3235
  {
3210
3236
  PGresult *result = get_pgresult( self );
3211
3237
  int fieldcode = NUM2INT( field );
3212
- VALUE ret = rb_tainted_str_new2( PQresultErrorField(result, fieldcode) );
3213
- ASSOCIATE_INDEX( ret, self );
3238
+ char * fieldstr = PQresultErrorField( result, fieldcode );
3239
+ VALUE ret = Qnil;
3240
+
3241
+ if ( fieldstr ) {
3242
+ ret = rb_tainted_str_new2( fieldstr );
3243
+ ASSOCIATE_INDEX( ret, self );
3244
+ }
3245
+
3214
3246
  return ret;
3215
3247
  }
3216
3248
 
@@ -3883,7 +3915,15 @@ static int enc_get_index(VALUE val)
3883
3915
  return i;
3884
3916
  }
3885
3917
 
3918
+ #ifdef HAVE_RB_ENCDB_ALIAS
3919
+ # define ENC_ALIAS(name, orig) rb_encdb_alias((name), (orig))
3920
+ #elif HAVE_RB_ENC_ALIAS
3921
+ # define ENC_ALIAS(name, orig) rb_enc_alias((name), (orig))
3922
+ #else
3886
3923
  extern int rb_enc_alias(const char *alias, const char *orig); /* declaration missing in Ruby 1.9.1 */
3924
+ # define ENC_ALIAS(name, orig) rb_enc_alias((name), (orig))
3925
+ #endif
3926
+
3887
3927
  static rb_encoding *
3888
3928
  find_or_create_johab(void)
3889
3929
  {
@@ -3897,7 +3937,7 @@ find_or_create_johab(void)
3897
3937
 
3898
3938
  enc_index = rb_define_dummy_encoding(aliases[0]);
3899
3939
  for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
3900
- rb_enc_alias(aliases[i], aliases[0]);
3940
+ ENC_ALIAS(aliases[i], aliases[0]);
3901
3941
  }
3902
3942
  return rb_enc_from_index(enc_index);
3903
3943
  }
@@ -4424,8 +4464,10 @@ Init_pg_ext()
4424
4464
  /****** PGresult INSTANCE METHODS: libpq ******/
4425
4465
  rb_define_method(rb_cPGresult, "result_status", pgresult_result_status, 0);
4426
4466
  rb_define_method(rb_cPGresult, "res_status", pgresult_res_status, 1);
4427
- rb_define_method(rb_cPGresult, "result_error_message", pgresult_result_error_message, 0);
4428
- rb_define_method(rb_cPGresult, "result_error_field", pgresult_result_error_field, 1);
4467
+ rb_define_method(rb_cPGresult, "error_message", pgresult_error_message, 0);
4468
+ rb_define_alias( rb_cPGresult, "result_error_message", "error_message");
4469
+ rb_define_method(rb_cPGresult, "error_field", pgresult_error_field, 1);
4470
+ rb_define_alias( rb_cPGresult, "result_error_field", "error_field" );
4429
4471
  rb_define_method(rb_cPGresult, "clear", pgresult_clear, 0);
4430
4472
  rb_define_method(rb_cPGresult, "ntuples", pgresult_ntuples, 0);
4431
4473
  rb_define_alias(rb_cPGresult, "num_tuples", "ntuples");
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pg'
4
+ require 'stringio'
5
+
6
+ # Using COPY asynchronously
7
+
8
+ $stderr.puts "Opening database connection ..."
9
+ conn = PGconn.connect( :dbname => 'test' )
10
+ conn.setnonblocking( true )
11
+
12
+ socket = IO.for_fd( conn.socket )
13
+
14
+ $stderr.puts "Running COPY command ..."
15
+ buf = ''
16
+ conn.transaction do
17
+ conn.send_query( "COPY logs TO STDOUT WITH csv" )
18
+ buf = nil
19
+
20
+ # #get_copy_data returns a row if there's a whole one to return, false
21
+ # if there isn't one but the COPY is still running, or nil when it's
22
+ # finished.
23
+ begin
24
+ $stderr.puts "COPY loop"
25
+ conn.consume_input
26
+ while conn.is_busy
27
+ $stderr.puts " ready loop"
28
+ select( [socket], nil, nil, 5.0 ) or
29
+ raise "Timeout (5s) waiting for query response."
30
+ conn.consume_input
31
+ end
32
+
33
+ buf = conn.get_copy_data
34
+ $stdout.puts( buf ) if buf
35
+ end until buf.nil?
36
+ end
37
+
38
+ conn.finish
39
+
@@ -8,10 +8,6 @@ require 'stringio'
8
8
  $stderr.puts "Opening database connection ..."
9
9
  conn = PGconn.connect( :dbname => 'test' )
10
10
 
11
- ### You can test the error case from the database side easily by
12
- ### changing one of the numbers at the end of one of the above rows to
13
- ### something non-numeric like "-".
14
-
15
11
  $stderr.puts "Running COPY command ..."
16
12
  buf = ''
17
13
  conn.transaction do
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pg'
4
+
5
+ # An example of how to use SQL cursors. This is mostly a straight port of
6
+ # the cursor portion of testlibpq.c from src/test/examples.
7
+
8
+ $stderr.puts "Opening database connection ..."
9
+ conn = PGconn.connect( :dbname => 'test' )
10
+
11
+ #
12
+ conn.transaction do
13
+ conn.exec( "DECLARE myportal CURSOR FOR select * from pg_database" )
14
+ res = conn.exec( "FETCH ALL IN myportal" )
15
+
16
+ puts res.fields.collect {|fname| "%-15s" % [fname] }.join( '' )
17
+ res.values.collect do |row|
18
+ puts row.collect {|col| "%-15s" % [col] }.join( '' )
19
+ end
20
+ end
21
+
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'pathname'
4
4
  require 'rspec'
5
+ require 'shellwords'
5
6
 
7
+ TEST_DIRECTORY = Pathname.getwd + "tmp_test_specs"
6
8
 
7
9
  RSpec.configure do |config|
8
10
  ruby_version_vec = RUBY_VERSION.split('.').map {|c| c.to_i }.pack( "N*" )
@@ -139,6 +141,7 @@ module PgTestingHelpers
139
141
  else
140
142
  $stdout.reopen( logfh )
141
143
  $stderr.reopen( $stdout )
144
+ $stderr.puts( ">>> " + cmd.shelljoin )
142
145
  exec( *cmd )
143
146
  $stderr.puts "After the exec()?!??!"
144
147
  exit!
@@ -184,8 +187,7 @@ module PgTestingHelpers
184
187
  stop_existing_postmasters()
185
188
 
186
189
  puts "Setting up test database for #{description} tests"
187
- @test_directory = Pathname.getwd + "tmp_test_specs"
188
- @test_pgdata = @test_directory + 'data'
190
+ @test_pgdata = TEST_DIRECTORY + 'data'
189
191
  @test_pgdata.mkpath
190
192
 
191
193
  @port = 54321
@@ -193,7 +195,7 @@ module PgTestingHelpers
193
195
  ENV['PGHOST'] = 'localhost'
194
196
  @conninfo = "host=localhost port=#{@port} dbname=test"
195
197
 
196
- @logfile = @test_directory + 'setup.log'
198
+ @logfile = TEST_DIRECTORY + 'setup.log'
197
199
  trace "Command output logged to #{@logfile}"
198
200
 
199
201
  begin
@@ -204,7 +206,7 @@ module PgTestingHelpers
204
206
  end
205
207
 
206
208
  trace "Starting postgres"
207
- log_and_run @logfile, 'pg_ctl', '-w', '-o', "-k #{@test_directory.to_s.inspect}",
209
+ log_and_run @logfile, 'pg_ctl', '-w', '-o', "-k #{TEST_DIRECTORY.to_s.dump}",
208
210
  '-D', @test_pgdata.to_s, 'start'
209
211
  sleep 2
210
212
 
@@ -7,7 +7,7 @@ BEGIN {
7
7
 
8
8
  basedir = Pathname( __FILE__ ).dirname.parent
9
9
  libdir = basedir + 'lib'
10
- archlib = libdir + Config::CONFIG['sitearch']
10
+ archlib = libdir + RbConfig::CONFIG['sitearch']
11
11
 
12
12
  $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
13
13
  $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
@@ -167,7 +167,7 @@ describe PGconn do
167
167
  # be careful to explicitly close files so that the
168
168
  # directory can be removed and we don't have to wait for
169
169
  # the GC to run.
170
- trace_file = @test_directory + "test_trace.out"
170
+ trace_file = TEST_DIRECTORY + "test_trace.out"
171
171
  trace_io = trace_file.open( 'w', 0600 )
172
172
  @conn.trace( trace_io )
173
173
  trace_io.close
@@ -38,7 +38,34 @@ describe PGresult do
38
38
 
39
39
  it "should insert nil AS NULL and return NULL as nil" do
40
40
  res = @conn.exec("SELECT $1::int AS n", [nil])
41
- res[0]['n'].should == nil
41
+ res[0]['n'].should be_nil()
42
+ end
43
+
44
+ it "encapsulates errors in a PGError object" do
45
+ exception = nil
46
+ begin
47
+ @conn.exec( "SELECT * FROM nonexistant_table" )
48
+ rescue PGError => err
49
+ exception = err
50
+ end
51
+
52
+ result = exception.result
53
+
54
+ result.should be_a( PGresult )
55
+ result.error_field( PGresult::PG_DIAG_SEVERITY ).should == 'ERROR'
56
+ result.error_field( PGresult::PG_DIAG_SQLSTATE ).should == '42P01'
57
+ result.error_field( PGresult::PG_DIAG_MESSAGE_PRIMARY ).
58
+ should == 'relation "nonexistant_table" does not exist'
59
+ result.error_field( PGresult::PG_DIAG_MESSAGE_DETAIL ).should be_nil()
60
+ result.error_field( PGresult::PG_DIAG_MESSAGE_HINT ).should be_nil()
61
+ result.error_field( PGresult::PG_DIAG_STATEMENT_POSITION ).should == '15'
62
+ result.error_field( PGresult::PG_DIAG_INTERNAL_POSITION ).should be_nil()
63
+ result.error_field( PGresult::PG_DIAG_INTERNAL_QUERY ).should be_nil()
64
+ result.error_field( PGresult::PG_DIAG_CONTEXT ).should be_nil()
65
+ result.error_field( PGresult::PG_DIAG_SOURCE_FILE ).should =~ /parse_relation\.c$/
66
+ result.error_field( PGresult::PG_DIAG_SOURCE_LINE ).should == '857'
67
+ result.error_field( PGresult::PG_DIAG_SOURCE_FUNCTION ).should == 'parserOpenTable'
68
+
42
69
  end
43
70
 
44
71
  it "should detect division by zero as SQLSTATE 22012" do
@@ -46,8 +73,7 @@ describe PGresult do
46
73
  begin
47
74
  res = @conn.exec("SELECT 1/0")
48
75
  rescue PGError => e
49
- sqlstate = e.result.result_error_field(
50
- PGresult::PG_DIAG_SQLSTATE).to_i
76
+ sqlstate = e.result.result_error_field( PGresult::PG_DIAG_SQLSTATE ).to_i
51
77
  end
52
78
  sqlstate.should == 22012
53
79
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923832429
4
+ hash: 1923832423
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 12
9
9
  - 0
10
10
  - pre
11
- - 258
12
- version: 0.12.0pre258
11
+ - 263
12
+ version: 0.12.0.pre263
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jeff Davis
@@ -38,7 +38,7 @@ cert_chain:
38
38
  cmlhXe46pZNJgWKbxZah85jIjx95hR8vOI+NAM5iH9kOqK13DrxacTKPhqj5PjwF
39
39
  -----END CERTIFICATE-----
40
40
 
41
- date: 2011-10-07 00:00:00 Z
41
+ date: 2011-12-05 00:00:00 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake-compiler
@@ -144,6 +144,7 @@ extra_rdoc_files:
144
144
  files:
145
145
  - .gemtest
146
146
  - BSD
147
+ - ChangeLog
147
148
  - Contributors.rdoc
148
149
  - GPL
149
150
  - History.rdoc
@@ -165,8 +166,10 @@ files:
165
166
  - lib/pg.rb
166
167
  - misc/openssl-pg-segfault.rb
167
168
  - sample/async_api.rb
169
+ - sample/async_copyto.rb
168
170
  - sample/copyfrom.rb
169
171
  - sample/copyto.rb
172
+ - sample/cursor.rb
170
173
  - sample/losample.rb
171
174
  - sample/notify_wait.rb
172
175
  - sample/psql.rb
@@ -215,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
218
  requirements: []
216
219
 
217
220
  rubyforge_project: pg
218
- rubygems_version: 1.8.10
221
+ rubygems_version: 1.8.11
219
222
  signing_key:
220
223
  specification_version: 3
221
224
  summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
@@ -0,0 +1,2 @@
1
+ ����5���%�Wtx��1v̒<�(w��R̠�����ҡ�I��.L�|��ϑ7z <Y�s�ۍK�6��y�����}uAV;4{w%�៝M��� �G���N/��l"�B�lEJ���x2�����$���1�%`���xP��c~$NW��ٓ��{�e
2
+ ͐]�^�{W��Ϙ�]�fcsAX�!���6��[0�ʣ���|8�V�!��F���|d�OM�����.��7��g3����i�9F�7^gu�V�R