diff options
author | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-09 21:50:19 +0000 |
---|---|---|
committer | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-08-09 21:50:19 +0000 |
commit | 0b19bb71ba5a4afa84e673a8239935426fa0db23 (patch) | |
tree | e9abae9c616fdfdfebd9a8a0931d8f21824f30d2 /trunk/src/examples/simpleSQL.py | |
parent | b2c3ade75384efe76b8774b607e17fe98fab92ef (diff) | |
download | pyparsing_2.1.6.tar.gz |
Remove incorrect tag directorypyparsing_2.1.6
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/tags/pyparsing_2.1.6@405 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
Diffstat (limited to 'trunk/src/examples/simpleSQL.py')
-rw-r--r-- | trunk/src/examples/simpleSQL.py | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/trunk/src/examples/simpleSQL.py b/trunk/src/examples/simpleSQL.py deleted file mode 100644 index 66dc18c..0000000 --- a/trunk/src/examples/simpleSQL.py +++ /dev/null @@ -1,72 +0,0 @@ -# simpleSQL.py
-#
-# simple demo of using the parsing library to do simple-minded SQL parsing
-# could be extended to include where clauses etc.
-#
-# Copyright (c) 2003,2016, Paul McGuire
-#
-from pyparsing import Literal, CaselessLiteral, Word, delimitedList, Optional, \
- Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
- ZeroOrMore, restOfLine, Keyword, upcaseTokens
-
-# define SQL tokens
-selectStmt = Forward()
-SELECT = Keyword("select", caseless=True)
-FROM = Keyword("from", caseless=True)
-WHERE = Keyword("where", caseless=True)
-
-ident = Word( alphas, alphanums + "_$" ).setName("identifier")
-columnName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens)
-columnNameList = Group( delimitedList( columnName ) )
-tableName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens)
-tableNameList = Group( delimitedList( tableName ) )
-
-whereExpression = Forward()
-and_ = Keyword("and", caseless=True)
-or_ = Keyword("or", caseless=True)
-in_ = Keyword("in", caseless=True)
-
-E = CaselessLiteral("E")
-binop = oneOf("= != < > >= <= eq ne lt le gt ge", caseless=True)
-arithSign = Word("+-",exact=1)
-realNum = Combine( Optional(arithSign) + ( Word( nums ) + "." + Optional( Word(nums) ) |
- ( "." + Word(nums) ) ) +
- Optional( E + Optional(arithSign) + Word(nums) ) )
-intNum = Combine( Optional(arithSign) + Word( nums ) +
- Optional( E + Optional("+") + Word(nums) ) )
-
-columnRval = realNum | intNum | quotedString | columnName # need to add support for alg expressions
-whereCondition = Group(
- ( columnName + binop + columnRval ) |
- ( columnName + in_ + "(" + delimitedList( columnRval ) + ")" ) |
- ( columnName + in_ + "(" + selectStmt + ")" ) |
- ( "(" + whereExpression + ")" )
- )
-whereExpression << whereCondition + ZeroOrMore( ( and_ | or_ ) + whereExpression )
-
-# define the grammar
-selectStmt <<= (SELECT + ('*' | columnNameList)("columns") +
- FROM + tableNameList( "tables" ) +
- Optional(Group(WHERE + whereExpression), "")("where"))
-
-simpleSQL = selectStmt
-
-# define Oracle comment format, and ignore them
-oracleSqlComment = "--" + restOfLine
-simpleSQL.ignore( oracleSqlComment )
-
-if __name__ == "__main__":
- simpleSQL.runTests("""\
- SELECT * from XYZZY, ABC
- select * from SYS.XYZZY
- Select A from Sys.dual
- Select A,B,C from Sys.dual
- Select A, B, C from Sys.dual
- Select A, B, C from Sys.dual, Table2
- Xelect A, B, C from Sys.dual
- Select A, B, C frox Sys.dual
- Select
- Select &&& frox Sys.dual
- Select A from Sys.dual where a in ('RED','GREEN','BLUE')
- Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30)
- Select A,b from table1,table2 where table1.id eq table2.id -- test out comparison operators""")
|