tsql_parser 0.0.3 → 0.0.5

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: 261c5aa051e63968deb877640c812121e3898cccdd71a60aebed350f7cbc2cd2
4
- data.tar.gz: e15cae8c9e0616deafc9d0ccefd5e4414c2653e673722d1995d7b27c24ad114c
3
+ metadata.gz: 47f15eed54caa7c7f4c7525b27d302577ed8a07c3fce61b6af631ccc4bfbb3cc
4
+ data.tar.gz: 06ad8019af83fbb0679692eb0ef91b6ee0258cca4e1c79c924d034d0e537c7f7
5
5
  SHA512:
6
- metadata.gz: 508119aff4af84168665d355bbc154232a4a98d713728adcd18495435fdc39fdb8868cde5cbccb2e570fc7c587f92e295d137f04b3c765aa99945974723c516f
7
- data.tar.gz: 3888919f8554c94e596f567ac085ecde9316b32244781b30600a1c6d1a4d0bd47cc6e824bbbf110b084fe4ed392fdf552d2f587f9075938a1881bc2ea623a049
6
+ metadata.gz: 56978f16697970a06636ccb533f50bf0528199622724568eea071647dcba591c14baa6e05564846f876fc01d413a64f2fdcb2e3f3e2f5b81cdd7a6a2f5c11d76
7
+ data.tar.gz: 8c874fde5552f5e331d618b5e8ed427e8442cfbe513d3f43e59330c04298022637be9b821f7c6dce621368c9f2449b9ad878d28fc96f84ae17676a834cd3343a
@@ -65,29 +65,25 @@ module TSqlParser::Parsing
65
65
  sub_one = false
66
66
  work_lines = work_lines.flatten
67
67
  last = ""
68
+ in_if_exists = false
68
69
  work_lines.each_with_index do |line, index|
69
70
  first = line.strip.split(" ").first
71
+ next_line = work_lines[index + 1] unless index + 1 > work_lines.size
72
+ next_line_first = next_line.strip.split(" ").first unless next_line.nil?
70
73
 
71
74
  if %w[CASE BEGIN SELECT].include? first or line.strip.start_with? "CREATE PROCEDURE"
72
75
  indented_lines << "#{tab * tab_count}#{line}"
73
76
  tab_count += 1
74
- elsif %w[END GO FROM].include? first and last != "DELETE"
77
+ elsif %w[FROM END GO].include? first and not %w[DELETE UPDATE INSERT].include? last
75
78
  tab_count -= 1 if tab_count > 0
76
79
  indented_lines << "#{tab * tab_count}#{line}"
77
- elsif %w[IF].include? first
78
- indented_lines << "#{tab * tab_count}#{line}"
79
- next_line = work_lines[index + 1] unless index + 1 > work_lines.size
80
- sub_one = true unless next_line.start_with? "BEGIN"
81
- tab_count += 1 if sub_one
82
- last = first
83
- next
84
80
  else
85
81
  indented_lines << "#{tab * tab_count}#{line}"
86
82
  end
87
83
 
88
84
  if sub_one
89
85
  sub_one = false
90
- tab_count -= 1
86
+ tab_count -= 1 if tab_count > 0
91
87
  end
92
88
  last = first
93
89
  end
@@ -184,10 +184,8 @@ module TSqlParser::Parsing
184
184
  formatted = []
185
185
  parts = s.split(" SET ")
186
186
  table = parts[0]
187
- where_parts = parts[1].split(" WHERE ")
188
187
  formatted << "\n#{tab * (tab_count + 1)}#{table}"
189
- formatted << "#{tab * tab_count}SET #{where_parts[0]}"
190
- formatted << "#{tab * tab_count}WHERE #{where_parts[1]}" if where_parts.size > 0
188
+ formatted << "#{tab * tab_count}SET #{parts[1]}"
191
189
  formatted.join("\n")
192
190
  end
193
191
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsql_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-27 00:00:00.000000000 Z
11
+ date: 2023-03-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A very light-weight and opinionated T-SQL parser and formatter.
14
14
  email: scott@fuseraft.com