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 +4 -4
- data/lib/parsing/formatters/strategy/set_formatter.rb +17 -7
- data/lib/parsing/tokenizer.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952e888020ea34386901d0476d96b7ae3520ec13bf4414e27bf65da4ca3d22e6
|
4
|
+
data.tar.gz: 5da27fe2eaa080678b73957c48af3702f504fa1126bec5668e501a443b6fed6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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 @"
|
46
|
-
|
47
|
-
|
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
|
data/lib/parsing/tokenizer.rb
CHANGED