0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Merge pull request #99 from digitalist/rogue_underscore

Rogue underscore
This commit is contained in:
Roland Bock 2016-06-11 07:58:53 +02:00 committed by GitHub
commit 232283ed6e

View File

@ -161,16 +161,16 @@ def ddlWord(string):
def ddlFunctionWord(string): def ddlFunctionWord(string):
return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")")
ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")])
negativeSign = Literal('-') negativeSign = Literal('-')
ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) ddlNum = Combine(Optional(negativeSign) + Word(nums + "."))
ddlTerm = Word(alphas, alphanums + "_$") ddlTerm = Word(alphanums + "_$")
ddlName = Or([ddlTerm, ddlString]) ddlName = Or([ddlTerm, ddlString])
ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")"
ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull")
ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue")
ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue") ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue")
ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment")
ddlConstraint = Or([ ddlConstraint = Or([
ddlWord("CONSTRAINT"), ddlWord("CONSTRAINT"),
ddlWord("PRIMARY"), ddlWord("PRIMARY"),
@ -179,9 +179,9 @@ ddlConstraint = Or([
ddlWord("INDEX"), ddlWord("INDEX"),
ddlWord("UNIQUE"), ddlWord("UNIQUE"),
]) ])
ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
#ddlString.setDebug(True) #uncomment to debug pyparsing
ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable)