1 #region Copyright © 2001-2003 Jean-Claude Manoli [jc@manoli.net]
3 * Based on code submitted by Mitsugi Ogawa.
5 * This software is provided 'as-is', without any express or implied warranty.
6 * In no event will the author(s) be held liable for any damages arising from
7 * the use of this software.
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
18 * 2. Altered source versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source distribution.
28 using System
.Text
.RegularExpressions
;
30 namespace Manoli
.Utils
.CSharpFormat
33 /// Generates color-coded T-SQL source code.
35 public class TsqlFormat
: CodeFormat
38 /// Regular expression string to match single line
41 protected override string CommentRegEx
45 return @"(?:--\s).*?(?=\r|\n)";
50 /// Regular expression string to match string literals.
52 protected override string StringRegEx
61 /// Returns <b>false</b>, since T-SQL is not case sensitive.
63 public override bool CaseSensitive
70 /// The list of T-SQL keywords.
72 protected override string Keywords
76 return "absolute action ada add admin after aggregate "
77 + "alias all allocate alter and any are array as asc "
78 + "assertion at authorization avg backup before begin "
79 + "between binary bit bit_length blob boolean both breadth "
80 + "break browse bulk by call cascade cascaded case cast "
81 + "catalog char char_length character character_length "
82 + "check checkpoint class clob close clustered coalesce "
83 + "collate collation column commit completion compute "
84 + "connect connection constraint constraints constructor "
85 + "contains containstable continue convert corresponding "
86 + "count create cross cube current current_date current_path "
87 + "current_role current_time current_timestamp current_user "
88 + "cursor cycle data database date day dbcc deallocate dec "
89 + "decimal declare default deferrable deferred delete deny "
90 + "depth deref desc describe descriptor destroy destructor "
91 + "deterministic diagnostics dictionary disconnect disk "
92 + "distinct distributed domain double drop dummy dump "
93 + "dynamic each else end end-exec equals errlvl escape "
94 + "every except exception exec execute exists exit external "
95 + "extract false fetch file fillfactor first float for "
96 + "foreign fortran found free freetext freetexttable from "
97 + "full function general get global go goto grant group "
98 + "grouping having holdlock host hour identity identity_insert "
99 + "identitycol if ignore immediate in include index indicator "
100 + "initialize initially inner inout input insensitive insert "
101 + "int integer intersect interval into is isolation iterate "
102 + "join key kill language large last lateral leading left "
103 + "less level like limit lineno load local localtime localtimestamp "
104 + "locator lower map match max min minute modifies modify "
105 + "module month names national natural nchar nclob new next "
106 + "no nocheck nonclustered none not null nullif numeric object "
107 + "octet_length of off offsets old on only open opendatasource "
108 + "openquery openrowset openxml operation option or order "
109 + "ordinality out outer output over overlaps pad parameter "
110 + "parameters partial pascal path percent plan position "
111 + "postfix precision prefix preorder prepare preserve "
112 + "primary print prior privileges proc procedure "
113 + "public raiserror read reads readtext real reconfigure "
114 + "recursive ref references referencing relative replication "
115 + "restore restrict result return returns revoke right role "
116 + "rollback rollup routine row rowcount rowguidcol rows rule "
117 + "save savepoint schema scope scroll search second section "
118 + "select sequence session session_user set sets setuser "
119 + "shutdown size smallint some space specific specifictype "
120 + "sql sqlca sqlcode sqlerror sqlexception sqlstate sqlwarning "
121 + "start state statement static statistics structure substring "
122 + "sum system_user table temporary terminate textsize than then "
123 + "time timestamp timezone_hour timezone_minute to top trailing "
124 + "tran transaction translate translation treat trigger trim "
125 + "true truncate tsequal under union unique unknown unnest "
126 + "update updatetext upper usage use user using value values "
127 + "varchar variable varying view waitfor when whenever where "
128 + "while with without work write writetext year zone";
133 /// Use the pre-processor color to mark keywords that start with @@.
135 protected override string Preprocessors
139 return @"@@CONNECTIONS @@CPU_BUSY @@CURSOR_ROWS @@DATEFIRST "
140 + "@@DBTS @@ERROR @@FETCH_STATUS @@IDENTITY @@IDLE "
141 + "@@IO_BUSY @@LANGID @@LANGUAGE @@LOCK_TIMEOUT "
142 + "@@MAX_CONNECTIONS @@MAX_PRECISION @@NESTLEVEL @@OPTIONS "
143 + "@@PACK_RECEIVED @@PACK_SENT @@PACKET_ERRORS @@PROCID "
144 + "@@REMSERVER @@ROWCOUNT @@SERVERNAME @@SERVICENAME @@SPID "
145 + "@@TEXTSIZE @@TIMETICKS @@TOTAL_ERRORS @@TOTAL_READ "
146 + "@@TOTAL_WRITE @@TRANCOUNT @@VERSION";