pg 0.12.2-x86-mingw32 → 0.13.0-x86-mingw32
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.
- data/.hoerc +2 -0
- data/.tm_properties +12 -0
- data/ChangeLog +166 -59
- data/Contributors.rdoc +7 -0
- data/History.rdoc +29 -0
- data/LICENSE +12 -14
- data/Manifest.txt +15 -14
- data/{BSD → POSTGRES} +0 -0
- data/{README.OS_X.rdoc → README-OS_X.rdoc} +0 -0
- data/{README.windows.rdoc → README-Windows.rdoc} +0 -0
- data/README.ja.rdoc +1 -1
- data/README.rdoc +39 -27
- data/Rakefile +1 -5
- data/Rakefile.cross +2 -2
- data/ext/extconf.rb +8 -2
- data/ext/pg.c +232 -4297
- data/ext/pg.h +88 -23
- data/ext/pg_connection.c +3288 -0
- data/ext/pg_result.c +905 -0
- data/lib/1.8/pg_ext.so +0 -0
- data/lib/1.9/pg_ext.so +0 -0
- data/lib/pg.rb +26 -43
- data/lib/pg/connection.rb +58 -0
- data/lib/pg/constants.rb +11 -0
- data/lib/pg/exceptions.rb +11 -0
- data/lib/pg/result.rb +11 -0
- data/misc/openssl-pg-segfault.rb +1 -1
- data/sample/async_api.rb +16 -21
- data/sample/async_copyto.rb +1 -1
- data/sample/async_mixed.rb +56 -0
- data/sample/copyfrom.rb +1 -1
- data/sample/copyto.rb +1 -1
- data/sample/cursor.rb +1 -1
- data/sample/losample.rb +6 -6
- data/sample/notify_wait.rb +51 -22
- data/sample/test_binary_values.rb +4 -6
- data/spec/lib/helpers.rb +14 -10
- data/spec/{pgconn_spec.rb → pg/connection_spec.rb} +228 -60
- data/spec/{pgresult_spec.rb → pg/result_spec.rb} +31 -35
- data/spec/pg_spec.rb +22 -0
- metadata +52 -41
- data/GPL +0 -340
- data/ext/compat.c +0 -541
- data/ext/compat.h +0 -184
- data/sample/psql.rb +0 -1181
- data/sample/psqlHelp.rb +0 -158
- data/sample/test1.rb +0 -60
- data/sample/test2.rb +0 -44
- data/sample/test4.rb +0 -71
- data/spec/m17n_spec.rb +0 -170
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$
|
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,170 +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
|
-
after( :each ) do
|
30
|
-
@conn.exec( 'ROLLBACK' ) if @conn
|
31
|
-
end
|
32
|
-
|
33
|
-
after( :all ) do
|
34
|
-
teardown_testing_db( @conn ) if @conn
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
# Examples
|
40
|
-
#
|
41
|
-
|
42
|
-
it "should return the same bytes in text format that are sent as inline text" do
|
43
|
-
binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
|
44
|
-
in_bytes = File.open(binary_file, 'r:ASCII-8BIT').read
|
45
|
-
|
46
|
-
out_bytes = nil
|
47
|
-
@conn.transaction do |conn|
|
48
|
-
conn.exec("SET standard_conforming_strings=on")
|
49
|
-
res = conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 0)
|
50
|
-
out_bytes = PGconn.unescape_bytea(res[0]['column1'])
|
51
|
-
end
|
52
|
-
out_bytes.should == in_bytes
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "rubyforge #22925: m17n support" do
|
56
|
-
it "should return results in the same encoding as the client (iso-8859-1)" do
|
57
|
-
out_string = nil
|
58
|
-
@conn.transaction do |conn|
|
59
|
-
conn.internal_encoding = 'iso8859-1'
|
60
|
-
res = conn.exec("VALUES ('fantasia')", [], 0)
|
61
|
-
out_string = res[0]['column1']
|
62
|
-
end
|
63
|
-
out_string.should == 'fantasia'
|
64
|
-
out_string.encoding.should == Encoding::ISO8859_1
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return results in the same encoding as the client (utf-8)" do
|
68
|
-
out_string = nil
|
69
|
-
@conn.transaction do |conn|
|
70
|
-
conn.internal_encoding = 'utf-8'
|
71
|
-
res = conn.exec("VALUES ('世界線航跡蔵')", [], 0)
|
72
|
-
out_string = res[0]['column1']
|
73
|
-
end
|
74
|
-
out_string.should == '世界線航跡蔵'
|
75
|
-
out_string.encoding.should == Encoding::UTF_8
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should return results in the same encoding as the client (EUC-JP)" do
|
79
|
-
out_string = nil
|
80
|
-
@conn.transaction do |conn|
|
81
|
-
conn.internal_encoding = 'EUC-JP'
|
82
|
-
stmt = "VALUES ('世界線航跡蔵')".encode('EUC-JP')
|
83
|
-
res = conn.exec(stmt, [], 0)
|
84
|
-
out_string = res[0]['column1']
|
85
|
-
end
|
86
|
-
out_string.should == '世界線航跡蔵'.encode('EUC-JP')
|
87
|
-
out_string.encoding.should == Encoding::EUC_JP
|
88
|
-
end
|
89
|
-
|
90
|
-
it "returns the results in the correct encoding even if the client_encoding has " +
|
91
|
-
"changed since the results were fetched" do
|
92
|
-
out_string = nil
|
93
|
-
@conn.transaction do |conn|
|
94
|
-
conn.internal_encoding = 'EUC-JP'
|
95
|
-
stmt = "VALUES ('世界線航跡蔵')".encode('EUC-JP')
|
96
|
-
res = conn.exec(stmt, [], 0)
|
97
|
-
conn.internal_encoding = 'utf-8'
|
98
|
-
out_string = res[0]['column1']
|
99
|
-
end
|
100
|
-
out_string.should == '世界線航跡蔵'.encode('EUC-JP')
|
101
|
-
out_string.encoding.should == Encoding::EUC_JP
|
102
|
-
end
|
103
|
-
|
104
|
-
it "the connection should return ASCII-8BIT when the server encoding is SQL_ASCII" do
|
105
|
-
@conn.external_encoding.should == Encoding::ASCII_8BIT
|
106
|
-
end
|
107
|
-
|
108
|
-
it "works around the unsupported JOHAB encoding by returning stuff in 'ASCII_8BIT'" do
|
109
|
-
pending "figuring out how to create a string in the JOHAB encoding" do
|
110
|
-
out_string = nil
|
111
|
-
@conn.transaction do |conn|
|
112
|
-
conn.exec( "set client_encoding = 'JOHAB';" )
|
113
|
-
stmt = "VALUES ('foo')".encode('JOHAB')
|
114
|
-
res = conn.exec( stmt, [], 0 )
|
115
|
-
out_string = res[0]['column1']
|
116
|
-
end
|
117
|
-
out_string.should == 'foo'.encode( Encoding::ASCII_8BIT )
|
118
|
-
out_string.encoding.should == Encoding::ASCII_8BIT
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it "uses the client encoding for escaped string" do
|
123
|
-
original = "string to escape".force_encoding( "euc-jp" )
|
124
|
-
@conn.set_client_encoding( "euc_jp" )
|
125
|
-
escaped = @conn.escape( original )
|
126
|
-
escaped.encoding.should == Encoding::EUC_JP
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
describe "Ruby 1.9.x default_internal encoding" do
|
132
|
-
|
133
|
-
it "honors the Encoding.default_internal if it's set and the synchronous interface is used" do
|
134
|
-
@conn.transaction do |txn_conn|
|
135
|
-
txn_conn.internal_encoding = Encoding::ISO8859_1
|
136
|
-
txn_conn.exec( "CREATE TABLE defaultinternaltest ( foo text )" )
|
137
|
-
txn_conn.exec( "INSERT INTO defaultinternaltest VALUES ('Grün und Weiß')" )
|
138
|
-
end
|
139
|
-
|
140
|
-
begin
|
141
|
-
prev_encoding = Encoding.default_internal
|
142
|
-
Encoding.default_internal = Encoding::UTF_8
|
143
|
-
|
144
|
-
conn = PGconn.connect( @conninfo )
|
145
|
-
conn.internal_encoding.should == Encoding::UTF_8
|
146
|
-
res = conn.exec( "SELECT foo FROM defaultinternaltest" )
|
147
|
-
res[0]['foo'].encoding.should == Encoding::UTF_8
|
148
|
-
ensure
|
149
|
-
conn.finish if conn
|
150
|
-
Encoding.default_internal = prev_encoding
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
it "encodes exception messages with the connection's encoding (#96)" do
|
158
|
-
@conn.set_client_encoding( 'utf-8' )
|
159
|
-
@conn.exec "CREATE TABLE foo (bar TEXT)"
|
160
|
-
|
161
|
-
begin
|
162
|
-
@conn.exec "INSERT INTO foo VALUES ('Côte d'Ivoire')"
|
163
|
-
rescue => err
|
164
|
-
err.message.encoding.should == Encoding::UTF_8
|
165
|
-
else
|
166
|
-
fail "No exception raised?!"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|