2
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22
#include "mysql_sql_editor_be.h"
24
#include "../../../images/ui/editor_statement.xpm"
25
#include "../../../images/ui/editor_error.xpm"
31
Mysql_sql_editor::Mysql_sql_editor(db_mgmt_RdbmsRef rdbms)
38
Mysql_sql_editor::~Mysql_sql_editor()
43
const char *Mysql_sql_editor::get_keywords(KeywordList list) const
45
const static char general_keywords[] =
46
"accessible add all alter analyze and as asc asensitive "
47
"before between bigint binary blob both by "
48
"call cascade case change char character check collate column condition connection constraint "
49
"continue convert create cross current_date current_time current_timestamp current_user cursor "
50
"database databases day_hour day_microsecond day_minute day_second dec decimal declare default "
51
"delayed delete desc describe deterministic distinct distinctrow div double drop dual "
52
"each else elseif enclosed escaped exists exit explain "
53
"false fetch float float4 float8 for force foreign from fulltext "
55
"having high_priority hour_microsecond hour_minute hour_second "
56
"if ignore in index infile inner inout insensitive insert int int1 int2 int3 int4 int8 integer "
57
"interval into is iterate "
60
"label leading leave left like limit linear lines load localtime localtimestamp lock long "
61
"longblob longtext loop low_priority "
62
"master_ssl_verify_server_cert match mediumblob mediumint mediumtext middleint minute_microsecond "
63
"minute_second mod modifies "
64
"natural not no_write_to_binlog null numeric "
65
"on optimize option optionally or order out outer outfile "
66
"precision primary procedure purge "
67
"range read reads read_only read_write real references regexp release rename repeat replace "
68
"require restrict return revoke right rlike "
69
"schema schemas second_microsecond select sensitive separator set show smallint spatial specific "
70
"sql sqlexception sqlstate sqlwarning sql_big_result sql_calc_found_rows sql_small_result ssl "
71
"starting straight_join "
72
"table terminated then tinyblob tinyint tinytext to trailing trigger true "
73
"undo union unique unlock unsigned until update upgrade usage use using utc_date utc_time utc_timestamp "
74
"values varbinary varchar varcharacter varying "
75
"when where while with write "
80
const static char procedure_keywords[] = // Not reserved words but intrinsic part of procedure definitions.
83
const static char client_keywords[] = // Definition of keywords only used by clients, not the server itself.
86
const static char user_keywords[] = // Definition of own keywords, not used by MySQL.
91
case Procedure_Keywords:
92
return procedure_keywords;
94
return client_keywords;
98
return general_keywords;
102
const char *Mysql_sql_editor::get_function_names() const
104
const static char function_names[] =
105
"abs acos adddate aes_encrypt aes_decrypt ascii asin atan atan2 benchmark bin bit_count bit_or "
106
"bit_and cast ceil ceiling current_user bit_length char_length character_length coalesce "
107
"concat concat_ws connection_id conv convert count cos cot curdate curtime date_add date_format "
108
"date_sub dayname dayofmonth dayofweek dayofyear decode degrees des_encrypt des_decrypt elt "
109
"encode encrypt extract exp export_set field find_in_set floor format found_rows from_days "
110
"from_unixtime get_lock greatest group_concat group_unique_users hex ifnull inet_aton inet_ntoa "
111
"instr isnull is_free_lock last_insert_id lcase least length ln load_file locate log log2 log10 "
112
"lower lpad ltrim make_set master_pos_wait max md5 mid min mod monthname now nullif octet_length "
113
"oct old_password ord period_add period_diff pi position pow power quarter quote radians rand "
114
"release_lock repeat reverse round rpad rtrim sec_to_time session_user subdate sign sin sha "
115
"sha1 soundex space sqrt std stddev strcmp substring substring_index sum sysdate system_user "
116
"tan time_format time_to_sec to_days trim ucase unique_users unix_timestamp upper user version "
117
"week weekday yearweek";
119
return function_names;
123
#include <Scintilla.h>
124
#include <SciLexer.h>
125
void Mysql_sql_editor::setup_scintilla_editor(boost::function<long (int, long, long)> send_editor)
127
// Lexer type is MySQL.
128
send_editor(SCI_SETLEXER, SCLEX_MYSQL, 0);
130
// Number of styles we use with this lexer.
131
send_editor(SCI_SETSTYLEBITS, send_editor(SCI_GETSTYLEBITSNEEDED, 0, 0), 0);
132
// Keywords to highlight. Indices are:
133
// 0 - Major keywords (reserved keywords)
134
// 1 - Normal keywords (everything not reserved but integral part of the language)
135
// 2 - Database objects
136
// 3 - Function keywords
137
// 4 - System variable keywords
138
// 5 - Procedure keywords (keywords used in procedures like "begin" and "end")
139
// 6..8 - User keywords 1..3
140
send_editor(SCI_SETKEYWORDS, 0, (long)get_keywords(Sql_editor::General_Keywords));
141
send_editor(SCI_SETKEYWORDS, 3, (long)get_function_names());
142
send_editor(SCI_SETKEYWORDS, 5, (long)get_keywords(Sql_editor::Procedure_Keywords));
143
send_editor(SCI_SETKEYWORDS, 6, (long)get_keywords(Sql_editor::Client_Keywords));
144
send_editor(SCI_SETKEYWORDS, 7, (long)get_keywords(Sql_editor::User_Keywords));
146
// [editor setStringProperty: SCI_STYLESETFONT, STYLE_DEFAULT value: @"Monospac821 BT"); // Very pleasing programmer's font.
147
#if defined(__APPLE__) || defined(_WIN32)
148
send_editor(SCI_STYLESETSIZE, STYLE_DEFAULT, 14);
150
send_editor(SCI_STYLESETSIZE, STYLE_DEFAULT, 9);
152
// send_editor(SCI_STYLESETFORE, STYLE_DEFAULT, 0x000000);
154
send_editor(SCI_STYLESETFORE, SCE_MYSQL_DEFAULT, 0x000000);
155
send_editor(SCI_STYLESETFORE, SCE_MYSQL_COMMENT, 0x909090);
156
send_editor(SCI_STYLESETFORE, SCE_MYSQL_COMMENTLINE, 0x909090);
157
send_editor(SCI_STYLESETFORE, SCE_MYSQL_HIDDENCOMMAND, 0x097BF7);
158
send_editor(SCI_STYLESETBACK, SCE_MYSQL_HIDDENCOMMAND, 0xF0F0F0);
160
send_editor(SCI_STYLESETFORE, SCE_MYSQL_VARIABLE, 0x378EA5);
161
send_editor(SCI_STYLESETFORE, SCE_MYSQL_SYSTEMVARIABLE, 0x378EA5);
162
send_editor(SCI_STYLESETFORE, SCE_MYSQL_KNOWNSYSTEMVARIABLE, 0x3A37A5);
164
send_editor(SCI_STYLESETFORE, SCE_MYSQL_NUMBER, 0x30A0F0); //0xBF7F00);
165
send_editor(SCI_STYLESETFORE, SCE_MYSQL_SQSTRING, 0x209F20); //0xFFAA3E);
167
// Note: if we were using ANSI quotes we would set the DQSTRING to the same color as the
168
// the back tick string.
169
send_editor(SCI_STYLESETFORE, SCE_MYSQL_DQSTRING, 0x274A6D);
171
// Keyword highlighting.
172
send_editor(SCI_STYLESETFORE, SCE_MYSQL_MAJORKEYWORD, 0xBF7F00); //0x209F20);
173
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_MAJORKEYWORD, 1);
174
send_editor(SCI_STYLESETFORE, SCE_MYSQL_KEYWORD, 0xBF7F00); //0x209F20);
175
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_KEYWORD, 1);
176
send_editor(SCI_STYLESETFORE, SCE_MYSQL_PROCEDUREKEYWORD, 0x0040C0); // 0x56007F);
177
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_PROCEDUREKEYWORD, 1);
178
send_editor(SCI_STYLESETFORE, SCE_MYSQL_USER1, 0x007F00);
179
send_editor(SCI_STYLESETFORE, SCE_MYSQL_USER2, 0x007F00);
181
send_editor(SCI_STYLESETFORE, SCE_MYSQL_FUNCTION, 0xC040C0);
182
send_editor(SCI_STYLESETFORE, SCE_MYSQL_DATABASEOBJECT, 0xff0000);
184
send_editor(SCI_STYLESETFORE, SCE_MYSQL_IDENTIFIER, 0x000000);
185
send_editor(SCI_STYLESETFORE, SCE_MYSQL_QUOTEDIDENTIFIER, 0x275A7D);
186
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_OPERATOR, 1);
188
// Second set of highlighter states for tokens in a conditional (hidden) command.
189
send_editor(SCI_STYLESETFORE, SCE_MYSQL_COMMENT + 0x40, 0x909090);
190
send_editor(SCI_STYLESETBACK, SCE_MYSQL_COMMENT + 0x40, 0xF0F0F0);
191
send_editor(SCI_STYLESETFORE, SCE_MYSQL_COMMENTLINE + 0x40, 0x909090);
192
send_editor(SCI_STYLESETBACK, SCE_MYSQL_COMMENTLINE + 0x40, 0xF0F0F0);
194
send_editor(SCI_STYLESETFORE, SCE_MYSQL_VARIABLE + 0x40, 0x378EA5);
195
send_editor(SCI_STYLESETBACK, SCE_MYSQL_VARIABLE + 0x40, 0xF0F0F0);
196
send_editor(SCI_STYLESETFORE, SCE_MYSQL_SYSTEMVARIABLE + 0x40, 0x378EA5);
197
send_editor(SCI_STYLESETBACK, SCE_MYSQL_SYSTEMVARIABLE + 0x40, 0xF0F0F0);
198
send_editor(SCI_STYLESETFORE, SCE_MYSQL_KNOWNSYSTEMVARIABLE + 0x40, 0x3A37A5);
199
send_editor(SCI_STYLESETBACK, SCE_MYSQL_KNOWNSYSTEMVARIABLE + 0x40, 0xF0F0F0);
201
send_editor(SCI_STYLESETFORE, SCE_MYSQL_NUMBER + 0x40, 0x30A0F0); //0xBF7F00);
202
send_editor(SCI_STYLESETBACK, SCE_MYSQL_NUMBER + 0x40, 0xF0F0F0);
203
send_editor(SCI_STYLESETFORE, SCE_MYSQL_SQSTRING + 0x40, 0x209F20); //0xFFAA3E);
204
send_editor(SCI_STYLESETBACK, SCE_MYSQL_SQSTRING + 0x40, 0xF0F0F0);
205
send_editor(SCI_STYLESETFORE, SCE_MYSQL_DQSTRING + 0x40, 0x274A6D);
206
send_editor(SCI_STYLESETBACK, SCE_MYSQL_DQSTRING + 0x40, 0xF0F0F0);
208
send_editor(SCI_STYLESETFORE, SCE_MYSQL_MAJORKEYWORD + 0x40, 0xBF7F00);
209
send_editor(SCI_STYLESETBACK, SCE_MYSQL_MAJORKEYWORD + 0x40, 0xF0F0F0);
210
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_MAJORKEYWORD + 0x40, 1);
211
send_editor(SCI_STYLESETFORE, SCE_MYSQL_KEYWORD + 0x40, 0xBF7F00); //0x209F20);
212
send_editor(SCI_STYLESETBACK, SCE_MYSQL_KEYWORD + 0x40, 0xF0F0F0);
213
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_KEYWORD + 0x40, 1);
214
send_editor(SCI_STYLESETFORE, SCE_MYSQL_PROCEDUREKEYWORD + 0x40, 0x0040C0); // 0x56007F);
215
send_editor(SCI_STYLESETBACK, SCE_MYSQL_PROCEDUREKEYWORD + 0x40, 0xF0F0F0);
216
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_PROCEDUREKEYWORD + 0x40, 1);
217
send_editor(SCI_STYLESETFORE, SCE_MYSQL_USER1 + 0x40, 0x007F00);
218
send_editor(SCI_STYLESETBACK, SCE_MYSQL_USER1 + 0x40, 0xF0F0F0);
219
send_editor(SCI_STYLESETFORE, SCE_MYSQL_USER2 + 0x402, 0x007F00);
220
send_editor(SCI_STYLESETBACK, SCE_MYSQL_USER2 + 0x40, 0xF0F0F0);
222
send_editor(SCI_STYLESETFORE, SCE_MYSQL_FUNCTION + 0x40, 0xC040C0);
223
send_editor(SCI_STYLESETBACK, SCE_MYSQL_FUNCTION + 0x40, 0xF0F0F0);
224
send_editor(SCI_STYLESETFORE, SCE_MYSQL_DATABASEOBJECT + 0x40, 0xff0000);
225
send_editor(SCI_STYLESETBACK, SCE_MYSQL_DATABASEOBJECT + 0x40, 0xF0F0F0);
227
send_editor(SCI_STYLESETFORE, SCE_MYSQL_IDENTIFIER + 0x40, 0x000000);
228
send_editor(SCI_STYLESETBACK, SCE_MYSQL_IDENTIFIER + 0x40, 0xF0F0F0);
229
send_editor(SCI_STYLESETFORE, SCE_MYSQL_QUOTEDIDENTIFIER + 0x40, 0x275A7D);
230
send_editor(SCI_STYLESETBACK, SCE_MYSQL_QUOTEDIDENTIFIER + 0x40, 0xF0F0F0);
231
send_editor(SCI_STYLESETBACK, SCE_MYSQL_OPERATOR + 0x40, 0xF0F0F0);
232
send_editor(SCI_STYLESETBOLD, SCE_MYSQL_OPERATOR + 0x40, 1);
234
// Margin: Line number style.
235
send_editor(SCI_STYLESETFORE, STYLE_LINENUMBER, 0x404040);
236
send_editor(SCI_STYLESETBACK, STYLE_LINENUMBER, 0xE0E0E0);
238
send_editor(SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER);
239
int lineNumberStyleWidth = send_editor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (long)"_99999");
240
send_editor(SCI_SETMARGINWIDTHN, 0, lineNumberStyleWidth);
243
send_editor(SCI_SETMARGINWIDTHN, 1, 16);
245
// Some special lexer properties.
246
send_editor(SCI_SETPROPERTY, (long)"fold", (long)"1");
247
send_editor(SCI_SETPROPERTY, (long)"fold.compact", (long)"0");
248
send_editor(SCI_SETPROPERTY, (long)"fold.comment", (long)"1");
251
send_editor(SCI_SETMARGINWIDTHN, 2, 16);
252
send_editor(SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS);
253
send_editor(SCI_SETMARGINSENSITIVEN, 2, 1);
254
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
255
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
256
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
257
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER);
258
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED);
259
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED);
260
send_editor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER);
261
for (int n= 25; n < 32; ++n) // Markers 25..31 are reserved for folding.
263
send_editor(SCI_MARKERSETFORE, n, 0xffffff);
264
send_editor(SCI_MARKERSETBACK, n, 0x404040);
267
// Init markers & indicators for highlighting of syntax errors.
268
send_editor(SCI_INDICSETFORE, 0, 0xD01921);
269
send_editor(SCI_INDICSETUNDER, 0, 1);
270
send_editor(SCI_INDICSETSTYLE, 0, INDIC_SQUIGGLE);
272
// Gutter markers for errors and statments.
273
send_editor(SCI_MARKERDEFINEPIXMAP, 0, (long)editor_statement);
274
send_editor(SCI_MARKERSETBACK, 0, 0xD01921);
276
send_editor(SCI_MARKERDEFINEPIXMAP, 1, (long)editor_error);
277
send_editor(SCI_MARKERSETBACK, 1, 0xD01921);
280
// - Set up the normal selection background color.
281
//Platform Specific: send_editor(SCI_SETSELBACK, 1 value: [NSColor selectedTextBackgroundColor)];
283
// - Tabulators + indentation
284
send_editor(SCI_SETTABWIDTH, 4, 0);
285
send_editor(SCI_SETUSETABS, 0, 0);
286
send_editor(SCI_SETINDENT, 4, 0);
287
send_editor(SCI_SETTABINDENTS, 1, 0);