@@ -1614,155 +1614,6 @@ function prettyProfilingNum (number, accuracy) {
16141614 return num + 's' ;
16151615}
16161616
1617- /**
1618- * Formats a SQL Query nicely with newlines and indentation. Depends on Codemirror and MySQL Mode!
1619- *
1620- * @param {string } string Query to be formatted
1621- * @return {string } The formatted query
1622- */
1623- function sqlPrettyPrint ( string ) {
1624- if ( typeof window . CodeMirror === 'undefined' ) {
1625- return string ;
1626- }
1627-
1628- var mode = window . CodeMirror . getMode ( { } , 'text/x-mysql' ) ;
1629- var stream = new window . CodeMirror . StringStream ( string ) ;
1630- var state = mode . startState ( ) ;
1631- var token ;
1632- var tokens = [ ] ;
1633- var output = '' ;
1634- var tabs = function ( cnt ) {
1635- var ret = '' ;
1636- for ( var i = 0 ; i < 4 * cnt ; i ++ ) {
1637- ret += ' ' ;
1638- }
1639-
1640- return ret ;
1641- } ;
1642-
1643- // "root-level" statements
1644- var statements = {
1645- 'select' : [ 'select' , 'from' , 'on' , 'where' , 'having' , 'limit' , 'order by' , 'group by' ] ,
1646- 'update' : [ 'update' , 'set' , 'where' ] ,
1647- 'insert into' : [ 'insert into' , 'values' ]
1648- } ;
1649- // don't put spaces before these tokens
1650- var spaceExceptionsBefore = { ';' : true , ',' : true , '.' : true , '(' : true } ;
1651- // don't put spaces after these tokens
1652- var spaceExceptionsAfter = { '.' : true } ;
1653-
1654- // Populate tokens array
1655- while ( ! stream . eol ( ) ) {
1656- stream . start = stream . pos ;
1657- token = mode . token ( stream , state ) ;
1658- if ( token !== null ) {
1659- tokens . push ( [ token , stream . current ( ) . toLowerCase ( ) ] ) ;
1660- }
1661- }
1662-
1663- var currentStatement = tokens [ 0 ] [ 1 ] ;
1664-
1665- if ( ! statements [ currentStatement ] ) {
1666- return string ;
1667- }
1668-
1669- // Holds all currently opened code blocks (statement, function or generic)
1670- var blockStack = [ ] ;
1671- // If a new code block is found, newBlock contains its type for one iteration and vice versa for endBlock
1672- var newBlock ;
1673- var endBlock ;
1674- // How much to indent in the current line
1675- var indentLevel = 0 ;
1676- // Holds the "root-level" statements
1677- var statementPart ;
1678- var lastStatementPart = statements [ currentStatement ] [ 0 ] ;
1679-
1680- blockStack . unshift ( 'statement' ) ;
1681-
1682- // Iterate through every token and format accordingly
1683- for ( var i = 0 ; i < tokens . length ; i ++ ) {
1684- // New block => push to stack
1685- if ( tokens [ i ] [ 1 ] === '(' ) {
1686- if ( i < tokens . length - 1 && tokens [ i + 1 ] [ 0 ] === 'statement-verb' ) {
1687- blockStack . unshift ( newBlock = 'statement' ) ;
1688- } else if ( i > 0 && tokens [ i - 1 ] [ 0 ] === 'builtin' ) {
1689- blockStack . unshift ( newBlock = 'function' ) ;
1690- } else {
1691- blockStack . unshift ( newBlock = 'generic' ) ;
1692- }
1693- } else {
1694- newBlock = null ;
1695- }
1696-
1697- // Block end => pop from stack
1698- if ( tokens [ i ] [ 1 ] === ')' ) {
1699- endBlock = blockStack [ 0 ] ;
1700- blockStack . shift ( ) ;
1701- } else {
1702- endBlock = null ;
1703- }
1704-
1705- // A subquery is starting
1706- if ( i > 0 && newBlock === 'statement' ) {
1707- indentLevel ++ ;
1708- output += '\n' + tabs ( indentLevel ) + tokens [ i ] [ 1 ] + ' ' + tokens [ i + 1 ] [ 1 ] . toUpperCase ( ) + '\n' + tabs ( indentLevel + 1 ) ;
1709- currentStatement = tokens [ i + 1 ] [ 1 ] ;
1710- i ++ ;
1711- continue ;
1712- }
1713-
1714- // A subquery is ending
1715- if ( endBlock === 'statement' && indentLevel > 0 ) {
1716- output += '\n' + tabs ( indentLevel ) ;
1717- indentLevel -- ;
1718- }
1719-
1720- // One less indentation for statement parts (from, where, order by, etc.) and a newline
1721- statementPart = statements [ currentStatement ] . indexOf ( tokens [ i ] [ 1 ] ) ;
1722- if ( statementPart !== - 1 ) {
1723- if ( i > 0 ) {
1724- output += '\n' ;
1725- }
1726-
1727- output += tabs ( indentLevel ) + tokens [ i ] [ 1 ] . toUpperCase ( ) ;
1728- output += '\n' + tabs ( indentLevel + 1 ) ;
1729- lastStatementPart = tokens [ i ] [ 1 ] ;
1730- // Normal indentation and spaces for everything else
1731- } else {
1732- if ( ! spaceExceptionsBefore [ tokens [ i ] [ 1 ] ] &&
1733- ! ( i > 0 && spaceExceptionsAfter [ tokens [ i - 1 ] [ 1 ] ] ) &&
1734- output . charAt ( output . length - 1 ) !== ' ' ) {
1735- output += ' ' ;
1736- }
1737-
1738- if ( tokens [ i ] [ 0 ] === 'keyword' ) {
1739- output += tokens [ i ] [ 1 ] . toUpperCase ( ) ;
1740- } else {
1741- output += tokens [ i ] [ 1 ] ;
1742- }
1743- }
1744-
1745- // split columns in select and 'update set' clauses, but only inside statements blocks
1746- if ( ( lastStatementPart === 'select' || lastStatementPart === 'where' || lastStatementPart === 'set' ) &&
1747- tokens [ i ] [ 1 ] === ',' && blockStack [ 0 ] === 'statement' ) {
1748- output += '\n' + tabs ( indentLevel + 1 ) ;
1749- }
1750-
1751- // split conditions in where clauses, but only inside statements blocks
1752- if ( lastStatementPart === 'where' &&
1753- ( tokens [ i ] [ 1 ] === 'and' || tokens [ i ] [ 1 ] === 'or' || tokens [ i ] [ 1 ] === 'xor' ) ) {
1754- if ( blockStack [ 0 ] === 'statement' ) {
1755- output += '\n' + tabs ( indentLevel + 1 ) ;
1756- }
1757- // Todo: Also split and or blocks in newlines & indentation++
1758- // if (blockStack[0] === 'generic')
1759- // output += ...
1760- }
1761- }
1762-
1763- return output ;
1764- }
1765-
17661617function createFunctionConfirmModal ( ) : void {
17671618 if ( $ ( '#functionConfirmModal' ) . length > 0 ) {
17681619 return ;
@@ -3843,7 +3694,6 @@ const Functions = {
38433694 showNoticeForEnum : showNoticeForEnum ,
38443695 showWarningForIntTypes : showWarningForIntTypes ,
38453696 prettyProfilingNum : prettyProfilingNum ,
3846- sqlPrettyPrint : sqlPrettyPrint ,
38473697 confirm : confirmDialog ,
38483698 sortTable : sortTable ,
38493699 teardownCreateTableEvents : teardownCreateTableEvents ,
0 commit comments