tsql_parser 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1f673c238a4d2ba62893cc40d1b9cba39ec670d89637dcbf414cc25d72ff796
4
- data.tar.gz: f08c8c2f290a5c66193ab8afa2c9e17095f801bb8d3793af09919e11f379c7e5
3
+ metadata.gz: 952e888020ea34386901d0476d96b7ae3520ec13bf4414e27bf65da4ca3d22e6
4
+ data.tar.gz: 5da27fe2eaa080678b73957c48af3702f504fa1126bec5668e501a443b6fed6b
5
5
  SHA512:
6
- metadata.gz: e71435ffd85aea0165c31b32f38c685daa3f2057dbb2b123628eb5b54b077836f679c5792580277997321da7514c5ffcb0f3c7a567a75d20a91de65609dae5d7
7
- data.tar.gz: c309fa288ffdeb797c7807293846fb641e49ae9c3cdc043cdedf9acd7823bb2d66c831d1212a38c17fb9c5961f6210213a696d3f694729d216e826ee82ff9d8e
6
+ metadata.gz: 22eb4777b4f9f716cb7e2bc158836e01fac84cbd007e1bc8be0e1bd8e6ca09c2ed1263af56d332f08ef806124e4681d23899a222178fcd441fa76865730ff755
7
+ data.tar.gz: 3e4c144c0b7e98c0bb909297cd0350e92a91762ff920a7801d3b6f451ec25b1f810b27cf2799619a68a7a55c55ea7efa84837faa916a242a878185b6371c4ead
@@ -23,8 +23,13 @@ module TSqlParser::Parsing::Formatters
23
23
  lines = text.split("\n")
24
24
  wait = false
25
25
  set_lines = []
26
+ special_set_keywords = %w[ANSI_DEFAULTS ANSI_NULL_DFLT_OFF ANSI_NULL_DFLT_ON ANSI_NULLS ANSI_PADDING ANSI_WARNINGS ARITHABORT ARITHIGNORE CONCAT_NULL_YIELDS_NULL CURSOR_CLOSE_ON_COMMIT DATEFIRST DATEFORMAT DEADLOCK_PRIORITY FIPS_FLAGGER FMTONLY FORCEPLAN IDENTITY_INSERT IMPLICIT_TRANSACTIONS LANGUAGE LOCK_TIMEOUT NOCOUNT NOEXEC NUMERIC_ROUNDABORT OFFSETS PARSEONLY QUERY_GOVERNOR_COST_LIMIT QUOTED_IDENTIFIER REMOTE_PROC_TRANSACTIONS ROWCOUNT SHOWPLAN_ALL SHOWPLAN_TEXT SHOWPLAN_XML STATISTICS TEXTSIZE TRANSACTION XACT_ABORT]
27
+
26
28
  lines.each do |line|
27
- first = line.strip.split(" ").first
29
+ tokens = line.strip.split(" ")
30
+ first = tokens.first
31
+ next_token = tokens[1] if tokens.size > 1
32
+
28
33
  if %w[FROM WHERE].include? first and wait
29
34
  wait = false
30
35
  tab_count = self.get_tab_count(line, tab)
@@ -42,9 +47,14 @@ module TSqlParser::Parsing::Formatters
42
47
  next
43
48
  end
44
49
 
45
- if first == "SET" and not line.strip.start_with? "SET @" and not %w[ON OFF].include? line.strip.split(" ").last
46
- wait = true
47
- set_lines << line
50
+ if first == "SET" and not line.strip.start_with? "SET @"
51
+ if not next_token.nil? and not special_set_keywords.include? next_token
52
+ wait = true
53
+ set_lines << line
54
+ else
55
+ formatted << line
56
+ formatted << ""
57
+ end
48
58
  elsif first != "SET" and line.include? " SET "
49
59
  parts = line.strip.split(" SET ")
50
60
  tab_count = self.get_tab_count(line, tab)
@@ -97,8 +107,8 @@ module TSqlParser::Parsing::Formatters
97
107
  builder = ""
98
108
  end
99
109
  elsif c == "\n"
100
- parts << builder unless builder.empty?
101
- builder = ""
110
+ #parts << builder unless builder.empty?
111
+ #builder = ""
102
112
  elsif c == "-"
103
113
  if next_c == "-"
104
114
  comment = true
@@ -114,7 +124,7 @@ module TSqlParser::Parsing::Formatters
114
124
  end
115
125
  parts << builder unless builder.empty?
116
126
  parts = parts.map { |p| p.strip }.select { |p| not p.empty? }
117
- "\n#{parts.map { |p| "#{tab * (tab_count + 1)}#{p.strip}" }.join(",\n")}"
127
+ "\n#{parts.map { |p| "#{tab * (tab_count + 1)}#{p.strip.gsub(tab, " ")}" }.join(",\n")}"
118
128
  end
119
129
  end
120
130
  end
@@ -94,7 +94,7 @@ module TSqlParser::Parsing
94
94
  next
95
95
  end
96
96
 
97
- if Parser.is_comment_start?(c, next_c)
97
+ if Parser.is_comment_start?(c, next_c) and not comment
98
98
  comment = true
99
99
  skip_count = 1
100
100
  specific_tokens << builder unless builder.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsql_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer