pg 1.6.0.rc2-aarch64-linux
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +986 -0
- data/Contributors.rdoc +46 -0
- data/Gemfile +23 -0
- data/LICENSE +56 -0
- data/POSTGRES +23 -0
- data/README-OS_X.rdoc +68 -0
- data/README-Windows.rdoc +56 -0
- data/README.ja.md +300 -0
- data/README.md +287 -0
- data/Rakefile +185 -0
- data/certs/ged.pem +24 -0
- data/certs/kanis@comcard.de.pem +20 -0
- data/certs/larskanis-2022.pem +26 -0
- data/certs/larskanis-2023.pem +24 -0
- data/certs/larskanis-2024.pem +24 -0
- data/ext/errorcodes.def +1043 -0
- data/ext/errorcodes.rb +45 -0
- data/ext/errorcodes.txt +494 -0
- data/ext/extconf.rb +320 -0
- data/ext/gvl_wrappers.c +32 -0
- data/ext/gvl_wrappers.h +297 -0
- data/ext/pg.c +703 -0
- data/ext/pg.h +391 -0
- data/ext/pg_binary_decoder.c +460 -0
- data/ext/pg_binary_encoder.c +590 -0
- data/ext/pg_cancel_connection.c +360 -0
- data/ext/pg_coder.c +671 -0
- data/ext/pg_connection.c +4890 -0
- data/ext/pg_copy_coder.c +921 -0
- data/ext/pg_errors.c +95 -0
- data/ext/pg_record_coder.c +522 -0
- data/ext/pg_result.c +1764 -0
- data/ext/pg_text_decoder.c +1008 -0
- data/ext/pg_text_encoder.c +846 -0
- data/ext/pg_tuple.c +572 -0
- data/ext/pg_type_map.c +200 -0
- data/ext/pg_type_map_all_strings.c +130 -0
- data/ext/pg_type_map_by_class.c +271 -0
- data/ext/pg_type_map_by_column.c +356 -0
- data/ext/pg_type_map_by_mri_type.c +313 -0
- data/ext/pg_type_map_by_oid.c +390 -0
- data/ext/pg_type_map_in_ruby.c +333 -0
- data/ext/pg_util.c +149 -0
- data/ext/pg_util.h +65 -0
- data/ext/vc/pg.sln +26 -0
- data/ext/vc/pg_18/pg.vcproj +216 -0
- data/ext/vc/pg_19/pg_19.vcproj +209 -0
- data/lib/2.7/pg_ext.so +0 -0
- data/lib/3.0/pg_ext.so +0 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/3.2/pg_ext.so +0 -0
- data/lib/3.3/pg_ext.so +0 -0
- data/lib/3.4/pg_ext.so +0 -0
- data/lib/pg/basic_type_map_based_on_result.rb +67 -0
- data/lib/pg/basic_type_map_for_queries.rb +206 -0
- data/lib/pg/basic_type_map_for_results.rb +104 -0
- data/lib/pg/basic_type_registry.rb +311 -0
- data/lib/pg/binary_decoder/date.rb +9 -0
- data/lib/pg/binary_decoder/timestamp.rb +26 -0
- data/lib/pg/binary_encoder/timestamp.rb +20 -0
- data/lib/pg/cancel_connection.rb +53 -0
- data/lib/pg/coder.rb +107 -0
- data/lib/pg/connection.rb +1092 -0
- data/lib/pg/exceptions.rb +31 -0
- data/lib/pg/result.rb +43 -0
- data/lib/pg/text_decoder/date.rb +21 -0
- data/lib/pg/text_decoder/inet.rb +9 -0
- data/lib/pg/text_decoder/json.rb +17 -0
- data/lib/pg/text_decoder/numeric.rb +9 -0
- data/lib/pg/text_decoder/timestamp.rb +30 -0
- data/lib/pg/text_encoder/date.rb +13 -0
- data/lib/pg/text_encoder/inet.rb +31 -0
- data/lib/pg/text_encoder/json.rb +17 -0
- data/lib/pg/text_encoder/numeric.rb +9 -0
- data/lib/pg/text_encoder/timestamp.rb +24 -0
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +16 -0
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +144 -0
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/misc/yugabyte/Dockerfile +9 -0
- data/misc/yugabyte/docker-compose.yml +28 -0
- data/misc/yugabyte/pg-test.rb +45 -0
- data/pg.gemspec +38 -0
- data/ports/aarch64-linux/lib/libpq-ruby-pg.so.1 +0 -0
- data/ports/patches/krb5/1.21.3/0001-Allow-static-linking-krb5-library.patch +30 -0
- data/ports/patches/openssl/3.5.1/0001-aarch64-mingw.patch +21 -0
- data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
- data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch +52 -0
- data/rakelib/pg_gem_helper.rb +64 -0
- data/rakelib/task_extension.rb +46 -0
- data/sample/array_insert.rb +20 -0
- data/sample/async_api.rb +102 -0
- data/sample/async_copyto.rb +39 -0
- data/sample/async_mixed.rb +56 -0
- data/sample/check_conn.rb +21 -0
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +81 -0
- data/sample/copyto.rb +19 -0
- data/sample/cursor.rb +21 -0
- data/sample/disk_usage_report.rb +177 -0
- data/sample/issue-119.rb +94 -0
- data/sample/losample.rb +69 -0
- data/sample/minimal-testcase.rb +17 -0
- data/sample/notify_wait.rb +72 -0
- data/sample/pg_statistics.rb +285 -0
- data/sample/replication_monitor.rb +222 -0
- data/sample/test_binary_values.rb +33 -0
- data/sample/wal_shipper.rb +434 -0
- data/sample/warehouse_partitions.rb +311 -0
- data.tar.gz.sig +0 -0
- metadata +258 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
services:
|
2
|
+
yb:
|
3
|
+
build: .
|
4
|
+
container_name: yb
|
5
|
+
ports:
|
6
|
+
- "127.0.0.1:5433:5433"
|
7
|
+
volumes:
|
8
|
+
- certs:/app/generated_certs
|
9
|
+
healthcheck:
|
10
|
+
test: 'ysqlsh -h $$(hostname) -c \\conninfo || exit 1;'
|
11
|
+
interval: 2s
|
12
|
+
timeout: 30s
|
13
|
+
retries: 20
|
14
|
+
start_period: 10s
|
15
|
+
|
16
|
+
pg:
|
17
|
+
image: ruby:3.0
|
18
|
+
working_dir: /app
|
19
|
+
volumes:
|
20
|
+
- .:/app
|
21
|
+
- certs:/generated_certs
|
22
|
+
command: bash -c "gem inst pg-*.gem && ruby pg-test.rb"
|
23
|
+
depends_on:
|
24
|
+
yb:
|
25
|
+
condition: service_healthy
|
26
|
+
|
27
|
+
volumes:
|
28
|
+
certs:
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pg'
|
2
|
+
|
3
|
+
conn = PG.connect(
|
4
|
+
host: 'yb',
|
5
|
+
port: 5433,
|
6
|
+
user: 'yugabyte',
|
7
|
+
dbname: 'yugabyte',
|
8
|
+
sslmode: 'require',
|
9
|
+
sslrootcert: 'app/generated_certs/127.0.0.1/ca.crt',
|
10
|
+
sslcert: 'app/generated_certs/127.0.0.1/node.127.0.0.1.crt',
|
11
|
+
sslkey: 'app/generated_certs/127.0.0.1/node.127.0.0.1.key'
|
12
|
+
)
|
13
|
+
|
14
|
+
$stdout.sync = true
|
15
|
+
# fd = File.open("pg_trace.log", "a+")
|
16
|
+
# conn.trace(fd)
|
17
|
+
|
18
|
+
begin
|
19
|
+
# Validate connection is working
|
20
|
+
res = conn.exec("SELECT version();")
|
21
|
+
res.each_row do |row|
|
22
|
+
puts "You are connected to: #{row[0]}"
|
23
|
+
end
|
24
|
+
# 53*511
|
25
|
+
# 53*767
|
26
|
+
# 53*1023
|
27
|
+
# 53*1279
|
28
|
+
# 7*1817
|
29
|
+
# 11*1487
|
30
|
+
# 13*1363
|
31
|
+
# 16*1211
|
32
|
+
# 18*1128
|
33
|
+
# 22*1984
|
34
|
+
# 27*1723
|
35
|
+
|
36
|
+
(22..53).each do |m|
|
37
|
+
(1..2048).each do |l|
|
38
|
+
hanging_query = "SELECT lpad(''::text, #{m}, '0') FROM generate_series(1, #{l});"
|
39
|
+
puts "Executing hanging query: #{hanging_query}"
|
40
|
+
conn.exec(hanging_query)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
ensure
|
44
|
+
conn.close if conn
|
45
|
+
end
|
data/pg.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
4
|
+
require_relative 'lib/pg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pg"
|
8
|
+
spec.version = PG::VERSION
|
9
|
+
spec.authors = ["Michael Granger", "Lars Kanis"]
|
10
|
+
spec.email = ["ged@FaerieMUD.org", "lars@greiz-reinsdorf.de"]
|
11
|
+
|
12
|
+
spec.summary = "Pg is the Ruby interface to the PostgreSQL RDBMS"
|
13
|
+
spec.description = "Pg is the Ruby interface to the PostgreSQL RDBMS. It works with PostgreSQL 10 and later."
|
14
|
+
spec.homepage = "https://github.com/ged/ruby-pg"
|
15
|
+
spec.license = "BSD-2-Clause"
|
16
|
+
spec.required_ruby_version = ">= 2.7"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/ged/ruby-pg"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/ged/ruby-pg/blob/master/CHANGELOG.md"
|
21
|
+
spec.metadata["documentation_uri"] = "http://deveiate.org/code/pg"
|
22
|
+
# https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers#msys2-library-dependency
|
23
|
+
spec.metadata["msys2_mingw_dependencies"] = "postgresql"
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{\A(?:test|spec|features|translation|\.)})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
spec.extensions = ["ext/extconf.rb"]
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
spec.cert_chain = ["certs/ged.pem"]
|
35
|
+
spec.rdoc_options = ["--main", "README.md",
|
36
|
+
"--title", "PG: The Ruby PostgreSQL Driver"]
|
37
|
+
spec.extra_rdoc_files = `git ls-files -z *.rdoc *.md lib/*.rb lib/*/*.rb lib/*/*/*.rb ext/*.c ext/*.h`.split("\x0")
|
38
|
+
end
|
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
From e82c1b395162ea71279ea2170259383082e41ab0 Mon Sep 17 00:00:00 2001
|
2
|
+
From: Lars Kanis <lars@greiz-reinsdorf.de>
|
3
|
+
Date: Sat, 12 Jul 2025 10:55:17 +0200
|
4
|
+
Subject: [PATCH] Allow static linking krb5 library
|
5
|
+
|
6
|
+
Otherwise it fails with:
|
7
|
+
Undefined symbols for architecture arm64:
|
8
|
+
"_krb5int_c_mit_des_zeroblock", referenced from:
|
9
|
+
_krb5int_des3_cbc_encrypt in libk5crypto.a(d3_aead.o)
|
10
|
+
_krb5int_des3_cbc_decrypt in libk5crypto.a(d3_aead.o)
|
11
|
+
---
|
12
|
+
src/lib/crypto/builtin/des/des_int.h | 2 +-
|
13
|
+
1 file changed, 1 insertion(+), 1 deletion(-)
|
14
|
+
|
15
|
+
diff --git a/src/lib/crypto/builtin/des/des_int.h b/src/lib/crypto/builtin/des/des_int.h
|
16
|
+
index 46fed7dbd..114e48ebd 100644
|
17
|
+
--- a/lib/crypto/builtin/des/des_int.h
|
18
|
+
+++ b/lib/crypto/builtin/des/des_int.h
|
19
|
+
@@ -159,7 +159,7 @@ mit_des_cbc_encrypt(const mit_des_cblock *in, mit_des_cblock *out,
|
20
|
+
const mit_des_cblock ivec, int enc);
|
21
|
+
|
22
|
+
#define mit_des_zeroblock krb5int_c_mit_des_zeroblock
|
23
|
+
-extern const mit_des_cblock mit_des_zeroblock;
|
24
|
+
+const mit_des_cblock mit_des_zeroblock;
|
25
|
+
|
26
|
+
/* fin_rndkey.c */
|
27
|
+
krb5_error_code mit_des_finish_random_key(const krb5_encrypt_block *,
|
28
|
+
--
|
29
|
+
2.43.0
|
30
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
--- a/Configurations/10-main.conf
|
2
|
+
+++ b/Configurations/10-main.conf
|
3
|
+
@@ -1603,6 +1603,18 @@
|
4
|
+
multilib => "64",
|
5
|
+
},
|
6
|
+
|
7
|
+
+ "mingwarm64" => {
|
8
|
+
+ inherit_from => [ "mingw-common" ],
|
9
|
+
+ cflags => "",
|
10
|
+
+ sys_id => "MINGWARM64",
|
11
|
+
+ bn_ops => add("SIXTY_FOUR_BIT"),
|
12
|
+
+ asm_arch => 'aarch64',
|
13
|
+
+ uplink_arch => 'armv8',
|
14
|
+
+ perlasm_scheme => "win64",
|
15
|
+
+ shared_rcflag => "",
|
16
|
+
+ multilib => "-arm64",
|
17
|
+
+ },
|
18
|
+
+
|
19
|
+
#### UEFI
|
20
|
+
"UEFI" => {
|
21
|
+
inherit_from => [ "BASE_unix" ],
|
data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
From 746e8e250b265c40d9706f26560e02e8623f123f Mon Sep 17 00:00:00 2001
|
2
|
+
From: Lars Kanis <lars@greiz-reinsdorf.de>
|
3
|
+
Date: Fri, 31 Jan 2025 21:58:00 +0100
|
4
|
+
Subject: [PATCH] Use workaround of __builtin_setjmp only on MINGW on MSVCRT
|
5
|
+
|
6
|
+
Because it is not present on ARM64 on Windows and not necessary on any UCRT based toolchain.
|
7
|
+
---
|
8
|
+
src/include/c.h | 10 +++++-----
|
9
|
+
1 file changed, 5 insertions(+), 5 deletions(-)
|
10
|
+
|
11
|
+
diff --git a/src/include/c.h b/src/include/c.h
|
12
|
+
index a14c631516..33792c860c 100644
|
13
|
+
--- a/src/include/c.h
|
14
|
+
+++ b/src/include/c.h
|
15
|
+
@@ -1312,19 +1312,19 @@ extern int fdatasync(int fildes);
|
16
|
+
/*
|
17
|
+
* When there is no sigsetjmp, its functionality is provided by plain
|
18
|
+
* setjmp. We now support the case only on Windows. However, it seems
|
19
|
+
- * that MinGW-64 has some longstanding issues in its setjmp support,
|
20
|
+
- * so on that toolchain we cheat and use gcc's builtins.
|
21
|
+
+ * that MinGW-64 on x86_64 has some longstanding issues in its setjmp
|
22
|
+
+ * support, so on that toolchain we cheat and use gcc's builtins.
|
23
|
+
*/
|
24
|
+
#ifdef WIN32
|
25
|
+
-#ifdef __MINGW64__
|
26
|
+
+#if defined(__MINGW64__) && !defined(_UCRT)
|
27
|
+
typedef intptr_t sigjmp_buf[5];
|
28
|
+
#define sigsetjmp(x,y) __builtin_setjmp(x)
|
29
|
+
#define siglongjmp __builtin_longjmp
|
30
|
+
-#else /* !__MINGW64__ */
|
31
|
+
+#else /* !defined(__MINGW64__) || defined(_UCRT) */
|
32
|
+
#define sigjmp_buf jmp_buf
|
33
|
+
#define sigsetjmp(x,y) setjmp(x)
|
34
|
+
#define siglongjmp longjmp
|
35
|
+
-#endif /* __MINGW64__ */
|
36
|
+
+#endif /* defined(__MINGW64__) && !defined(_UCRT) */
|
37
|
+
#endif /* WIN32 */
|
38
|
+
|
39
|
+
/* /port compatibility functions */
|
40
|
+
--
|
41
|
+
2.43.0
|
42
|
+
|
data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
From ab793829a4ce473f1cc2bbc0e2a6f6753553255d Mon Sep 17 00:00:00 2001
|
2
|
+
From: Lars Kanis <lars@greiz-reinsdorf.de>
|
3
|
+
Date: Sun, 8 Sep 2024 13:59:05 +0200
|
4
|
+
Subject: [PATCH] libpq: Process buffered SSL read bytes to support records
|
5
|
+
>8kB on async API
|
6
|
+
|
7
|
+
The async API of libpq doesn't support SSL record sizes >8kB so far.
|
8
|
+
This size isn't exceeded by vanilla PostgreSQL, but by other products using
|
9
|
+
the postgres wire protocol 3.
|
10
|
+
PQconsumeInput() reads all data readable from the socket, so that the read
|
11
|
+
condition is cleared.
|
12
|
+
But it doesn't process all the data that is pending on the SSL layer.
|
13
|
+
Also a subsequent call to PQisBusy() doesn't process it, so that the client
|
14
|
+
is triggered to wait for more readable data on the socket.
|
15
|
+
But this never arrives, so that the connection blocks infinitely.
|
16
|
+
|
17
|
+
To fix this issue call pqReadData() repeatedly until there is no buffered
|
18
|
+
SSL data left to be read.
|
19
|
+
|
20
|
+
The synchronous libpq API isn't affected, since it supports arbitrary SSL
|
21
|
+
record sizes already.
|
22
|
+
---
|
23
|
+
src/interfaces/libpq/fe-exec.c | 13 +++++++++++++
|
24
|
+
1 file changed, 13 insertions(+)
|
25
|
+
|
26
|
+
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
|
27
|
+
index 0d224a852..637894ee1 100644
|
28
|
+
--- a/src/interfaces/libpq/fe-exec.c
|
29
|
+
+++ b/src/interfaces/libpq/fe-exec.c
|
30
|
+
@@ -2006,6 +2006,19 @@ PQconsumeInput(PGconn *conn)
|
31
|
+
if (pqReadData(conn) < 0)
|
32
|
+
return 0;
|
33
|
+
|
34
|
+
+ #ifdef USE_SSL
|
35
|
+
+ /*
|
36
|
+
+ * Ensure all buffered read bytes in the SSL library are processed,
|
37
|
+
+ * which might be not the case, if the SSL record size exceeds 8k.
|
38
|
+
+ * Otherwise parseInput can't process the data.
|
39
|
+
+ */
|
40
|
+
+ while (conn->ssl_in_use && pgtls_read_pending(conn))
|
41
|
+
+ {
|
42
|
+
+ if (pqReadData(conn) < 0)
|
43
|
+
+ return 0;
|
44
|
+
+ }
|
45
|
+
+ #endif
|
46
|
+
+
|
47
|
+
/* Parsing of the data waits till later. */
|
48
|
+
return 1;
|
49
|
+
}
|
50
|
+
--
|
51
|
+
2.43.0
|
52
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/gem_helper'
|
3
|
+
|
4
|
+
class PgGemHelper < Bundler::GemHelper
|
5
|
+
attr_accessor :cross_platforms
|
6
|
+
|
7
|
+
def install
|
8
|
+
super
|
9
|
+
|
10
|
+
task "release:guard_clean" => ["release:update_history"]
|
11
|
+
|
12
|
+
task "release:update_history" do
|
13
|
+
update_history
|
14
|
+
end
|
15
|
+
|
16
|
+
task "release:rubygem_push" => ["gem:native"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def hfile
|
20
|
+
"CHANGELOG.md"
|
21
|
+
end
|
22
|
+
|
23
|
+
def headline
|
24
|
+
'^([^\n]*)(\d+\.\d+\.\d+(?:\.\w+)?)([^\w]+)([2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])([^\w]*|$)'
|
25
|
+
end
|
26
|
+
|
27
|
+
def reldate
|
28
|
+
Time.now.strftime("%Y-%m-%d")
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_history
|
32
|
+
hin = File.read(hfile)
|
33
|
+
hout = hin.sub(/#{headline}/) do
|
34
|
+
raise "#{hfile} isn't up-to-date for version #{version} (!= #{$2})" unless $2==version.to_s
|
35
|
+
$1 + $2 + $3 + reldate + $5
|
36
|
+
end
|
37
|
+
if hout != hin
|
38
|
+
Bundler.ui.confirm "Updating #{hfile} for release."
|
39
|
+
File.write(hfile, hout)
|
40
|
+
Rake::FileUtilsExt.sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def tag_version
|
45
|
+
Bundler.ui.confirm "Tag release with annotation:"
|
46
|
+
m = File.read(hfile).match(/(?<annotation>#{headline}.*?)#{headline}/m) || raise("Unable to find release notes in #{hfile}")
|
47
|
+
Bundler.ui.info(m[:annotation].gsub(/^/, " "))
|
48
|
+
IO.popen(["git", "tag", "--file=-", version_tag], "w") do |fd|
|
49
|
+
fd.write m[:annotation]
|
50
|
+
end
|
51
|
+
yield if block_given?
|
52
|
+
rescue
|
53
|
+
Bundler.ui.error "Untagging #{version_tag} due to error."
|
54
|
+
Rake::FileUtilsExt.sh "git", "tag", "-d", version_tag
|
55
|
+
raise
|
56
|
+
end
|
57
|
+
|
58
|
+
def rubygem_push(path)
|
59
|
+
cross_platforms.each do |ruby_platform|
|
60
|
+
super(path.gsub(/\.gem\z/, "-#{ruby_platform}.gem"))
|
61
|
+
end
|
62
|
+
super(path)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# This source code is borrowed from:
|
2
|
+
# https://github.com/oneclick/rubyinstaller2/blob/b3dcbf69f131e44c78ea3a1c5e0041c223f266ce/lib/ruby_installer/build/utils.rb#L104-L144
|
3
|
+
|
4
|
+
module TaskExtension
|
5
|
+
# Extend rake's file task to be defined only once and to check the expected file is indeed generated
|
6
|
+
#
|
7
|
+
# The same as #task, but for #file.
|
8
|
+
# In addition this file task raises an error, if the file that is expected to be generated is not present after the block was executed.
|
9
|
+
def file(name, *args, &block)
|
10
|
+
task_once(name, block) do
|
11
|
+
super(name, *args) do |ta|
|
12
|
+
block&.call(ta).tap do
|
13
|
+
raise "file #{ta.name} is missing after task executed" unless File.exist?(ta.name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Extend rake's task definition to be defined only once, even if called several times
|
20
|
+
#
|
21
|
+
# This allows to define common tasks next to specific tasks.
|
22
|
+
# It is expected that any variation of the task's block is reflected in the task name or namespace.
|
23
|
+
# If the task name is identical, the task block is executed only once, even if the file task definition is executed twice.
|
24
|
+
def task(name, *args, &block)
|
25
|
+
task_once(name, block) do
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private def task_once(name, block)
|
31
|
+
name = name.keys.first if name.is_a?(Hash)
|
32
|
+
if block &&
|
33
|
+
Rake::Task.task_defined?(name) &&
|
34
|
+
Rake::Task[name].instance_variable_get('@task_block_location') == block.source_location
|
35
|
+
# task is already defined for this target and the same block
|
36
|
+
# So skip double definition of the same action
|
37
|
+
Rake::Task[name]
|
38
|
+
elsif block
|
39
|
+
yield.tap do
|
40
|
+
Rake::Task[name].instance_variable_set('@task_block_location', block.source_location)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
|
5
|
+
c = PG.connect( dbname: 'test' )
|
6
|
+
|
7
|
+
# this one works:
|
8
|
+
c.exec( "DROP TABLE IF EXISTS foo" )
|
9
|
+
c.exec( "CREATE TABLE foo (strings character varying[]);" )
|
10
|
+
|
11
|
+
# But using a prepared statement works:
|
12
|
+
c.set_error_verbosity( PG::PQERRORS_VERBOSE )
|
13
|
+
c.prepare( 'stmt', "INSERT INTO foo VALUES ($1);" )
|
14
|
+
|
15
|
+
# This won't work
|
16
|
+
#c.exec_prepared( 'stmt', ["ARRAY['this','that']"] )
|
17
|
+
|
18
|
+
# but this will:
|
19
|
+
c.exec_prepared( 'stmt', ["{'this','that'}"] )
|
20
|
+
|
data/sample/async_api.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
|
5
|
+
# This is a example of how to use the asynchronous API to query the
|
6
|
+
# server without blocking other threads. It's intentionally low-level;
|
7
|
+
# if you hooked up the PG::Connection#socket to some kind of reactor, you
|
8
|
+
# could make this much nicer.
|
9
|
+
|
10
|
+
TIMEOUT = 5.0 # seconds to wait for an async operation to complete
|
11
|
+
|
12
|
+
# Print 'x' continuously to demonstrate that other threads aren't
|
13
|
+
# blocked while waiting for the connection, for the query to be sent,
|
14
|
+
# for results, etc. You might want to sleep inside the loop or
|
15
|
+
# comment this out entirely for cleaner output.
|
16
|
+
progress_thread = Thread.new { loop { print 'x' } }
|
17
|
+
|
18
|
+
# Output progress messages
|
19
|
+
def output_progress( msg )
|
20
|
+
puts "\n>>> #{msg}\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Start the connection
|
24
|
+
output_progress "Starting connection..."
|
25
|
+
conn = PG::Connection.connect_start( :dbname => 'test' ) or
|
26
|
+
abort "Unable to create a new connection!"
|
27
|
+
abort "Connection failed: %s" % [ conn.error_message ] if
|
28
|
+
conn.status == PG::CONNECTION_BAD
|
29
|
+
|
30
|
+
# Track the progress of the connection, waiting for the socket to become readable/writable
|
31
|
+
# before polling it
|
32
|
+
poll_status = PG::PGRES_POLLING_WRITING
|
33
|
+
until poll_status == PG::PGRES_POLLING_OK ||
|
34
|
+
poll_status == PG::PGRES_POLLING_FAILED
|
35
|
+
|
36
|
+
# If the socket needs to read, wait 'til it becomes readable to poll again
|
37
|
+
case poll_status
|
38
|
+
when PG::PGRES_POLLING_READING
|
39
|
+
output_progress " waiting for socket to become readable"
|
40
|
+
select( [conn.socket_io], nil, nil, TIMEOUT ) or
|
41
|
+
raise "Asynchronous connection timed out!"
|
42
|
+
|
43
|
+
# ...and the same for when the socket needs to write
|
44
|
+
when PG::PGRES_POLLING_WRITING
|
45
|
+
output_progress " waiting for socket to become writable"
|
46
|
+
select( nil, [conn.socket_io], nil, TIMEOUT ) or
|
47
|
+
raise "Asynchronous connection timed out!"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Output a status message about the progress
|
51
|
+
case conn.status
|
52
|
+
when PG::CONNECTION_STARTED
|
53
|
+
output_progress " waiting for connection to be made."
|
54
|
+
when PG::CONNECTION_MADE
|
55
|
+
output_progress " connection OK; waiting to send."
|
56
|
+
when PG::CONNECTION_AWAITING_RESPONSE
|
57
|
+
output_progress " waiting for a response from the server."
|
58
|
+
when PG::CONNECTION_AUTH_OK
|
59
|
+
output_progress " received authentication; waiting for backend start-up to finish."
|
60
|
+
when PG::CONNECTION_SSL_STARTUP
|
61
|
+
output_progress " negotiating SSL encryption."
|
62
|
+
when PG::CONNECTION_SETENV
|
63
|
+
output_progress " negotiating environment-driven parameter settings."
|
64
|
+
when PG::CONNECTION_NEEDED
|
65
|
+
output_progress " internal state: connect() needed."
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check to see if it's finished or failed yet
|
69
|
+
poll_status = conn.connect_poll
|
70
|
+
end
|
71
|
+
|
72
|
+
abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
|
73
|
+
|
74
|
+
output_progress "Sending query"
|
75
|
+
conn.send_query( "SELECT * FROM pg_stat_activity" )
|
76
|
+
|
77
|
+
# Fetch results until there aren't any more
|
78
|
+
loop do
|
79
|
+
output_progress " waiting for a response"
|
80
|
+
|
81
|
+
# Buffer any incoming data on the socket until a full result is ready.
|
82
|
+
conn.consume_input
|
83
|
+
while conn.is_busy
|
84
|
+
select( [conn.socket_io], nil, nil, TIMEOUT ) or
|
85
|
+
raise "Timeout waiting for query response."
|
86
|
+
conn.consume_input
|
87
|
+
end
|
88
|
+
|
89
|
+
# Fetch the next result. If there isn't one, the query is finished
|
90
|
+
result = conn.get_result or break
|
91
|
+
|
92
|
+
puts "\n\nQuery result:\n%p\n" % [ result.values ]
|
93
|
+
end
|
94
|
+
|
95
|
+
output_progress "Done."
|
96
|
+
conn.finish
|
97
|
+
|
98
|
+
if defined?( progress_thread )
|
99
|
+
progress_thread.kill
|
100
|
+
progress_thread.join
|
101
|
+
end
|
102
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
# Using COPY asynchronously
|
7
|
+
|
8
|
+
$stderr.puts "Opening database connection ..."
|
9
|
+
conn = PG.connect( :dbname => 'test' )
|
10
|
+
conn.setnonblocking( true )
|
11
|
+
|
12
|
+
socket = conn.socket_io
|
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
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
|
5
|
+
$stdout.sync = true
|
6
|
+
|
7
|
+
# This is a example of how to mix and match synchronous and async APIs. In this case,
|
8
|
+
# the connection to the server is made syncrhonously, and then queries are
|
9
|
+
# asynchronous.
|
10
|
+
|
11
|
+
TIMEOUT = 5.0 # seconds to wait for an async operation to complete
|
12
|
+
CONN_OPTS = {
|
13
|
+
:host => 'localhost',
|
14
|
+
:dbname => 'test',
|
15
|
+
}
|
16
|
+
|
17
|
+
# Output progress messages
|
18
|
+
def output_progress( msg )
|
19
|
+
puts ">>> #{msg}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Start the (synchronous) connection
|
23
|
+
output_progress "Starting connection..."
|
24
|
+
conn = PG.connect( CONN_OPTS ) or abort "Unable to create a new connection!"
|
25
|
+
|
26
|
+
abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
|
27
|
+
|
28
|
+
# Now grab a reference to the underlying socket to select() on while the query is running
|
29
|
+
socket = conn.socket_io
|
30
|
+
|
31
|
+
# Send the (asynchronous) query
|
32
|
+
output_progress "Sending query"
|
33
|
+
conn.send_query( "SELECT * FROM pg_stat_activity" )
|
34
|
+
|
35
|
+
# Fetch results until there aren't any more
|
36
|
+
loop do
|
37
|
+
output_progress " waiting for a response"
|
38
|
+
|
39
|
+
# Buffer any incoming data on the socket until a full result is ready.
|
40
|
+
conn.consume_input
|
41
|
+
while conn.is_busy
|
42
|
+
output_progress " waiting for data to be available on %p..." % [ socket ]
|
43
|
+
select( [socket], nil, nil, TIMEOUT ) or
|
44
|
+
raise "Timeout waiting for query response."
|
45
|
+
conn.consume_input
|
46
|
+
end
|
47
|
+
|
48
|
+
# Fetch the next result. If there isn't one, the query is finished
|
49
|
+
result = conn.get_result or break
|
50
|
+
|
51
|
+
output_progress "Query result:\n%p\n" % [ result.values ]
|
52
|
+
end
|
53
|
+
|
54
|
+
output_progress "Done."
|
55
|
+
conn.finish
|
56
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
3
|
+
# encoding: utf-8
|
4
|
+
|
5
|
+
require 'pg'
|
6
|
+
|
7
|
+
# This is a minimal example of a function that can test an existing PG::Connection and
|
8
|
+
# reset it if necessary.
|
9
|
+
|
10
|
+
def check_connection( conn )
|
11
|
+
begin
|
12
|
+
conn.exec( "SELECT 1" )
|
13
|
+
rescue PG::Error => err
|
14
|
+
$stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
|
15
|
+
conn.reset
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
conn = PG.connect( dbname: 'test' )
|
20
|
+
check_connection( conn )
|
21
|
+
|