Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:30:20+00:00 2026-05-23T02:30:20+00:00

I am looking for a good SQL parser in Delphi (2010) for SQL Server.

  • 0

I am looking for a good SQL parser in Delphi (2010) for SQL Server. I need such thing to parse an query and extract: select list, where and order by clauses. It does not matter if it is a commercial or an open-source solution. It can also be a DLL (written in any language, of course) but I prefer a VCL component over a DLL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:30:21+00:00Added an answer on May 23, 2026 at 2:30 am

    Rafael Delphi comes with a sql parser located in the DBCommon unit

    Check these functions

    function NextSQLToken(var p: PAnsiChar; out Token: AnsiString; CurSection: TSQLToken): TSQLToken; overload;
    function NextSQLToken(var p: PWideChar; out Token: WideString; CurSection: TSQLToken): TSQLToken; overload;
    function NextSQLToken(var p: PChar; out Token: String; CurSection: TSQLToken): TSQLToken; overload;
    
    function GetIndexForOrderBy(const SQL: WideString; DataSet: TDataSet): TIndexDef;
    function GetTableNameFromSQL(const SQL: WideString): WideString;
    function GetTableNameFromQuery(const SQL: Widestring): Widestring;
    function AddParamSQLForDetail(Params: TParams; SQL: WideString; Native: Boolean; QuoteChar: WideString = ''): WideString;
    function IsMultiTableQuery(const SQL: WideString): Boolean;
    function SQLRequiresParams(const SQL: WideString): Boolean;
    
    function NextSQLTokenEx(var p: PWideChar; out Token: UnicodeString; CurSection: TSQLToken; IdOption: IDENTIFIEROption): TSQLToken; overload;
    function NextSQLTokenEx(var p: PWideChar; out Token: WideString; CurSection: TSQLToken; IdOption: IDENTIFIEROption): TSQLToken; overload;
    function NextSQLTokenEx(var p: PAnsiChar; out Token: AnsiString; CurSection: TSQLToken; IdOption: IDENTIFIEROption): TSQLToken; overload;
    function GetTableNameFromSQLEx(const SQL: WideString; IdOption: IDENTIFIEROption): WideString;
    

    This is a very simple sample to show how parse a sql sentence and get all the elements.

    uses
      TypInfo,
      DbCommon,
      SysUtils;
    
    
    const
      StrSql ='Select Field1, Field2, 54 field3, Field4 from Mytable1 Order by Field1,Field5';
    
    procedure ParseSql(Const Sql : string);
    var
      SQLToken     : TSQLToken;
      CurSection   : TSQLToken;
      Start        : PWideChar;
      Token        : WideString;
      IdOption     : IDENTIFIEROption;
    begin
      IdOption   :=idMixCase;
      Start      :=PWideChar(StrSql);
      CurSection := stUnknown;
      repeat
        SQLToken := NextSQLTokenEx(Start, Token, CurSection, IdOption);
        if SQLToken<>stEnd then
        Writeln(Format('Type %s Token %s', [GetEnumName(TypeInfo(TSQLToken), integer(SQLToken)),Token]));
        CurSection := SQLToken;
      until SQLToken in [stEnd];
    end;
    
    
    
    begin
      try
        ParseSql(StrSql);
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
      Readln;
    end.
    

    this will return

    Type stSelect Token Select
    Type stFieldName Token Field1
    Type stFieldName Token Field2
    Type stNumber Token 54
    Type stFieldName Token field3
    Type stFieldName Token Field4
    Type stFrom Token from
    Type stTableName Token Mytable1
    Type stOrderBy Token Order by
    Type stFieldName Token Field1
    Type stFieldName Token Field5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for good SQL parser. One that will work with subselects, non-select queries,
I am looking for good resources on Stored Procedures. Particularly for Microsoft SQL server
I'm looking for some good tutorials involving ASP.NET MVC 3 and SQL Server databases.
I am looking for a good SQL Statement to select all rows from the
I need to shorten this query and while I'm pretty good at SQL, I'm
I use SQL Server 2008 R2 and I'm looking for a good reporting tool.
I'm looking for a good T-SQL Pretty Printer so that all the code looks
I'm currently looking for a good (free) tool to do some PL/SQL development on
Im looking good SQL (MySQL) editor/viewer for MacOS. I want to spend money on
I am no good at SQL. I am looking for a way to speed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.