RegEx for parsing SQL query in C#

后端 未结 2 665
南旧
南旧 2021-01-21 23:50

I need to write RegEx in C# to parse SQL join query which is given as a string. Can somebody please help me because I\'m new at this. Thanks a lot

this is my problem:

2条回答
  •  失恋的感觉
    2021-01-22 00:33

    I personally do not recommend doing this unless you have a VERY, VERY valid reason to do so as well as full control over the way that the SQL would be written.

    First and foremost the syntax that you noted for the SQL statement is the old style join syntax and not using the more common ON syntax.

    Something like

    SELECT A.ColumnA, B.ColumnB
    FROM MyTable A
        INNER JOIN YourTable B
            ON (A.MyIdentity = B.MyForeignKey)
    

    So unless you can force users to input queries in the old syntax you are already going down the road to a way that will not work.

    If I was forced to do this type of thing, and I did have control over it, I personally wouldn't bother with RegEx, due to the fact that the process is so structured. i would just use basic string manipulation.

提交回复
热议问题