Is there something I just haven't found within Npgsql that would make it possible for me to get a parsed "tree" of a SQL statement using Npgsql? Something that breaks down the statement into its individual clauses (
ORDER BY, etc.) with the "sub-elements" (e.g., the actual column list from the
SELECT clause, or the specific conditions in the
WHERE clause) exposed as well?
I'd really like to be able to parse an existing statement, modify one or more clauses (add an
ORDER BY condition, alter the
WHERE condition, etc.), then have it recompiled for execution so that I don't have to either rebuild the statement entirely or do some "funky" RegEx or
String.Replace() calls to get the SQL I want in the end.
.rptdocument that I'm wanting to modify and push back into the document for the actual report generation. Like I said, I know I can do it manually, but I'd love to be able to do something like
WHEREClause.Add("column1" = "'value'")or
Microsoft.SqlServer.Management.SqlParser.dlllibrary, but that doesn't support PostgreSQL-specific syntax (e.g., string concatenation using
I'm trying to teach myself how to use ANTLR and their plsql grammar to (hopefully) get where I want to be but, as I said, it would be a lot nicer if I didn't have to go through all of that (or could, at least, eventually replace that).
I would assume that Npgsql does some sort of parsing at some level behind the scenes. I'm certainly not saying I think this request is "simple", but I would guess that there's at least a partial framework in place for some of the task.
Well, after a week of trying to get ANTLR to a place I could at least do some testing, I've given up for now. If a feature like I've described eventually becomes available in Npgsql (or if it's already there and I'm just not able to find it) or, if it's available in some other library somewhere that I haven't yet found, I'd be thrilled to hear about it. In the meantime, I'm just going to have to rebuild the SQL statements I need as I go.
I've posted a question on StackOverflow to this effect (.NET Library to Parse/Modify/Reconstruct SQL Statement) but, as I stated before, I'd certainly prefer to have it as a part of the Npgsql library I'm already using for most of my database communication anyway. If anyone else here has any suggestions or thoughts, I'd be glad to hear them. Thanks.