text: (function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../../lib/codemirror"),require("../../mode/sql/sql"))}else{if(typeof define=="function"&&define.amd){define(["../../lib/codemirror","../../mode/sql/sql"],a)}else{a(CodeMirror)}}})(function(n){var f;var p;var h;var i={QUERY_DIV:";",ALIAS_KEYWORD:"AS"};var m=n.Pos;function b(t){var u=t.doc.modeOption;if(u==="sql"){u="text/x-sql"}return n.resolveMode(u).keywords}function a(t){return typeof t=="string"?t:t.text}function g(v,u){if(!v.slice){return v[u]}for(var t=v.length-1;t>=0;t--){if(a(v[t])==u){return v[t]}}}function e(u){var t={};for(var v in u){if(u.hasOwnProperty(v)){t[v]=u[v]}}return t}function c(u,w){var t=u.length;var v=a(w).substr(0,t);return u.toUpperCase()===v.toUpperCase()}function d(t,v,w,u){for(var x in w){if(!w.hasOwnProperty(x)){continue}if(w.slice){x=w[x]}if(c(v,x)){t.push(u(x))}}}function j(t){if(t.charAt(0)=="."){t=t.substr(1)}return t.replace(/`/g,"")}function o(u){var t=a(u).split(".");for(var v=0;v<t.length;v++){t[v]="`"+t[v]+"`"}var w=t.join(".");if(typeof u=="string"){return w}u=e(u);u.text=w;return u}function r(A,v,C,y){var z=false;var w=[];var t=v.start;var D=true;while(D){D=(v.string.charAt(0)==".");z=z||(v.string.charAt(0)=="`");t=v.start;w.unshift(j(v.string));v=y.getTokenAt(m(A.line,v.start));if(v.string=="."){D=true;v=y.getTokenAt(m(A.line,v.start))}}var x=w.join(".");d(C,x,f,function(E){return z?o(E):E});d(C,x,p,function(E){return z?o(E):E});x=w.pop();var B=w.join(".");if(!g(f,B)){B=k(B,y)}var u=g(f,B);if(u&&u.columns){u=u.columns}if(u){d(C,x,u,function(E){if(typeof E=="string"){E=B+"."+E}else{E=e(E);E.text=B+"."+E.text}return z?o(E):E})}return t}function s(u,w){if(!u){return}var t=/[,;]/g;var x=u.split(" ");for(var v=0;v<x.length;v++){w(x[v]?x[v].replace(t,""):"")}}function q(t){return t.line+t.ch/Math.pow(10,6)}function l(t){return m(Math.floor(t),+t.toString().split(".").pop())}function k(y,z){var H=z.doc;var u=H.getValue();var t=y.toUpperCase();var A="";var I="";var x=[];var G={start:m(0,0),end:m(z.lastLine(),z.getLineHandle(z.lastLine()).length)};var w=u.indexOf(i.QUERY_DIV);while(w!=-1){x.push(H.posFromIndex(w));w=u.indexOf(i.QUERY_DIV,w+1)}x.unshift(m(0,0));x.push(m(z.lastLine(),z.getLineHandle(z.lastLine()).text.length));var E=0;var B=q(z.getCursor());for(var v=0;v<x.length;v++){var F=q(x[v]);if(B>E&&B<=F){G={start:l(E),end:l(F)};break}E=F}var C=H.getRange(G.start,G.end,false);for(var v=0;v<C.length;v++){var D=C[v];s(D,function(K){var J=K.toUpperCase();if(J===t&&g(f,A)){I=A}if(J!==i.ALIAS_KEYWORD){A=K}});if(I){break}}return I}n.registerHelper("hint","sql",function(x,A){f=(A&&A.tables)||{};var u=A&&A.defaultTable;p=u&&g(f,u);h=h||b(x);if(u&&!p){p=k(u,x)}p=p||[];if(p.columns){p=p.columns}var y=x.getCursor();var B=[];var v=x.getTokenAt(y),t,w,z;if(v.end>y.ch){v.end=y.ch;v.string=v.string.slice(0,y.ch-v.start)}if(v.string.match(/^[.`\w@]\w*$/)){z=v.string;t=v.start;w=v.end}else{t=w=y.ch;z=""}if(z.charAt(0)=="."||z.charAt(0)=="`"){t=r(y,v,B,x)}else{d(B,z,f,function(C){return C});d(B,z,p,function(C){return C});d(B,z,h,function(C){return C.toUpperCase()})}return{list:B,from:m(y.line,t),to:m(y.line,w)}})});