I was thinking about using my hierarchy framework
to start with. It's essentially a binary-tree library meant for automated assembly and exporting the tree as formatted data. Each node is derived from a base class, so I'd derive a new node type for each of the "stackable" statements. Each one would have a variable for its required/optional parameters (e.g. table name, column name) and a list of names of other statements that can be embedded. The framework allows simple, pre-insertion checks so that a node can reject insertion of an another node as a child. Lastly, the framework allows export of the tree via an interface that passes an output object recursively to the nodes; each node would export its name and data, then its children (or whatever order the statement requires,) and the result would be a text string ready to pass to an SQL API.
That shouldn't be too difficult a task; just time consuming while I find the time to track down and implement specifications for each command. But once I know what's unique to e.g. SELECT, I can just specify what "add-ons" it allows, and define those separately. What I ponder at this point is how to hide this with an interface; I want to be able to assemble statements one step at a time. My first thought is to use a global-function interface and provide a handle to an instance of a class defined internally, then have it passed to modification functions to add branches to the tree corresponding to sub-statements. The majority of the work is already done by the library.
PS There's also the matter of quoting, escaping, and validating user-provide strings, which I don't know if I want to do. Right now the plan is to fill a requirement (mine) and later include third-party considerations if anyone expresses interest.