Hi,
I use CodeMirror in a website where you have a SQL editor where you can type and run SQL queries in, and dynamically switch from SQL syntax (MSSQL/MySQL/Oracle/Access) by pressing a button. I have created extra MIME types for each SQL syntax like this in […]/mode/sql/sql.js :
CodeMirror.defineMIME(“text/x-ELO-mssql”, {
name: “sql”,
client: set(“”),
keywords: set(sqlKeywords + “ABS ASCII AVG … YEAR”),
builtin: set(“”),
atoms: set(“false true null”),
operatorChars: /[1]/,
dateSQL: set(“date datetimeoffset datetime2 smalldatetime datetime time”),
support: set(“ODBCdotTable”),
hooks: { }
});
If I type “select count(price) from plant” the SQL keywords are drawn in a purple color. These words get a cm-keyword CSS style applied. This works for all standard sqlKeywords defined in sql.js. :
var sqlKeywords = "alter and as asc between by count create delete desc distinct drop from group having in insert into is join like not on or order select set table union update values where limit ";
But the extra SQL keywords defined in the MIME for example avg doesn’t get this style applied (color stays the same), I also checked this with Firebug.
In your SQL mode demo at CodeMirror: SQL Mode for CodeMirror it does work for both standard keywords and extra defined SQL keywords. But your method of switching mode is different. You reload the complete page and set the mode when instantiating the editor. I use the following method:
var curmode=editor.getOption("mode"); //get current database type if (curmode.indexOf(dbType)==-1) { //is database type changed? var mode="text/x-ELO-"+dbType; console.log("Changing mode from "+curmode+" to "+mode); editor.setOption("mode",mode); }
How do I get the same behaviour like standard SQL keywords for the extra own defined SQL keywords in the MIME?
*+-%<>!= ↩︎