From 32dfdf7f4d5eddbdca1eb65dc9250aa749b5cf75 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Sat, 14 May 2016 16:11:48 +0300 Subject: [PATCH] merge with devel with regression --- scripts/ddl2cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c368338f..ec26dd26 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -38,7 +38,9 @@ ERROR_STRANGE_PARSING = 20 from pyparsing import CaselessLiteral, Literal, SkipTo, restOfLine, oneOf, ZeroOrMore, Optional, Combine, Suppress, \ - WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group, ParseException + WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, \ + Or, Group, ParseException + # HELPERS @@ -53,6 +55,7 @@ def repl_func(m): else: return m.group(1) + m.group(2).upper() + def repl_func_for_args(m): if m.group(1) == '-': return m.group(2).upper() @@ -85,7 +88,8 @@ def help_message(): if argument == '-help': continue arg_string = arg_string + ' [-[no]'+argument+'] ' + optionalArgs[argument] + '\n' - print('Usage: ddl2cpp [-help] ' + arg_string + ' ') + print('Usage: ddl2cpp [-help] ' + arg_string + + ' ') sys.exit(0) optionalArgs = { @@ -139,6 +143,11 @@ NAMESPACE = 'sqlpp' def ddlWord(string): return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") +# This function should be refactored if we find some database function which needs parameters +# Right now it works only for something like NOW() in MySQL default field value +def ddlFunctionWord(string): + return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") + ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) @@ -157,6 +166,14 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) +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") + + +ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) + +ddlComment = oneOf(["--", "#"]) + restOfLine +ddl.ignore(ddlComment) # MAP SQL TYPES types = { @@ -205,6 +222,7 @@ if warnOnParse: # PROCESS DDL +tableCreations = ddl.parseFile(pathToDdl) header = open(pathToHeader, 'w') print('// generated by ' + ' '.join(sys.argv), file=header)