globegit-postgresql-plruby 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +121 -0
- data/README.markdown +155 -0
- data/Rakefile +48 -0
- data/docs/plruby.rb +1931 -0
- data/ex_trans.sql +33 -0
- data/extconf.rb +267 -0
- data/plruby.html +1454 -0
- data/plruby.rd +1571 -0
- data/postgresql-plruby.gemspec +56 -0
- data/src/conversions.h +5 -0
- data/src/conversions/basic/conversions.h +25 -0
- data/src/conversions/basic/extconf.rb +8 -0
- data/src/conversions/basic/plruby_basic.c +357 -0
- data/src/conversions/bitstring/bitstring.sql +75 -0
- data/src/conversions/bitstring/conversions.h +15 -0
- data/src/conversions/bitstring/extconf.rb +8 -0
- data/src/conversions/bitstring/plruby_bitstring.c +579 -0
- data/src/conversions/convcommon.h +129 -0
- data/src/conversions/datetime/conversions.h +13 -0
- data/src/conversions/datetime/extconf.rb +8 -0
- data/src/conversions/datetime/plruby_datetime.c +269 -0
- data/src/conversions/geometry/conversions.h +37 -0
- data/src/conversions/geometry/extconf.rb +8 -0
- data/src/conversions/geometry/geometry.sql +196 -0
- data/src/conversions/geometry/plruby_geometry.c +2494 -0
- data/src/conversions/network/conversions.h +21 -0
- data/src/conversions/network/extconf.rb +8 -0
- data/src/conversions/network/network.sql +63 -0
- data/src/conversions/network/plruby_network.c +537 -0
- data/src/package.h +20 -0
- data/src/plpl.c +1708 -0
- data/src/plplan.c +893 -0
- data/src/plruby.c +1676 -0
- data/src/plruby.h +324 -0
- data/src/pltrans.c +388 -0
- data/test/conv_bitstring/b.rb +45 -0
- data/test/conv_bitstring/runtest +26 -0
- data/test/conv_bitstring/test.expected.73 +148 -0
- data/test/conv_bitstring/test.expected.74 +148 -0
- data/test/conv_bitstring/test.expected.80 +148 -0
- data/test/conv_bitstring/test.expected.81 +148 -0
- data/test/conv_bitstring/test.expected.82 +148 -0
- data/test/conv_bitstring/test.expected.83 +148 -0
- data/test/conv_bitstring/test.expected.84 +148 -0
- data/test/conv_bitstring/test.out +148 -0
- data/test/conv_bitstring/test_mklang.sql +8 -0
- data/test/conv_bitstring/test_queries.sql +63 -0
- data/test/conv_bitstring/test_queries.sql.in +63 -0
- data/test/conv_geometry/b.rb +45 -0
- data/test/conv_geometry/runtest +26 -0
- data/test/conv_geometry/test.expected.73 +265 -0
- data/test/conv_geometry/test.expected.74 +265 -0
- data/test/conv_geometry/test.expected.80 +265 -0
- data/test/conv_geometry/test.expected.81 +265 -0
- data/test/conv_geometry/test.expected.82 +265 -0
- data/test/conv_geometry/test.expected.83 +265 -0
- data/test/conv_geometry/test.expected.84 +265 -0
- data/test/conv_geometry/test.out +265 -0
- data/test/conv_geometry/test_mklang.sql +8 -0
- data/test/conv_geometry/test_queries.sql +194 -0
- data/test/conv_geometry/test_queries.sql.in +194 -0
- data/test/conv_network/b.rb +45 -0
- data/test/conv_network/runtest +26 -0
- data/test/conv_network/test.expected.73 +213 -0
- data/test/conv_network/test.expected.74 +237 -0
- data/test/conv_network/test.expected.80 +237 -0
- data/test/conv_network/test.expected.81 +237 -0
- data/test/conv_network/test.expected.82 +237 -0
- data/test/conv_network/test.expected.83 +237 -0
- data/test/conv_network/test.expected.84 +237 -0
- data/test/conv_network/test.out +237 -0
- data/test/conv_network/test_mklang.sql +8 -0
- data/test/conv_network/test_queries.sql +60 -0
- data/test/conv_network/test_queries.sql.in +60 -0
- data/test/plp/b.rb +34 -0
- data/test/plp/runtest +29 -0
- data/test/plp/test.expected.73 +472 -0
- data/test/plp/test.expected.74 +472 -0
- data/test/plp/test.expected.75 +472 -0
- data/test/plp/test.expected.80 +472 -0
- data/test/plp/test.expected.81 +472 -0
- data/test/plp/test.expected.82 +472 -0
- data/test/plp/test.expected.83 +472 -0
- data/test/plp/test.expected.84 +472 -0
- data/test/plp/test.out +472 -0
- data/test/plp/test_mklang.sql +8 -0
- data/test/plp/test_queries.sql +273 -0
- data/test/plp/test_setup.sql +931 -0
- data/test/plp/test_setup.sql.in +931 -0
- data/test/plt/b.rb +34 -0
- data/test/plt/runtest +29 -0
- data/test/plt/test.expected.73 +178 -0
- data/test/plt/test.expected.74 +178 -0
- data/test/plt/test.expected.75 +178 -0
- data/test/plt/test.expected.80 +178 -0
- data/test/plt/test.expected.81 +178 -0
- data/test/plt/test.expected.82 +178 -0
- data/test/plt/test.expected.83 +164 -0
- data/test/plt/test.expected.84 +168 -0
- data/test/plt/test.out +168 -0
- data/test/plt/test_mklang.sql +8 -0
- data/test/plt/test_queries.sql +72 -0
- data/test/plt/test_setup.sql +252 -0
- data/test/plt/test_setup.sql.in +252 -0
- data/test/range/b.rb +45 -0
- data/test/range/runtest +26 -0
- data/test/range/test.expected.73 +396 -0
- data/test/range/test.expected.73.in +396 -0
- data/test/range/test.expected.74 +396 -0
- data/test/range/test.expected.74.in +396 -0
- data/test/range/test.expected.75 +396 -0
- data/test/range/test.expected.75.in +396 -0
- data/test/range/test.expected.80 +396 -0
- data/test/range/test.expected.81 +397 -0
- data/test/range/test.expected.82 +397 -0
- data/test/range/test.expected.83 +397 -0
- data/test/range/test.expected.84 +399 -0
- data/test/range/test.out +399 -0
- data/test/range/test_mklang.sql +8 -0
- data/test/range/test_queries.sql +249 -0
- data/test/range/test_queries.sql.in +249 -0
- metadata +207 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rbconfig'
|
3
|
+
include Config
|
4
|
+
pwd = Dir.pwd
|
5
|
+
pwd.sub!(%r{[^/]+/[^/]+$}, "")
|
6
|
+
|
7
|
+
language, extension = 'C', '_new_trigger'
|
8
|
+
opaque = 'language_handler'
|
9
|
+
|
10
|
+
version = ARGV[0].to_i
|
11
|
+
suffix = ARGV[1].to_s
|
12
|
+
|
13
|
+
begin
|
14
|
+
f = File.new("test_queries.sql", "w")
|
15
|
+
IO.foreach("test_queries.sql.in") do |x|
|
16
|
+
x.gsub!(/language\s+'plruby'/i, "language 'plruby#{suffix}'")
|
17
|
+
f.print x
|
18
|
+
end
|
19
|
+
f.close
|
20
|
+
|
21
|
+
Dir["test.expected.*.in"].each do |name|
|
22
|
+
result = name.sub(/\.in\z/, '')
|
23
|
+
f = File.new(result, "w")
|
24
|
+
IO.foreach(name) do |x|
|
25
|
+
x.gsub!(/'plruby'/i, "'plruby#{suffix}'")
|
26
|
+
f.print x
|
27
|
+
end
|
28
|
+
f.close
|
29
|
+
end
|
30
|
+
|
31
|
+
f = File.new("test_mklang.sql", "w")
|
32
|
+
f.print <<EOF
|
33
|
+
|
34
|
+
create function plruby#{suffix}_call_handler() returns #{opaque}
|
35
|
+
as '#{pwd}src/plruby#{suffix}.#{CONFIG["DLEXT"]}'
|
36
|
+
language '#{language}';
|
37
|
+
|
38
|
+
create trusted procedural language 'plruby#{suffix}'
|
39
|
+
handler plruby#{suffix}_call_handler
|
40
|
+
lancompiler 'PL/Ruby';
|
41
|
+
EOF
|
42
|
+
f.close
|
43
|
+
rescue
|
44
|
+
raise "Why I can't write #$!"
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
DBNAME=plruby_test
|
4
|
+
export DBNAME
|
5
|
+
|
6
|
+
sleep 1
|
7
|
+
echo "**** Destroy old database $DBNAME ****"
|
8
|
+
dropdb $DBNAME
|
9
|
+
|
10
|
+
echo "**** Create test database $DBNAME ****"
|
11
|
+
createdb $DBNAME
|
12
|
+
|
13
|
+
echo "**** Create procedural language plruby$2 ****"
|
14
|
+
"${RUBY-ruby}" b.rb $*
|
15
|
+
psql -q -n -X $DBNAME < test_mklang.sql
|
16
|
+
|
17
|
+
echo "**** Running test queries ****"
|
18
|
+
psql -q -n -X -e $DBNAME < test_queries.sql > test.out 2>&1
|
19
|
+
|
20
|
+
if cmp -s test.expected.$1 test.out; then
|
21
|
+
echo " Tests passed O.K."
|
22
|
+
else
|
23
|
+
echo " Tests failed - look at diffs between"
|
24
|
+
echo " test.expected.$1 and test.out"
|
25
|
+
fi
|
26
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
create table bit_op (
|
2
|
+
b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
|
3
|
+
bxor bit(8), bnot0 bit(8), bnot1 bit(8)
|
4
|
+
);
|
5
|
+
create function bt(integer, integer) returns bit_op as '
|
6
|
+
b0 = BitString.new(args[0], 8)
|
7
|
+
b1 = BitString.new(args[1], 8)
|
8
|
+
[b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
|
9
|
+
' language 'plruby';
|
10
|
+
select * from bt(12, 24);
|
11
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
12
|
+
----------+----------+----------+----------+----------+----------+----------
|
13
|
+
00001100 | 00011000 | 00001000 | 00011100 | 00010100 | 11110011 | 11100111
|
14
|
+
(1 row)
|
15
|
+
|
16
|
+
select * from bt(12, 32);
|
17
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
18
|
+
----------+----------+----------+----------+----------+----------+----------
|
19
|
+
00001100 | 00100000 | 00000000 | 00101100 | 00101100 | 11110011 | 11011111
|
20
|
+
(1 row)
|
21
|
+
|
22
|
+
select * from bt(15, 278);
|
23
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
24
|
+
----------+----------+----------+----------+----------+----------+----------
|
25
|
+
00001111 | 00010110 | 00000110 | 00011111 | 00011001 | 11110000 | 11101001
|
26
|
+
(1 row)
|
27
|
+
|
28
|
+
create function be(integer) returns setof integer as '
|
29
|
+
BitString.new(args[0], 8).each {|i| yield i}
|
30
|
+
' language 'plruby';
|
31
|
+
select * from be(12);
|
32
|
+
be
|
33
|
+
----
|
34
|
+
0
|
35
|
+
0
|
36
|
+
0
|
37
|
+
0
|
38
|
+
1
|
39
|
+
1
|
40
|
+
0
|
41
|
+
0
|
42
|
+
(8 rows)
|
43
|
+
|
44
|
+
select * from be(257);
|
45
|
+
be
|
46
|
+
----
|
47
|
+
0
|
48
|
+
0
|
49
|
+
0
|
50
|
+
0
|
51
|
+
0
|
52
|
+
0
|
53
|
+
0
|
54
|
+
1
|
55
|
+
(8 rows)
|
56
|
+
|
57
|
+
create function bx(integer, integer) returns bit varying as '
|
58
|
+
BitString.new(*args)
|
59
|
+
' language 'plruby';
|
60
|
+
select bx(12, 6);
|
61
|
+
bx
|
62
|
+
--------
|
63
|
+
001100
|
64
|
+
(1 row)
|
65
|
+
|
66
|
+
select bx(12, 8);
|
67
|
+
bx
|
68
|
+
----------
|
69
|
+
00001100
|
70
|
+
(1 row)
|
71
|
+
|
72
|
+
create table bit_sht (
|
73
|
+
b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
|
74
|
+
sz integer, osz integer
|
75
|
+
);
|
76
|
+
create function bs(integer, integer) returns bit_sht as '
|
77
|
+
b0 = BitString.new(args[0], 8)
|
78
|
+
[b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
|
79
|
+
b0.size, b0.octet_size]
|
80
|
+
' language 'plruby';
|
81
|
+
select * from bs(12, 2);
|
82
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
83
|
+
----------+------+----------+----------+----------+----+----+-----
|
84
|
+
00001100 | 2 | 00110000 | 00000011 | 00001100 | 12 | 8 | 1
|
85
|
+
(1 row)
|
86
|
+
|
87
|
+
select * from bs(277, -3);
|
88
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
89
|
+
----------+------+----------+----------+----------+----+----+-----
|
90
|
+
00010101 | -3 | 00000010 | 10101000 | 00010101 | 21 | 8 | 1
|
91
|
+
(1 row)
|
92
|
+
|
93
|
+
create function ext(text, integer) returns integer as '
|
94
|
+
b0 = BitString.new(args[0])
|
95
|
+
b0[args[1]]
|
96
|
+
' language 'plruby';
|
97
|
+
select ext('011110', 0);
|
98
|
+
ext
|
99
|
+
-----
|
100
|
+
0
|
101
|
+
(1 row)
|
102
|
+
|
103
|
+
select ext('011110', -1);
|
104
|
+
ext
|
105
|
+
-----
|
106
|
+
0
|
107
|
+
(1 row)
|
108
|
+
|
109
|
+
select ext('011110', 1);
|
110
|
+
ext
|
111
|
+
-----
|
112
|
+
1
|
113
|
+
(1 row)
|
114
|
+
|
115
|
+
select ext('011110', 4);
|
116
|
+
ext
|
117
|
+
-----
|
118
|
+
1
|
119
|
+
(1 row)
|
120
|
+
|
121
|
+
create function ext2(text, integer, integer) returns bit varying(8) as '
|
122
|
+
b0 = BitString.new(args[0])
|
123
|
+
b0[args[1], args[2]]
|
124
|
+
' language 'plruby';
|
125
|
+
select ext2('0111101', 0, 2);
|
126
|
+
ext2
|
127
|
+
------
|
128
|
+
01
|
129
|
+
(1 row)
|
130
|
+
|
131
|
+
select ext2('0111101', -1, 3);
|
132
|
+
ext2
|
133
|
+
------
|
134
|
+
1
|
135
|
+
(1 row)
|
136
|
+
|
137
|
+
select ext2('0111101', 1, 2);
|
138
|
+
ext2
|
139
|
+
------
|
140
|
+
11
|
141
|
+
(1 row)
|
142
|
+
|
143
|
+
select ext2('0111101', 4, 1);
|
144
|
+
ext2
|
145
|
+
------
|
146
|
+
1
|
147
|
+
(1 row)
|
148
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
create table bit_op (
|
2
|
+
b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
|
3
|
+
bxor bit(8), bnot0 bit(8), bnot1 bit(8)
|
4
|
+
);
|
5
|
+
create function bt(integer, integer) returns bit_op as '
|
6
|
+
b0 = BitString.new(args[0], 8)
|
7
|
+
b1 = BitString.new(args[1], 8)
|
8
|
+
[b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
|
9
|
+
' language 'plruby';
|
10
|
+
select * from bt(12, 24);
|
11
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
12
|
+
----------+----------+----------+----------+----------+----------+----------
|
13
|
+
00001100 | 00011000 | 00001000 | 00011100 | 00010100 | 11110011 | 11100111
|
14
|
+
(1 row)
|
15
|
+
|
16
|
+
select * from bt(12, 32);
|
17
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
18
|
+
----------+----------+----------+----------+----------+----------+----------
|
19
|
+
00001100 | 00100000 | 00000000 | 00101100 | 00101100 | 11110011 | 11011111
|
20
|
+
(1 row)
|
21
|
+
|
22
|
+
select * from bt(15, 278);
|
23
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
24
|
+
----------+----------+----------+----------+----------+----------+----------
|
25
|
+
00001111 | 00010110 | 00000110 | 00011111 | 00011001 | 11110000 | 11101001
|
26
|
+
(1 row)
|
27
|
+
|
28
|
+
create function be(integer) returns setof integer as '
|
29
|
+
BitString.new(args[0], 8).each {|i| yield i}
|
30
|
+
' language 'plruby';
|
31
|
+
select * from be(12);
|
32
|
+
be
|
33
|
+
----
|
34
|
+
0
|
35
|
+
0
|
36
|
+
0
|
37
|
+
0
|
38
|
+
1
|
39
|
+
1
|
40
|
+
0
|
41
|
+
0
|
42
|
+
(8 rows)
|
43
|
+
|
44
|
+
select * from be(257);
|
45
|
+
be
|
46
|
+
----
|
47
|
+
0
|
48
|
+
0
|
49
|
+
0
|
50
|
+
0
|
51
|
+
0
|
52
|
+
0
|
53
|
+
0
|
54
|
+
1
|
55
|
+
(8 rows)
|
56
|
+
|
57
|
+
create function bx(integer, integer) returns bit varying as '
|
58
|
+
BitString.new(*args)
|
59
|
+
' language 'plruby';
|
60
|
+
select bx(12, 6);
|
61
|
+
bx
|
62
|
+
--------
|
63
|
+
001100
|
64
|
+
(1 row)
|
65
|
+
|
66
|
+
select bx(12, 8);
|
67
|
+
bx
|
68
|
+
----------
|
69
|
+
00001100
|
70
|
+
(1 row)
|
71
|
+
|
72
|
+
create table bit_sht (
|
73
|
+
b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
|
74
|
+
sz integer, osz integer
|
75
|
+
);
|
76
|
+
create function bs(integer, integer) returns bit_sht as '
|
77
|
+
b0 = BitString.new(args[0], 8)
|
78
|
+
[b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
|
79
|
+
b0.size, b0.octet_size]
|
80
|
+
' language 'plruby';
|
81
|
+
select * from bs(12, 2);
|
82
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
83
|
+
----------+------+----------+----------+----------+----+----+-----
|
84
|
+
00001100 | 2 | 00110000 | 00000011 | 00001100 | 12 | 8 | 1
|
85
|
+
(1 row)
|
86
|
+
|
87
|
+
select * from bs(277, -3);
|
88
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
89
|
+
----------+------+----------+----------+----------+----+----+-----
|
90
|
+
00010101 | -3 | 00000010 | 10101000 | 00010101 | 21 | 8 | 1
|
91
|
+
(1 row)
|
92
|
+
|
93
|
+
create function ext(text, integer) returns integer as '
|
94
|
+
b0 = BitString.new(args[0])
|
95
|
+
b0[args[1]]
|
96
|
+
' language 'plruby';
|
97
|
+
select ext('011110', 0);
|
98
|
+
ext
|
99
|
+
-----
|
100
|
+
0
|
101
|
+
(1 row)
|
102
|
+
|
103
|
+
select ext('011110', -1);
|
104
|
+
ext
|
105
|
+
-----
|
106
|
+
0
|
107
|
+
(1 row)
|
108
|
+
|
109
|
+
select ext('011110', 1);
|
110
|
+
ext
|
111
|
+
-----
|
112
|
+
1
|
113
|
+
(1 row)
|
114
|
+
|
115
|
+
select ext('011110', 4);
|
116
|
+
ext
|
117
|
+
-----
|
118
|
+
1
|
119
|
+
(1 row)
|
120
|
+
|
121
|
+
create function ext2(text, integer, integer) returns bit varying(8) as '
|
122
|
+
b0 = BitString.new(args[0])
|
123
|
+
b0[args[1], args[2]]
|
124
|
+
' language 'plruby';
|
125
|
+
select ext2('0111101', 0, 2);
|
126
|
+
ext2
|
127
|
+
------
|
128
|
+
01
|
129
|
+
(1 row)
|
130
|
+
|
131
|
+
select ext2('0111101', -1, 3);
|
132
|
+
ext2
|
133
|
+
------
|
134
|
+
1
|
135
|
+
(1 row)
|
136
|
+
|
137
|
+
select ext2('0111101', 1, 2);
|
138
|
+
ext2
|
139
|
+
------
|
140
|
+
11
|
141
|
+
(1 row)
|
142
|
+
|
143
|
+
select ext2('0111101', 4, 1);
|
144
|
+
ext2
|
145
|
+
------
|
146
|
+
1
|
147
|
+
(1 row)
|
148
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
create table bit_op (
|
2
|
+
b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
|
3
|
+
bxor bit(8), bnot0 bit(8), bnot1 bit(8)
|
4
|
+
);
|
5
|
+
create function bt(integer, integer) returns bit_op as '
|
6
|
+
b0 = BitString.new(args[0], 8)
|
7
|
+
b1 = BitString.new(args[1], 8)
|
8
|
+
[b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
|
9
|
+
' language 'plruby';
|
10
|
+
select * from bt(12, 24);
|
11
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
12
|
+
----------+----------+----------+----------+----------+----------+----------
|
13
|
+
00001100 | 00011000 | 00001000 | 00011100 | 00010100 | 11110011 | 11100111
|
14
|
+
(1 row)
|
15
|
+
|
16
|
+
select * from bt(12, 32);
|
17
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
18
|
+
----------+----------+----------+----------+----------+----------+----------
|
19
|
+
00001100 | 00100000 | 00000000 | 00101100 | 00101100 | 11110011 | 11011111
|
20
|
+
(1 row)
|
21
|
+
|
22
|
+
select * from bt(15, 278);
|
23
|
+
b0 | b1 | band | bor | bxor | bnot0 | bnot1
|
24
|
+
----------+----------+----------+----------+----------+----------+----------
|
25
|
+
00001111 | 00010110 | 00000110 | 00011111 | 00011001 | 11110000 | 11101001
|
26
|
+
(1 row)
|
27
|
+
|
28
|
+
create function be(integer) returns setof integer as '
|
29
|
+
BitString.new(args[0], 8).each {|i| yield i}
|
30
|
+
' language 'plruby';
|
31
|
+
select * from be(12);
|
32
|
+
be
|
33
|
+
----
|
34
|
+
0
|
35
|
+
0
|
36
|
+
0
|
37
|
+
0
|
38
|
+
1
|
39
|
+
1
|
40
|
+
0
|
41
|
+
0
|
42
|
+
(8 rows)
|
43
|
+
|
44
|
+
select * from be(257);
|
45
|
+
be
|
46
|
+
----
|
47
|
+
0
|
48
|
+
0
|
49
|
+
0
|
50
|
+
0
|
51
|
+
0
|
52
|
+
0
|
53
|
+
0
|
54
|
+
1
|
55
|
+
(8 rows)
|
56
|
+
|
57
|
+
create function bx(integer, integer) returns bit varying as '
|
58
|
+
BitString.new(*args)
|
59
|
+
' language 'plruby';
|
60
|
+
select bx(12, 6);
|
61
|
+
bx
|
62
|
+
--------
|
63
|
+
001100
|
64
|
+
(1 row)
|
65
|
+
|
66
|
+
select bx(12, 8);
|
67
|
+
bx
|
68
|
+
----------
|
69
|
+
00001100
|
70
|
+
(1 row)
|
71
|
+
|
72
|
+
create table bit_sht (
|
73
|
+
b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
|
74
|
+
sz integer, osz integer
|
75
|
+
);
|
76
|
+
create function bs(integer, integer) returns bit_sht as '
|
77
|
+
b0 = BitString.new(args[0], 8)
|
78
|
+
[b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
|
79
|
+
b0.size, b0.octet_size]
|
80
|
+
' language 'plruby';
|
81
|
+
select * from bs(12, 2);
|
82
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
83
|
+
----------+------+----------+----------+----------+----+----+-----
|
84
|
+
00001100 | 2 | 00110000 | 00000011 | 00001100 | 12 | 8 | 1
|
85
|
+
(1 row)
|
86
|
+
|
87
|
+
select * from bs(277, -3);
|
88
|
+
b0 | shft | bl | br | bs | bi | sz | osz
|
89
|
+
----------+------+----------+----------+----------+----+----+-----
|
90
|
+
00010101 | -3 | 00000010 | 10101000 | 00010101 | 21 | 8 | 1
|
91
|
+
(1 row)
|
92
|
+
|
93
|
+
create function ext(text, integer) returns integer as '
|
94
|
+
b0 = BitString.new(args[0])
|
95
|
+
b0[args[1]]
|
96
|
+
' language 'plruby';
|
97
|
+
select ext('011110', 0);
|
98
|
+
ext
|
99
|
+
-----
|
100
|
+
0
|
101
|
+
(1 row)
|
102
|
+
|
103
|
+
select ext('011110', -1);
|
104
|
+
ext
|
105
|
+
-----
|
106
|
+
0
|
107
|
+
(1 row)
|
108
|
+
|
109
|
+
select ext('011110', 1);
|
110
|
+
ext
|
111
|
+
-----
|
112
|
+
1
|
113
|
+
(1 row)
|
114
|
+
|
115
|
+
select ext('011110', 4);
|
116
|
+
ext
|
117
|
+
-----
|
118
|
+
1
|
119
|
+
(1 row)
|
120
|
+
|
121
|
+
create function ext2(text, integer, integer) returns bit varying(8) as '
|
122
|
+
b0 = BitString.new(args[0])
|
123
|
+
b0[args[1], args[2]]
|
124
|
+
' language 'plruby';
|
125
|
+
select ext2('0111101', 0, 2);
|
126
|
+
ext2
|
127
|
+
------
|
128
|
+
01
|
129
|
+
(1 row)
|
130
|
+
|
131
|
+
select ext2('0111101', -1, 3);
|
132
|
+
ext2
|
133
|
+
------
|
134
|
+
1
|
135
|
+
(1 row)
|
136
|
+
|
137
|
+
select ext2('0111101', 1, 2);
|
138
|
+
ext2
|
139
|
+
------
|
140
|
+
11
|
141
|
+
(1 row)
|
142
|
+
|
143
|
+
select ext2('0111101', 4, 1);
|
144
|
+
ext2
|
145
|
+
------
|
146
|
+
1
|
147
|
+
(1 row)
|
148
|
+
|