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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 736495bc6e9ad8785b755afb2b3a834cd0dff2e62983b0397e4d6fdf6f0fe3af
4
- data.tar.gz: 958489e0a1a542230ad57dc8748ef4a231e9c03cea1452c34246887e9789746f
3
+ metadata.gz: adbaaa6aae6c18867afc0b250fcd1cf24d521be698e318af2094e91c56cde27d
4
+ data.tar.gz: b12f902025d1b49e10c4844d2dfbdf920edb89b5a5512fb530a108b9fadc54d7
5
5
  SHA512:
6
- metadata.gz: ba81b385db041ea25c62a0777838d84ed89a165e489d6d4ef3f60ea908902acad3ba2a186e3eb7325a7520f407eead2ae3e6121fd8f4429664a3a9f00a848b01
7
- data.tar.gz: e076e78ce56f6e8e7ed238f7fa354dfe9799b2707520394e5635162f8029359c581bf5d055b53efd0c0739b58410c59ee5cb9e94c08b7dd600ecf64f478fb7d4
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
- '"' + @schema + '"."' + normalize(@name) + '"' + @array
73
+ if @schema.nil? || @schema == "" || @schema == "pg_catalog"
74
+ readable(normalize(@name)) + @array
75
75
  else
76
- '"' + normalize(@name) + '"' + @array
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 type.name == "record" and type.schema == "pg_catalog" and arg_modes.include?("t")
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
- varDeclarationMisc / varDeclarationCursor
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'
@@ -2,9 +2,9 @@ module Piggly
2
2
  module VERSION
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
- RELEASE_DATE = "2026-05-21"
7
+ RELEASE_DATE = "2026-06-01"
8
8
  end
9
9
 
10
10
  class << VERSION
@@ -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
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module Piggly
4
4
 
@@ -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.5
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