From 18e1c180fe0373bae98cb000b3476a42fd97c610 Mon Sep 17 00:00:00 2001 From: "Andreas C. Osowski" Date: Wed, 18 Apr 2018 19:02:06 +0200 Subject: [PATCH] ddl2cpp: support CHECK constraint --- scripts/ddl2cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 8ca0deed..1649b78e 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -178,7 +178,16 @@ negativeSign = Literal('-') ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) ddlTerm = Word(alphanums + "_$") ddlName = Or([ddlTerm, ddlString]) +ddlMathOp = Word("+><=-") +ddlBoolean = Or([ddlWord("AND"), ddlWord("OR"), ddlWord("NOT")]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" +ddlMathCond = "(" + delimitedList( + Or([ + Group(ddlName + ddlMathOp + ddlName), + Group(ddlName + ddlWord("NOT") + ddlWord("NULL")), + ]), + delim=ddlBoolean) + ")" + ddlUnsigned = ddlWord("unsigned").setResultsName("isUnsigned") ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") @@ -196,8 +205,9 @@ ddlConstraint = Or([ ddlWord("KEY"), ddlWord("INDEX"), ddlWord("UNIQUE"), + ddlWord("CHECK") ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlUnsigned, ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlUnsigned, ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments, ddlMathCond]))) ddlIfNotExists = Optional(Group(ddlWord("IF") + ddlWord("NOT") + ddlWord("EXISTS")).setResultsName("ifNotExists")) createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") #ddlString.setDebug(True) #uncomment to debug pyparsing