Advertisement
Guest User

Ken Kuhlman

a guest
Apr 19th, 2008
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. --- simpleSQL-1.4.11.py 2008-04-19 20:39:03.000000000 -0500
  2. +++ simpleSQL.py 2008-04-19 20:47:25.000000000 -0500
  3. @@ -7,7 +7,7 @@
  4. #
  5. from pyparsing import Literal, CaselessLiteral, Word, Upcase, delimitedList, Optional, \
  6. Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
  7. - ZeroOrMore, restOfLine, Keyword
  8. + ZeroOrMore, restOfLine, Keyword, ErrStop, ParseFatalException
  9.  
  10. def test( str ):
  11. print str,"->"
  12. @@ -17,7 +17,7 @@
  13. print "tokens.columns =", tokens.columns
  14. print "tokens.tables =", tokens.tables
  15. print "tokens.where =", tokens.where
  16. - except ParseException, err:
  17. + except (ParseException, ParseFatalException), err:
  18. print " "*err.loc + "^\n" + err.msg
  19. print err
  20. print
  21. @@ -59,10 +59,11 @@
  22.  
  23. # define the grammar
  24. selectStmt << ( selectToken +
  25. - ( '*' | columnNameList ).setResultsName( "columns" ) +
  26. + ( '*' | columnNameList )( "columns" ) +
  27. fromToken +
  28. tableNameList.setResultsName( "tables" ) +
  29. - Optional( Group( CaselessLiteral("where") + whereExpression ), "" ).setResultsName("where") )
  30. + Optional( Group( CaselessLiteral("where") +
  31. + ErrStop(whereExpression)), "" ).setResultsName("where") )
  32.  
  33. simpleSQL = selectStmt
  34.  
  35. @@ -84,7 +85,7 @@
  36. test( "Select A from Sys.dual where a in ('RED','GREEN','BLUE')" )
  37. test( "Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30)" )
  38. test( "Select A,b from table1,table2 where table1.id eq table2.id -- test out comparison operators" )
  39. -
  40. +test( "select * from table1 where a b" )
  41. """
  42. Test output:
  43. >pythonw -u simpleSQL.py
  44. @@ -138,5 +139,10 @@
  45. Expected '*'
  46. Expected '*' (7), (1,8)
  47.  
  48. +select * from table1 where a b
  49. + ^
  50. +Expected '='
  51. +Expected '=' (at char 29), (line:1, col:30)
  52. +
  53. >Exit code: 0
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement