.NET SQL Statement Parser

General
General covers Articles, Reference documentation, FAQs, Downloads and Blogs that do not belong to a specific subject area. General-purpose Articles about everything and anything
Fan

.NET SQL Statement Parser

Dears,

   I'm a Microsoft.NET developer (C#, VB.NET) and I need to validate SQL statements programmatically (from my custom code). I do not need to connect to Teradata and execure the command. I need just parse and validate bunch of files - SQL statements (semantics, syntaxt, naming conventions, etc.). I know sqlparser.com product, but it seems to me, it does not support Teradata SQL.

 

Thank a lot!

Frunta.

4 REPLIES
Senior Apprentice

Re: .NET SQL Statement Parser

Hi,

 

I don't think this will be easy for you to do unless you connect to a TD system.

 

IF you can do that then you can use the 'Prepare' method.

 

Otherwise I think you're looking at building your own parser, or adjusting (if you can) the sqlparser.com product to handle Teradata specifics.

 

Having said that, the sqlparser.com website says they support Teradata (although I don't know what version of TD their support is at).

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
Fan

Re: .NET SQL Statement Parser

Hi,

   thank you for your reply. I do not know what method 'Prepare' do you mean. Method of what?

If necessary, I'm able to connect to TD using .NET Data Provider, it works perfectly, but I do not know, how to validate DDL / DML scripts without executing them. And finally, I need to check if the script is matching 'code-standards'. upper/lower/camel case, commas, indentation etc.

   My idea is to parse the script, make a expression tree and re-format it before processing it. Each delepper has its own coding culture and I need to umifi it somehow, before passinf them to the cusomer.

For example "SELECT col1, col2, 'a' AS col3 FROM db1.table1" format as

"select
   col1,

   col2,

   col3, ... "

 

 

Concerning product sqlparser.com - it is based on their "gudusoft" parser. It seems to me, Java version supports Teradata, but .NET not. I'm willing to ask there. But asinkg community forum on Teradata web, was my first choice.

 

Thank you again!

Frunta.

Senior Apprentice

Re: .NET SQL Statement Parser

Hi Frunta,

 

The 'Prepare' is a method of the TDCommand class. If you have got code that allows you to run SQL then (I think) you'll be using TDCommand. This will validate the SQL syntax. It's very similar to using the 'EXPLAIN' feature that Teradata provides. Check the TD manuals if you're not familiar with this.

 

Although now that you've explained more about what you're doing I'm not sure it's really going to help you. I think you're looking at writing your own parser.

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
Fan

Re: .NET SQL Statement Parser

Hi Dave,

   what I'm trying to do, is to validate SQL statement (without connectivity to DB). Then reformat it and finally handover it to the customer. For instance, for SEL col1, col2, FROM ... It shoud say: "Hey guy, there is an exctra comma in your statement." Even if the col1, co2, table1 doesn't really exists in the TD DB.

   I've contacted sqlparser.com company. New version of their parser for .NET will support Teradata, so I'll see :)

Thanks a lot!

Frunta.