Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Select SQL String

Select SQL String

Scheduled Pinned Locked Moved Database
databasealgorithmshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nguyen Vu Cuong
    wrote on last edited by
    #1

    My problem has 2 workflows: WF1:=>I'm OK<=With an active connection, the user can drag and drop fields in a table and I'm succesfully generate an SQL string. WF2:=>I'm now in trouble<= I let the user type the SQL string in a richtextbox. And now I must display all the tables, the relation ships, the fields etc... specified in the SQL string typed by the user. Would you please give me some helps? I really need an effective algorithm to parse this SQL string. Thank you in advance

    S 1 Reply Last reply
    0
    • N Nguyen Vu Cuong

      My problem has 2 workflows: WF1:=>I'm OK<=With an active connection, the user can drag and drop fields in a table and I'm succesfully generate an SQL string. WF2:=>I'm now in trouble<= I let the user type the SQL string in a richtextbox. And now I must display all the tables, the relation ships, the fields etc... specified in the SQL string typed by the user. Would you please give me some helps? I really need an effective algorithm to parse this SQL string. Thank you in advance

      S Offline
      S Offline
      Steven Campbell
      wrote on last edited by
      #2

      I have written a basic SQL parser before, but it was parsing generated SQL, which was fairly tightly under my control anyway. I would not want to do it for SQL that the user typed! SQL can be very complex, with nested queries and multiple ways of writing the same query. Most typed queries will be simple though, so maybe you can get by with something basic, that works in 90% of cases. Alternate solution 1: I would leverage what I could from SQL Server. In SQL Query Analyzer, you can look at the query plan for a particular query. This shows some of what you are interested in. Perhaps you could find out how that is done, and use a similar technique. Alternate solution 2: SQL Enterprise and SQL Query analyzer both have a query designer tool that does something similar to what you want. It may be that there is an underlying API that you could utilize. Alternate solution 3: Create a temporary view from the SQL, and then use various techniques to analyze that view. sp_depends will tell you the tables, sp_help will tell you the result structure. Not sure how you would tell the relationships though.

      N 1 Reply Last reply
      0
      • S Steven Campbell

        I have written a basic SQL parser before, but it was parsing generated SQL, which was fairly tightly under my control anyway. I would not want to do it for SQL that the user typed! SQL can be very complex, with nested queries and multiple ways of writing the same query. Most typed queries will be simple though, so maybe you can get by with something basic, that works in 90% of cases. Alternate solution 1: I would leverage what I could from SQL Server. In SQL Query Analyzer, you can look at the query plan for a particular query. This shows some of what you are interested in. Perhaps you could find out how that is done, and use a similar technique. Alternate solution 2: SQL Enterprise and SQL Query analyzer both have a query designer tool that does something similar to what you want. It may be that there is an underlying API that you could utilize. Alternate solution 3: Create a temporary view from the SQL, and then use various techniques to analyze that view. sp_depends will tell you the tables, sp_help will tell you the result structure. Not sure how you would tell the relationships though.

        N Offline
        N Offline
        Nguyen Vu Cuong
        wrote on last edited by
        #3

        Would you please tell me more about the Solution 2? It will be better if I can utilize some API, but which API? Can you show me an example using these API? And would you mind send me your project that you've written? Thank you.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups