pg 0.12.0 → 0.16.0

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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/BSDL +22 -0
  4. data/ChangeLog +1504 -11
  5. data/Contributors.rdoc +7 -0
  6. data/History.rdoc +181 -3
  7. data/LICENSE +12 -14
  8. data/Manifest.txt +29 -15
  9. data/{BSD → POSTGRES} +0 -0
  10. data/{README.OS_X.rdoc → README-OS_X.rdoc} +0 -0
  11. data/{README.windows.rdoc → README-Windows.rdoc} +0 -0
  12. data/README.ja.rdoc +10 -3
  13. data/README.rdoc +54 -28
  14. data/Rakefile +53 -26
  15. data/Rakefile.cross +235 -196
  16. data/ext/errorcodes.def +931 -0
  17. data/ext/errorcodes.rb +45 -0
  18. data/ext/errorcodes.txt +463 -0
  19. data/ext/extconf.rb +37 -7
  20. data/ext/gvl_wrappers.c +19 -0
  21. data/ext/gvl_wrappers.h +211 -0
  22. data/ext/pg.c +317 -4277
  23. data/ext/pg.h +124 -21
  24. data/ext/pg_connection.c +3642 -0
  25. data/ext/pg_errors.c +89 -0
  26. data/ext/pg_result.c +920 -0
  27. data/lib/pg/connection.rb +86 -0
  28. data/lib/pg/constants.rb +11 -0
  29. data/lib/pg/exceptions.rb +11 -0
  30. data/lib/pg/result.rb +16 -0
  31. data/lib/pg.rb +26 -43
  32. data/sample/array_insert.rb +20 -0
  33. data/sample/async_api.rb +21 -24
  34. data/sample/async_copyto.rb +2 -2
  35. data/sample/async_mixed.rb +56 -0
  36. data/sample/check_conn.rb +21 -0
  37. data/sample/copyfrom.rb +1 -1
  38. data/sample/copyto.rb +1 -1
  39. data/sample/cursor.rb +2 -2
  40. data/sample/disk_usage_report.rb +186 -0
  41. data/sample/issue-119.rb +94 -0
  42. data/sample/losample.rb +6 -6
  43. data/sample/minimal-testcase.rb +17 -0
  44. data/sample/notify_wait.rb +51 -22
  45. data/sample/pg_statistics.rb +294 -0
  46. data/sample/replication_monitor.rb +231 -0
  47. data/sample/test_binary_values.rb +4 -6
  48. data/sample/wal_shipper.rb +434 -0
  49. data/sample/warehouse_partitions.rb +320 -0
  50. data/spec/lib/helpers.rb +70 -23
  51. data/spec/pg/connection_spec.rb +1128 -0
  52. data/spec/{pgresult_spec.rb → pg/result_spec.rb} +142 -47
  53. data/spec/pg_spec.rb +44 -0
  54. data.tar.gz.sig +0 -0
  55. metadata +145 -100
  56. metadata.gz.sig +0 -0
  57. data/GPL +0 -340
  58. data/ext/compat.c +0 -541
  59. data/ext/compat.h +0 -184
  60. data/misc/openssl-pg-segfault.rb +0 -31
  61. data/sample/psql.rb +0 -1181
  62. data/sample/psqlHelp.rb +0 -158
  63. data/sample/test1.rb +0 -60
  64. data/sample/test2.rb +0 -44
  65. data/sample/test4.rb +0 -71
  66. data/spec/m17n_spec.rb +0 -151
  67. data/spec/pgconn_spec.rb +0 -643
data/sample/psqlHelp.rb DELETED
@@ -1,158 +0,0 @@
1
- #
2
- # Help for query language syntax
3
- #
4
- # Original source code is written by C.
5
- # Copyright (c) 1996, Regents of the University of California
6
- #
7
- # ruby version is written by ematsu
8
- # Copyright (c) 1997 Eiji-usagi-MATSUmoto <ematsu@pfu.co.jp>
9
- #
10
- # $Id: psqlHelp.rb,v a3434e641f6a 2009/12/10 18:22:46 mahlon $
11
-
12
-
13
- QL_HELP = [
14
- [ "abort",
15
- "abort the current transaction",
16
- "abort [transaction];"],
17
- [ "abort transaction",
18
- "abort the current transaction",
19
- "abort [transaction];"],
20
- [ "alter table",
21
- "add/rename attributes, rename tables",
22
- "\talter table <class_name> [*] add column <attr> <type>;\n\talter table <class_name> [*] rename [column] <attr1> to <attr2>;\n\talter table <class_name1> rename to <class_name2>"],
23
- [ "begin",
24
- "begin a new transaction",
25
- "begin [transaction|work];"],
26
- [ "begin transaction",
27
- "begin a new transaction",
28
- "begin [transaction|work];"],
29
- [ "begin work",
30
- "begin a new transaction",
31
- "begin [transaction|work];"],
32
- [ "cluster",
33
- "create a clustered index (from an existing index)",
34
- "cluster <index_name> on <relation_name>"],
35
- [ "close",
36
- "close an existing cursor (cursor)",
37
- "close <cursorname>;"],
38
- [ "commit",
39
- "commit a transaction",
40
- "commit [work]"],
41
- [ "commit work",
42
- "commit a transaction",
43
- "commit [work]"],
44
- [ "copy",
45
- "copy data to and from a table",
46
- "copy [binary] <class_name> [with oids]\n\t{to|from} {<filename>|stdin|stdout} [using delimiters <delim>];"],
47
- [ "create",
48
- "Please more be specific:",
49
- "\tcreate aggregate\n\tcreate database\n\tcreate function\n\tcreate index\n\tcreate operator\n\tcreate rule\n\tcreate table\n\tcreate type\n\tcreate view"],
50
- [ "create aggregate",
51
- "define an aggregate function",
52
- "create aggregate <agg_name> [as] (basetype = <data_type>, \n\t[sfunc1 = <sfunc_1>, stype1 = <sfunc1_return_type>]\n\t[sfunc2 = <sfunc_2>, stype2 = <sfunc2_return_type>]\n\t[,finalfunc = <final-function>]\n\t[,initcond1 = <initial-cond1>][,initcond2 = <initial-cond2>]);"],
53
- [ "create database",
54
- "create a database",
55
- "create database <dbname>"],
56
- [ "create function",
57
- "create a user-defined function",
58
- "create function <function_name> ([<type1>,...<typeN>]) returns <return_type>\n\tas '<object_filename>'|'<sql-queries>'\n\tlanguage 'c'|'sql'|'internal';"],
59
- [ "create index",
60
- "construct an index",
61
- "create [unique] index <indexname> on <class_name> [using <access_method>] (<attr1>|<funcname>(<attr1>,...) [<type_class1>]);"],
62
- [ "create operator",
63
- "create a user-defined operator",
64
- "create operator <operator_name> (\n\t[leftarg = <type1>][,rightarg = <type2>]\n\t,procedure = <func_name>,\n\t[,commutator = <com_op>][,negator = <neg_op>]\n\t[,restrict = <res_proc>][,hashes]\n\t[,join = <join_proc>][,sort = <sort_op1>...<sort_opN>]);"],
65
- [ "create rule",
66
- "define a new rule",
67
- "create rule <rule_name> as on\n\t[select|update|delete|insert]\n\tto <object> [where <qual>]\n\tdo [instead] [<action>|nothing| [<actions>]];"],
68
- [ "create table",
69
- "create a new table",
70
- "create table <class_name> ( <attr1> <type1>,... <attrN> <typeN>)\n\t[inherits (<class_name1>,...<class_nameN>\n\tarchive=<archive_mode>\n\tstore=<smgr_name>\n\tarch_store=<smgr_name>];"],
71
- [ "create type",
72
- "create a new user-defined base data type",
73
- "create type <typename> (\n\tinternallength = (<number> | variable),\n\t[externallength = (<number>|variable),]\n\tinput=<input_function>, output = <output_function>\n\t[,element = <typename>][,delimiter=<character>][,default=\'<string>\']\n\t[,send = <send_function>][,receive = <receive_function>][,passedbyvalue]);"],
74
- [ "create view",
75
- "create a view",
76
- "create view <view_name> as select <expr1>[as <attr1>][,... <exprN>[as <attrN>]] [from <from_list>] [where <qual>];"],
77
- [ "declare",
78
- "set up a cursor",
79
- "declare <cursorname> [binary] cursor for\n\tselect [distinct]\n\t<expr1> [as <attr1>],...<exprN> [as <attrN>]\n\t[from <from_list>] [where <qual>]\n\t[order by <attr1> [using <op1>],... <attrN> [using <opN>]];"],
80
- [ "delete",
81
- "delete tuples",
82
- "delete from <class_name> [where <qual>];"],
83
- [ "drop",
84
- "Please more be specific:",
85
- "\tdrop aggregate\n\tdrop database\n\tdrop function\n\tdrop index\n\tdrop operator\n\tdrop rule\n\tdrop table\n\tdrop type\n\tdrop view"],
86
- [ "drop aggregate",
87
- "remove an aggregate function",
88
- "drop aggregate <agg_name>;"],
89
- [ "drop database",
90
- "remove a database",
91
- "drop database <dbname>"],
92
- [ "drop function",
93
- "remove a user-defined function",
94
- "drop function <funcname> ([<type1>,....<typeN>]);"],
95
- [ "drop index",
96
- "remove an existing index",
97
- "drop index <indexname>;"],
98
- [ "drop operator",
99
- "remove a user-defined operator",
100
- "drop operator <operator_name> ([<ltype>|none],[<rtype>|none]);"],
101
- [ "drop rule",
102
- "remove a rule",
103
- "drop rule <rulename>;"],
104
- [ "drop table",
105
- "remove a table",
106
- "drop table <class_name>[,...<class_nameN];"],
107
- [ "drop type",
108
- "remove a user-defined base type",
109
- "drop type <typename>;"],
110
- [ "drop view",
111
- "remove a view",
112
- "drop view <view_name>"],
113
- [ "end",
114
- "end the current transaction",
115
- "end [transaction];"],
116
- [ "end transaction",
117
- "end the current transaction",
118
- "end [transaction];"],
119
- [ "explain",
120
- "explain the query execution plan",
121
- "explain [with {cost|plan|full}] <query>"],
122
- [ "fetch",
123
- "retrieve tuples from a cursor",
124
- "fetch [forward|backward] [<number>|all] [in <cursorname>];"],
125
- [ "grant",
126
- "grant access control to a user or group",
127
- "grant <privilege[,privilege,...]> on <rel1>[,...<reln>] to \n[public | group <group> | <username>]\n\t privilege is {ALL | SELECT | INSERT | UPDATE | DELETE | RULE}"],
128
- [ "insert",
129
- "insert tuples",
130
- "insert into <class_name> [(<attr1>...<attrN>)]\n\t[values (<expr1>...<exprN>); |\n\tselect <expr1>,...<exprN> [from <from_clause>] [where <qual>];"],
131
- [ "listen",
132
- "listen for notification on a relation",
133
- "listen <class_name>"],
134
- [ "load",
135
- "dynamically load a module",
136
- "load <filename>;"],
137
- [ "notify",
138
- "signal all frontends and backends listening on a relation",
139
- "notify <class_name>"],
140
- [ "purge",
141
- "purge historical data",
142
- "purge <class_name> [before <abstime>] [after <reltime>];"],
143
- [ "revoke",
144
- "revoke access control from a user or group",
145
- "revoke <privilege[,privilege,...]> on <rel1>[,...<reln>] from \n[public | group <group> | <username>]\n\t privilege is {ALL | SELECT | INSERT | UPDATE | DELETE | RULE}"],
146
- [ "rollback",
147
- "abort a transaction",
148
- "rollback [transaction|work]"],
149
- [ "select",
150
- "retrieve tuples",
151
- "select [distinct on <attr>] <expr1> [as <attr1>], ... <exprN> [as <attrN>]\n\t[into table <class_name>] [from <from_list>]\n\t[where <qual>]\n\t[order by <attr1>\n\t\t[using <op1>],..<attrN> [[using <opN>] | ASC | DESC]];" ],
152
- [ "update",
153
- "update tuples",
154
- "update <class_name> set <attr1>=<expr1>,...<attrN>=<exprN> [from <from_clause>] [where <qual>];"],
155
- [ "vacuum",
156
- "vacuum the database, i.e. cleans out deleted records, updates statistics",
157
- "vacuum [table];"]
158
- ]
data/sample/test1.rb DELETED
@@ -1,60 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # original file src/test/examples/testlibpq.c
4
- #
5
- require 'pg'
6
-
7
- def main
8
- pghost = nil
9
- pgport = nil
10
- pgoptions = nil
11
- pgtty = nil
12
- dbname = "template1"
13
- begin
14
- conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname)
15
- if $DEBUG
16
- fd = open("/tmp/trace.out","w")
17
- conn.trace(fd)
18
- end
19
- res = conn.exec("BEGIN")
20
- res.clear
21
- res = conn.exec("DECLARE myportal CURSOR FOR select * from pg_database")
22
- res.clear
23
-
24
- res = conn.exec("FETCH ALL in myportal")
25
- if (res.result_status != PGresult::PGRES_TUPLES_OK)
26
- raise PGerror,"FETCH ALL command didn't return tuples properly\n"
27
- end
28
-
29
- for fld in res.fields
30
- printf("%-15s",fld)
31
- end
32
- printf("\n\n")
33
-
34
- res.values.each do |tupl|
35
- tupl.each do |fld|
36
- printf("%-15s",fld)
37
- end
38
- printf("\n")
39
- end
40
- res = conn.exec("CLOSE myportal")
41
- res = conn.exec("END")
42
- res.clear
43
- conn.close
44
-
45
- if $DEBUG
46
- fl.close
47
- end
48
- rescue PGError
49
- if (conn.status == PGconn::CONNECTION_BAD)
50
- printf(STDERR, "We have lost the connection to the backend, so ")
51
- printf(STDERR, "further processing is impossible. ")
52
- printf(STDERR, "Terminating.\n")
53
- else
54
- printf(STDERR, conn.error)
55
- end
56
- exit(1)
57
- end
58
- end
59
-
60
- main
data/sample/test2.rb DELETED
@@ -1,44 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # original file src/test/examples/testlibpq2.c
4
- # Test of the asynchronous notification interface
5
- # CREATE TABLE TBL1 (i int4);
6
- # CREATE TABLE TBL2 (i int4);
7
- # CREATE RULE r1 AS ON INSERT TO TBL1 DO (INSERT INTO TBL2 values (new.i); \
8
- # NOTIFY TBL2);
9
- # Then start up this program
10
- # After the program has begun, do
11
- # INSERT INTO TBL1 values (10);
12
-
13
-
14
- require 'pg'
15
-
16
- def main
17
- pghost = nil
18
- pgport = nil
19
- pgoptions = nil
20
- pgtty = nil
21
- dbname = ENV['USER']
22
- begin
23
- conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname)
24
- rescue PGError
25
- printf(STDERR, "Connection to database '%s' failed.\n",dbname)
26
- exit(2)
27
- end
28
- begin
29
- res = conn.exec("LISTEN TBL2")
30
- rescue PGError
31
- printf(STDERR, "LISTEN command failed\n")
32
- exit(2)
33
- end
34
- res.clear
35
- while 1
36
- notify = conn.get_notify
37
- if (notify)
38
- printf(STDERR,"ASYNC NOTIFY '%s' from backend pid '%d' received\n",notify[0],notify[1])
39
- break
40
- end
41
- end
42
- end
43
-
44
- main
data/sample/test4.rb DELETED
@@ -1,71 +0,0 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # original file src/test/examples/testlibpq4.c
4
- # this test programs shows to use LIBPQ to make multiple backend
5
- #
6
- require 'pg'
7
-
8
- def main
9
- if (ARGV.size != 4)
10
- printf(STDERR,"usage: %s tableName dbName1 dbName2\n", ARGV[0])
11
- printf(STDERR," compares two tables in two databases\n")
12
- exit(1)
13
- end
14
- tblname = ARGV[1]
15
- dbname1 = ARGV[2]
16
- dbname2 = ARGV[3]
17
- pghost = nil
18
- pgport = nil
19
- pgoptions = nil
20
- pgtty = nil
21
-
22
- begin
23
- conn1 = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname1)
24
- conn2 = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname2)
25
- rescue PGError
26
- printf(STDERR,"connection to database.\n")
27
- exit(1)
28
- end
29
- begin
30
- res1 = conn1.exec("BEGIN")
31
- res1.clear
32
- res1 = conn1.exec("DECLARE myportal CURSOR FOR select * from pg_database")
33
- res1.clear
34
-
35
- res1 = conn1.exec("FETCH ALL in myportal")
36
- if (res1.status != PGresult::TUPLES_OK)
37
- raise PGerror,"FETCH ALL command didn't return tuples properly\n"
38
- end
39
-
40
- for fld in res1.fields
41
- printf("%-15s",fld)
42
- end
43
- printf("\n\n")
44
-
45
- res1.result.each do |tupl|
46
- tupl.each do |fld|
47
- printf("%-15s",fld)
48
- end
49
- printf("\n")
50
- end
51
- res1 = conn1.exec("CLOSE myportal")
52
- res1 = conn1.exec("END")
53
- res1.clear
54
- conn1.close
55
-
56
- rescue PGError
57
- if (conn1.status == PGconn::CONNECTION_BAD)
58
- printf(STDERR, "We have lost the connection to the backend, so ")
59
- printf(STDERR, "further processing is impossible. ")
60
- printf(STDERR, "Terminating.\n")
61
- else
62
- printf(STDERR, conn1.error)
63
- end
64
- exit(1)
65
- end
66
- end
67
-
68
- main
69
-
70
-
71
-
data/spec/m17n_spec.rb DELETED
@@ -1,151 +0,0 @@
1
- #!/usr/bin/env rspec
2
- # encoding: utf-8
3
-
4
- BEGIN {
5
- require 'pathname'
6
- require 'rbconfig'
7
-
8
- basedir = Pathname( __FILE__ ).dirname.parent
9
- libdir = basedir + 'lib'
10
- archlib = libdir + RbConfig::CONFIG['sitearch']
11
-
12
- $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
13
- $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
14
- $LOAD_PATH.unshift( archlib.to_s ) unless $LOAD_PATH.include?( archlib.to_s )
15
- }
16
-
17
- require 'rspec'
18
- require 'spec/lib/helpers'
19
- require 'pg'
20
-
21
- describe "multinationalization support", :ruby_19 => true do
22
- include PgTestingHelpers
23
-
24
- before( :all ) do
25
- @conn = setup_testing_db( "m17n" )
26
- @conn.exec( 'BEGIN' )
27
- end
28
-
29
-
30
- it "should return the same bytes in text format that are sent as inline text" do
31
- binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
32
- in_bytes = File.open(binary_file, 'r:ASCII-8BIT').read
33
-
34
- out_bytes = nil
35
- @conn.transaction do |conn|
36
- conn.exec("SET standard_conforming_strings=on")
37
- res = conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 0)
38
- out_bytes = PGconn.unescape_bytea(res[0]['column1'])
39
- end
40
- out_bytes.should == in_bytes
41
- end
42
-
43
- describe "rubyforge #22925: m17n support" do
44
- it "should return results in the same encoding as the client (iso-8859-1)" do
45
- out_string = nil
46
- @conn.transaction do |conn|
47
- conn.internal_encoding = 'iso8859-1'
48
- res = conn.exec("VALUES ('fantasia')", [], 0)
49
- out_string = res[0]['column1']
50
- end
51
- out_string.should == 'fantasia'
52
- out_string.encoding.should == Encoding::ISO8859_1
53
- end
54
-
55
- it "should return results in the same encoding as the client (utf-8)" do
56
- out_string = nil
57
- @conn.transaction do |conn|
58
- conn.internal_encoding = 'utf-8'
59
- res = conn.exec("VALUES ('世界線航跡蔵')", [], 0)
60
- out_string = res[0]['column1']
61
- end
62
- out_string.should == '世界線航跡蔵'
63
- out_string.encoding.should == Encoding::UTF_8
64
- end
65
-
66
- it "should return results in the same encoding as the client (EUC-JP)" do
67
- out_string = nil
68
- @conn.transaction do |conn|
69
- conn.internal_encoding = 'EUC-JP'
70
- stmt = "VALUES ('世界線航跡蔵')".encode('EUC-JP')
71
- res = conn.exec(stmt, [], 0)
72
- out_string = res[0]['column1']
73
- end
74
- out_string.should == '世界線航跡蔵'.encode('EUC-JP')
75
- out_string.encoding.should == Encoding::EUC_JP
76
- end
77
-
78
- it "returns the results in the correct encoding even if the client_encoding has " +
79
- "changed since the results were fetched" do
80
- out_string = nil
81
- @conn.transaction do |conn|
82
- conn.internal_encoding = 'EUC-JP'
83
- stmt = "VALUES ('世界線航跡蔵')".encode('EUC-JP')
84
- res = conn.exec(stmt, [], 0)
85
- conn.internal_encoding = 'utf-8'
86
- out_string = res[0]['column1']
87
- end
88
- out_string.should == '世界線航跡蔵'.encode('EUC-JP')
89
- out_string.encoding.should == Encoding::EUC_JP
90
- end
91
-
92
- it "the connection should return ASCII-8BIT when the server encoding is SQL_ASCII" do
93
- @conn.external_encoding.should == Encoding::ASCII_8BIT
94
- end
95
-
96
- it "works around the unsupported JOHAB encoding by returning stuff in 'ASCII_8BIT'" do
97
- pending "figuring out how to create a string in the JOHAB encoding" do
98
- out_string = nil
99
- @conn.transaction do |conn|
100
- conn.exec( "set client_encoding = 'JOHAB';" )
101
- stmt = "VALUES ('foo')".encode('JOHAB')
102
- res = conn.exec( stmt, [], 0 )
103
- out_string = res[0]['column1']
104
- end
105
- out_string.should == 'foo'.encode( Encoding::ASCII_8BIT )
106
- out_string.encoding.should == Encoding::ASCII_8BIT
107
- end
108
- end
109
-
110
- it "uses the client encoding for escaped string" do
111
- original = "string to escape".force_encoding( "euc-jp" )
112
- @conn.set_client_encoding( "euc_jp" )
113
- escaped = @conn.escape( original )
114
- escaped.encoding.should == Encoding::EUC_JP
115
- end
116
- end
117
-
118
- describe "Ruby 1.9.x default_internal encoding" do
119
-
120
- it "honors the Encoding.default_internal if it's set and the synchronous interface is used" do
121
- @conn.transaction do |txn_conn|
122
- txn_conn.internal_encoding = Encoding::ISO8859_1
123
- txn_conn.exec( "CREATE TABLE defaultinternaltest ( foo text )" )
124
- txn_conn.exec( "INSERT INTO defaultinternaltest VALUES ('Grün und Weiß')" )
125
- end
126
-
127
- begin
128
- prev_encoding = Encoding.default_internal
129
- Encoding.default_internal = Encoding::UTF_8
130
-
131
- conn = PGconn.connect( @conninfo )
132
- conn.internal_encoding.should == Encoding::UTF_8
133
- res = conn.exec( "SELECT foo FROM defaultinternaltest" )
134
- res[0]['foo'].encoding.should == Encoding::UTF_8
135
- ensure
136
- conn.finish if conn
137
- Encoding.default_internal = prev_encoding
138
- end
139
- end
140
-
141
- end
142
-
143
-
144
- after( :each ) do
145
- @conn.exec( 'ROLLBACK' ) if @conn
146
- end
147
-
148
- after( :all ) do
149
- teardown_testing_db( @conn ) if @conn
150
- end
151
- end