in Education by
I'm trying to use pyparsing to build a little not-quite-sql parser (I don't have from clauses, I don't have any joins, etc). I've been basing my work today on the simpleSQL.py example script included with pyparsing. I'm trying to add the "GROUP BY" and "ORDER BY" clauses to the parser, but trying to match them no matter which comes before the other. I'm using the Each class, and it seems to be matching them, but it does not set the result name from within the Each class. I am either not doing something right, or something is happening I'm not clear on. Again, from the simpleSQL.py example, I removed the fromToken, so my selectStmt now looks like: # define the grammar selectStmt << ( selectToken + columnNameList.setResultsName('columns') + Optional( CaselessKeyword('where') + whereExpression, "" ).setResultsName('where') + Each( [ Optional( CaselessKeyword('group by') + columnNameList, "" ).setResultsName('group'), Optional( CaselessKeyword('order by') + columnNameList, "" ).setResultsName('order') ] ) ) I get the result: SELECT a WHERE a=b and c = d GROUP BY c, e ORDER By d -> tokens = ['select', ['a'], 'where', ['a', '=', 'b'], 'and', ['c', '=', 'd'], 'group by', ['c', 'e'], 'order by', ['d']] SELECT a WHERE a=b and c =d ORDER BY z, y GROUP BY c -> tokens = ['select', ['a'], 'where', ['a', '=', 'b'], 'and', ['c', '=', 'd'], 'order by', ['z', 'y'], 'group by', ['c']] So, it looks like it's parsing the group and order clauses in either order, but does not assign the results name (to 'order' and 'group'). I can see this being completely dumb and I'm missing something, or I can see it being that I'm going about finding those clauses in any order (and more clauses in the future, like LIMIT) completely wrong. Any help would be greatly appreciated! LOVING pyparsing so far. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Give this a shot: Stmt << ( selectToken + columnNameList('columns') + Optional( CaselessKeyword('where') + whereExpression('where'), "" ) + Each( [ Optional( CaselessKeyword('group by') + columnNameList('group'), "" ).setDebug(), Optional( CaselessKeyword('order by') + columnNameList('order'), "" ).setDebug() ] ) )

Related questions

0 votes
    I want to save files for each result from the loop. For example, I wrote the code but it only saves one file ... do I modify my code? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    The results of each intermediate operation are created and then are used for evaluation of the next-level ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which option controls the number of rows returned in each block of paginated results? (1)threshold (2)PagingSpec (3)pagingIdentifiers...
asked Aug 20, 2021 in Technology by JackTerrance
0 votes
    Which function is accountable for consolidating the results produced by each of the Map() functions/tasks. 1. Reduce 2. Reducer 3. Map 4. All of the mentioned...
asked Aug 7, 2021 in Technology by JackTerrance
0 votes
    A DOMAIN NAME IS A UNIQUE NAME GIVEN TO EACH WEBSITE TRUE OR FALSE Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    The structure of a table Employee is given below. Suggest suitable data type and size of each column. Column name ... _ Design _ _ Select the correct answer from above options...
asked Dec 11, 2021 in Education by JackTerrance
0 votes
    Write the name and category of each of the component shown in picture. Select the correct answer ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 8, 2021 in Education by JackTerrance
0 votes
    What is shown in the picture? Write name and trophic level of each component. Select the correct ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    The unordered collection of properties, each of which has a name and a value is called _________ (a) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    I have a WCF service which is called in 4 different places in my system. It returns approx 500 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I've been trying for some time now to get a screen-space pixel (provided by a deferred HLSL ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    I try to scrape some search results from https://www.companiesintheuk.co.uk/Company/Find?q=a With the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I try to scrape some search results from https://www.companiesintheuk.co.uk/Company/Find?q=a With the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    How to sort wordpress results by category or taxonomy? I have this code: function ordenarResultados($query) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...