Color a mysql query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Color a mysql query?

Post by phice »

Are there any query colorers out there? I can't seem to find any using Google, yet I've seen mysql queries colored before.

Any help?
Image Image
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Umm. Theres a web-based one here: http://tripleasp.net/Services/ShowCode.asmx but your probably best just coding your own.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You could also look at the phpMyAdmin solution as I did:

Just one interesting place: /libraries/sqlparser.lib.php(1996): function PMA_SQP_buildCssData()
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

JAM is on the right track, but it's too built into the system to really take anything away from it.
Image Image
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

What!? Wasn't that a good challenge for you? ;)
I'll see what I have in the store, though i doubt saving this...

Another idea is to look at taglists/wordlists that alot of win32 software use to internally syntax highlight code (among others, SQL). Is there a get_defined_functions() for mysql? Never thought of it, but if so, youre halfways there...

Edit II:
Download the mysql source, and check out the /sql/lex.h file (functions) and /Docs/reservedwords.texi (reserved words) for a good start...

Edited:
I couldn't find the old work, so I whipped something easy together to get you started. Took some data from phpMyAdmin to help me get started...
> Demo and source example

For others reading: Yes, it's ugly. Yes, it can be done better, but... It more fun to do something by yourself isn't it? ;)
Post Reply