General SQL Parser is a powerful component with rich set of features, Usually, you begin to code use one of the following code snippets:
1.
TGSqlParser sqlparser = new TGSqlParser(TDbVendor.DbVMssql); // replace TDbVendor.DbVMssql with other vendors when necessary sqlparser.SqlText.Text = "sql text here ..."; int iRet = sqlparser.Parse(); You code goes to here.... ...
2.
TGSqlParser sqlparser = new TGSqlParser(TDbVendor.DbVMssql); // replace TDbVendor.DbVMssql with other vendors when necessary sqlparser.SqlText.Text = "sql text here ..."; int iRet = PrettyPrint(); You code goes to here.... ...
3.
TGSqlParser sqlparser = new TGSqlParser(TDbVendor.DbVMssql); // replace TDbVendor.DbVMssql with other vendors when necessary sqlparser.SqlText.Text = "sql text here ..."; int iRet = GetRawSqlStatements(); You code goes to here.... ...
int iRet = GetRawSqlStatements();
This function will analyze input sql script, and put each sql statement into SqlStatements
with corresponding SqlStatementType, besides SqlStatementType, the only available property
is SourceTokenList which includes all source tokens in this sql statement.
If sql statement can be handled by GetRawSqlStatements, then we call this sql was supported in level 1, almost all sqls in oracle, sql server, db2, mysql was supported in this level.
Now, Let's move one step forward,
int iRet = sqlparser.Parse();
If sql statement can be handled by Parse function, then we call this sql was supported in level 2, after successfully parsed, there will be a parse tree that represent this sql sqlstatement, all detailed information such as clauses, expressions, predicates, queries will be available.
Parse function should be called first before any further processing of sql scripts.
For detailed information about what's sql supported in level 1 or level 2 , check supported sql.
There is another function people may use widely, PrettyPrint, this can beautify sql with lots of
format options.
int iRet = PrettyPrint();
all sqls supported in level 2 will be handled correctly by PrettyPrint.
The best way to getting started with this component is to check demos that meet your requirements, here is the list, and you can find more samples in demo directory shipped together with this component:
1. XML output of sql query structure.
Try any sqls you have with this demo, check out how it was processed by sql parser, and what output you can get. By checking source code of this demo, you will familiar with most important properties and methods of this component.
http://www.sqlparser.com/dl/samples/xmloutput.zip
2. Beautify SQL.
You can tidy sql within your program just with several lines of code.
http://www.sqlparser.com/dl/samples/prettyprint.zip
3. Get database objects in sql.
There are several ways you can use to fetch database objects in sql statement, please check more detail information here:
http://www.sqlparser.com/docs/How_to_identify_DB_objects_in_your_sql.html
http://www.sqlparser.com/dl/samples/getdbobject.zip
4. Handle expression or predicates accurately.
Where clause or other clauses that include expression/predicates can be visited in different ways to accomplish your task.
http://www.sqlparser.com/docs/How_to_use_expression.html
http://www.sqlparser.com/dl/samples/visitexpression.zip
Still doesn't find demos you need? Feel free to contact us to request demo.