Adding syntax for MySQL to WordPress plugin Crayon Syntax Highlighter

… or how to make Crayon Syntax Highlighter speak „MySQL“

First – if not already done – you have to download and install Crayon Syntax Highlighter.

Then just extract the following zip file and copy the mysql folder into the following directory and your done:
{your-wordpress-root-path}/wp-content/plugins/crayon-syntax-highlighter/langs

Here is the download link for the add-on:
mysql-1.0.0.zip (2219 Downloads )

And this is how it looks like with the new add-on installed:

-- a comment
SET NAMES 'utf8';

# another comment
DROP TABLE item;
DROP DATABASE `shop`;

/*
 * and another comment
 */
DROP TRIGGER IF EXISTS `trigger_item`;
DELIMITER //
CREATE TRIGGER `trigger_item` AFTER UPDATE ON `item`
FOR EACH ROW BEGIN
    IF COALESCE(NEW.value, -1) <> COALESCE(OLD.value, -1) THEN
        INSERT INTO item_log (item_id, old, new, inserted) VALUES (NEW.item_id, OLD.value, NEW.value, NOW());
    END IF;
END
//
DELIMITER ;

CREATE TABLE `item` (
    `item_id` int(8) unsigned NOT NULL AUTO_INCREMENT,
    `value` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
    `category` enum('lifestyle', 'it', 'unknown') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'unknown',
    `inserted` date NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

SELECT
    i.item_id AS `ItemID`,
    i.category AS Category,
    FLOOR(i.category / 100) AS Catalog,
    CONCAT(i.value, ' ', SUM(r.amount), ' hits') AS `Hits`,
    DATE_FORMAT(i.inserted, '%d.%m.%Y') AS `Datum`,
    IF(i.category = 'lifestyle', 'cool', '') AS `Feedback`,
    IFNULL ( i.category, 'buggy' ) AS CategorySomething  -- not nice but works: there should be no whitespace between function name and the bracket
FROM
    item AS i
LEFT JOIN
    rate AS r
    USE INDEX(  -- not nice but works: there should be a whitespace between the reserved word and the bracket
        idx_item_rate
    )
    ON (
        i.item_id = r.item_id
        AND r.is_active = 1
    )

WHERE
    i.article_id = 12345
    AND i.category IN('lifestyle', 'it')
    AND(
        i.value IS NOT NULL
        OR i.inserted > NOW() - INTERVAL 10 HOUR
        OR HOUR(i.inserted) = 8
        OR i.inserted BETWEEN '2013-01-01' AND CURDATE()
        OR i.value REGEXP "abc"
    )
GROUP BY
    `ItemID`
HAVING
    Catalog = 12
ORDER BY
    Category ASC,
    `Hits` DESC
LIMIT
    1
    OFFSET 10
;

Of course the sql statements don’t really make sense. It’s just an example for the syntax highlighting.

Das könnte dich auch interessieren …

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Bitte beachte die Hinweise zum Datenschutz