piggly-nsd 2.3.5 → 2.3.6
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 +4 -4
- data/lib/piggly/dumper/qualified_type.rb +3 -3
- data/lib/piggly/dumper/reified_procedure.rb +1 -1
- data/lib/piggly/parser/grammar.tt +7 -6
- data/lib/piggly/version.rb +2 -2
- data/spec/examples/dumper/definition_spec.rb +49 -0
- data/spec/examples/dumper/procedure_spec.rb +1 -1
- data/spec/examples/grammar/statements/declaration_spec.rb +12 -0
- data/spec/examples/grammar/statements/if_spec.rb +6 -0
- data/spec/examples/grammar/statements/sql_spec.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: adbaaa6aae6c18867afc0b250fcd1cf24d521be698e318af2094e91c56cde27d
|
|
4
|
+
data.tar.gz: b12f902025d1b49e10c4844d2dfbdf920edb89b5a5512fb530a108b9fadc54d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 464088a04d5cfce256c45bfd69ba44112cd0fe5faa8de6736cae795205915a9c1e885112cf24d4883f3329d6688f64f9fdd00e92ee240dada167a07a7da1b2a0
|
|
7
|
+
data.tar.gz: b686c522d0f8cb75548b6765a9ed5aaf0f57aab0298691e4ee017987468ca3a6a2d37c95742620e661d5421a33f2211dd24ef9948a75ddecac2be07879f172ee
|
|
@@ -70,10 +70,10 @@ module Piggly
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def quote
|
|
73
|
-
if @schema
|
|
74
|
-
|
|
73
|
+
if @schema.nil? || @schema == "" || @schema == "pg_catalog"
|
|
74
|
+
readable(normalize(@name)) + @array
|
|
75
75
|
else
|
|
76
|
-
'"' +
|
|
76
|
+
'"' + @schema + '"."' + @name + '"' + @array
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -11,7 +11,7 @@ module Piggly
|
|
|
11
11
|
# Ensure source is UTF-8 encoded
|
|
12
12
|
@source = source.to_s.force_encoding('UTF-8').strip
|
|
13
13
|
|
|
14
|
-
if
|
|
14
|
+
if arg_modes.include?("t")
|
|
15
15
|
prefix = arg_modes.take_while{|m| m != "t" }.length
|
|
16
16
|
type = RecordType.new(arg_types[prefix..-1], arg_names[prefix..-1], arg_modes[prefix..-1], arg_defaults[prefix..-1])
|
|
17
17
|
arg_modes = arg_modes[0, prefix]
|
|
@@ -271,7 +271,7 @@ grammar PigglyParser
|
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
rule varDeclaration
|
|
274
|
-
|
|
274
|
+
varDeclarationCursor / varDeclarationMisc
|
|
275
275
|
end
|
|
276
276
|
|
|
277
277
|
rule varDeclarationMisc
|
|
@@ -284,7 +284,7 @@ grammar PigglyParser
|
|
|
284
284
|
end
|
|
285
285
|
|
|
286
286
|
rule varDeclarationCursor
|
|
287
|
-
name:tIdentifier tSpace ( ( kwNO tSpace )? kwSCROLL tSpace )? kwCURSOR tSpace
|
|
287
|
+
name:tIdentifier tSpace ( ( kwNO tSpace )? kwSCROLL tSpace )? kwCURSOR tSpace?
|
|
288
288
|
rval:expressionUntilSemiColon
|
|
289
289
|
tSpace?
|
|
290
290
|
';' tSpace?
|
|
@@ -346,17 +346,17 @@ grammar PigglyParser
|
|
|
346
346
|
|
|
347
347
|
rule expressionUntilThen
|
|
348
348
|
head:tSpace? expr:( sqlCaseExpression / tString / skipWords / tSpace !kwTHEN / !tSpace !kwTHEN . )+
|
|
349
|
-
tail:tSpace &kwTHEN <Piggly::Parser::Nodes::Expression>
|
|
349
|
+
tail:tSpace? &kwTHEN <Piggly::Parser::Nodes::Expression>
|
|
350
350
|
end
|
|
351
351
|
|
|
352
352
|
rule expressionUntilWhen
|
|
353
353
|
head:tSpace? expr:( sqlCaseExpression / tString / skipWords / tSpace !kwWHEN / !tSpace !kwWHEN . )+
|
|
354
|
-
tail:tSpace &kwWHEN <Piggly::Parser::Nodes::Expression>
|
|
354
|
+
tail:tSpace? &kwWHEN <Piggly::Parser::Nodes::Expression>
|
|
355
355
|
end
|
|
356
356
|
|
|
357
357
|
rule expressionUntilLoop
|
|
358
358
|
head:tSpace? expr:( sqlCaseExpression / tString / skipWords / tSpace !kwLOOP / !tSpace !kwLOOP . )+
|
|
359
|
-
tail:tSpace &kwLOOP <Piggly::Parser::Nodes::Expression>
|
|
359
|
+
tail:tSpace? &kwLOOP <Piggly::Parser::Nodes::Expression>
|
|
360
360
|
end
|
|
361
361
|
|
|
362
362
|
rule sqlCaseExpression
|
|
@@ -366,7 +366,7 @@ grammar PigglyParser
|
|
|
366
366
|
end
|
|
367
367
|
|
|
368
368
|
rule skipWords
|
|
369
|
-
[a-z0-9_]+ <Piggly::Parser::Nodes::TextNode>
|
|
369
|
+
!keyword [a-z0-9_]+ ![a-z0-9_] <Piggly::Parser::Nodes::TextNode>
|
|
370
370
|
end
|
|
371
371
|
|
|
372
372
|
#############################################################################
|
|
@@ -495,6 +495,7 @@ grammar PigglyParser
|
|
|
495
495
|
/ 'create'
|
|
496
496
|
/ 'drop'
|
|
497
497
|
/ 'alter'
|
|
498
|
+
/ 'analyze'
|
|
498
499
|
/ 'commit'
|
|
499
500
|
/ 'rollback'
|
|
500
501
|
/ 'copy'
|
data/lib/piggly/version.rb
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Piggly
|
|
4
|
+
module Dumper
|
|
5
|
+
|
|
6
|
+
describe SkeletonProcedure, "definition" do
|
|
7
|
+
def qname(schema, name)
|
|
8
|
+
QualifiedName.new(schema, name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def qtype(*args)
|
|
12
|
+
QualifiedType.parse(*args)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "quotes user-defined types but not built-in types" do
|
|
16
|
+
expect(qtype("character varying").quote).to eq("varchar")
|
|
17
|
+
expect(qtype("pg_catalog", "varchar").quote).to eq("varchar")
|
|
18
|
+
expect(qtype("bigint").quote).to eq("bigint")
|
|
19
|
+
expect(qtype("private", "mytype").quote).to eq('"private"."mytype"')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "generates valid SQL for functions with table return columns" do
|
|
23
|
+
procedure = ReifiedProcedure.new(
|
|
24
|
+
"begin end;",
|
|
25
|
+
1,
|
|
26
|
+
qname("public", "f_test_function"),
|
|
27
|
+
false,
|
|
28
|
+
false,
|
|
29
|
+
true,
|
|
30
|
+
qtype("pg_catalog", "varchar"),
|
|
31
|
+
"volatile",
|
|
32
|
+
%w[in in in t],
|
|
33
|
+
%w[p_payment_session_id p_payment_type_start p_payment_type_end type_mnemo].map { |n| qname(nil, n) },
|
|
34
|
+
["bigint", "character varying", "character varying", "character varying"].map { |t| qtype(t) },
|
|
35
|
+
[nil, nil, nil, nil]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
sql = procedure.definition("begin end;")
|
|
39
|
+
|
|
40
|
+
expect(sql).to include('in "p_payment_session_id" bigint')
|
|
41
|
+
expect(sql).to include('in "p_payment_type_start" varchar')
|
|
42
|
+
expect(sql).to include('returns table ("type_mnemo" varchar)')
|
|
43
|
+
expect(sql).not_to include('t "type_mnemo"')
|
|
44
|
+
expect(sql).not_to include('"varchar"')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -15,6 +15,18 @@ module Piggly
|
|
|
15
15
|
it "allows an initial assignment" do
|
|
16
16
|
node = parse(:stmtDeclare, "declare a text := 10;")
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
it "parses parameterized cursor declarations" do
|
|
20
|
+
parse(:stmtDeclare, <<~SQL)
|
|
21
|
+
declare
|
|
22
|
+
c_lic_acc_value cursor(c_lic_acc_id bigint, c_date_old timestamp) for
|
|
23
|
+
select date_v, beg_val from public.t_table_value where link_lic_acc = c_lic_acc_id;
|
|
24
|
+
SQL
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "parses cursor declarations without space before parameter list" do
|
|
28
|
+
parse(:stmtDeclare, "declare c cursor(x int) for select 1;")
|
|
29
|
+
end
|
|
18
30
|
end
|
|
19
31
|
|
|
20
32
|
end
|
|
@@ -62,6 +62,12 @@ module Piggly
|
|
|
62
62
|
node.should be_statement
|
|
63
63
|
node.count{|e| e.comment? }.should == 3
|
|
64
64
|
end
|
|
65
|
+
|
|
66
|
+
it "allows then immediately after closing parenthesis" do
|
|
67
|
+
node, rest = parse_some(:statement, 'IF exists(select 1)then null; end if;')
|
|
68
|
+
node.should be_statement
|
|
69
|
+
rest.should == ''
|
|
70
|
+
end
|
|
65
71
|
end
|
|
66
72
|
|
|
67
73
|
describe "if .. then .. else .. end if" do
|
|
@@ -13,6 +13,14 @@ module Piggly
|
|
|
13
13
|
rest.should == ''
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
it "parses ANALYZE statements" do
|
|
17
|
+
node, rest = parse_some(:statement, 'ANALYZE tt_test;')
|
|
18
|
+
node.should be_statement
|
|
19
|
+
node.count{|e| e.sql? }.should == 1
|
|
20
|
+
node.find{|e| e.sql? }.source_text.should == 'ANALYZE tt_test;'
|
|
21
|
+
rest.should == ''
|
|
22
|
+
end
|
|
23
|
+
|
|
16
24
|
it "parses MERGE statements" do
|
|
17
25
|
node, rest = parse_some(:statement, <<-SQL.strip)
|
|
18
26
|
MERGE INTO users u
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: piggly-nsd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kvle Putnam
|
|
@@ -111,6 +111,7 @@ files:
|
|
|
111
111
|
- spec/examples/compiler/report_spec.rb
|
|
112
112
|
- spec/examples/compiler/trace_spec.rb
|
|
113
113
|
- spec/examples/config_spec.rb
|
|
114
|
+
- spec/examples/dumper/definition_spec.rb
|
|
114
115
|
- spec/examples/dumper/index_spec.rb
|
|
115
116
|
- spec/examples/dumper/procedure_spec.rb
|
|
116
117
|
- spec/examples/grammar/expression_spec.rb
|