CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2005
    Location
    DELHI
    Posts
    3

    Display SQL Parsed string with reserved keywords in color.

    Hi

    I am developing a SQL-DMO application where i need to display SQL Scripts with reserved keywords in color like the way Query Window of Sql Analyzer displays. I am using sqlparser.dll to parse the script into RTF format much like this

    \cf1 CREATE\cf \cf1 TABLE\cf \cf5 [\cf \cf10 card_types\cf \cf5 ]\cf \cf5 (\cf
    \par \cf5 [\cf \cf10 card_type_id\cf \cf5 ]\cf \cf5 [\cf \cf2 int\cf \cf5 ]\cf \cf1 IDENTITY\cf \cf5 (\cf \cf7 1\cf \cf5 ,\cf \cf7 1\cf \cf5 )\cf \cf5 NOT\cf \cf5 NULL\cf \cf5 ,\cf
    \par \cf5 [\cf \cf1 name\cf \cf5 ]\cf \cf5 [\cf \cf2 varchar\cf \cf5 ]\cf \cf5 (\cf \cf7 50\cf \cf5 )\cf \cf1 COLLATE\cf \cf10 SQL_Latin1_General_CP1_CI_AS\cf \cf5 NOT\cf \cf5 NULL\cf \cf5 ,\cf
    \par \cf1 PRIMARY\cf \cf1 KEY\cf \cf1 CLUSTERED\cf
    \par \cf5 (\cf
    \par \cf5 [\cf \cf10 card_type_id\cf \cf5 ]\cf
    \par \cf5 )\cf \cf1 ON\cf \cf5 [\cf \cf1 PRIMARY\cf \cf5 ]\cf
    \par \cf5 )\cf \cf1 ON\cf \cf5 [\cf \cf1 PRIMARY\cf \cf5 ]\cf
    \par \cf1 GO\cf
    \par
    \par
    \par


    Now my problem is neither Textbox nor RichTextBox control is able to display it the way i want. I also tried word document thru VB code to display this text, but it displayed without color.

    Can anybody know which control/component/library SQL Query Analyzer uses or is there any other control that i can use.

    Thanks in advance.
    Rajender Kr.

  2. #2
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: Display SQL Parsed string with reserved keywords in color.

    Here... this should do the trick... I wrote this a few years back.

    You'll just need to finish setting up for the SQL language. To see how it is done you can also refer to the inbuilt functions SetupForC, SetupForVB and SetupForMATLAB.

    One problem with it which I have noticed is that, after pasting multiple lines, it is not so happy... but it still works quite well. Note that to use it in FAST mode you need to have 2 rtf boxes. (One remains invisible and does the colourising whilst the other is presented to the user.)

    Hope it helps you.
    Attached Files Attached Files
    Mike

  3. #3
    Join Date
    Jun 2005
    Location
    DELHI
    Posts
    3

    Re: Display SQL Parsed string with reserved keywords in color.

    Thanks Pinky, this will definitly work, if i don't find any inbuilt component then i'll use your code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured