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

Scan for unsigned integral columns

This commit is contained in:
rbock 2017-11-06 21:37:10 +01:00
parent e921d81049
commit fd939975ee

View File

@ -169,6 +169,7 @@ ddlNum = Combine(Optional(negativeSign) + Word(nums + "."))
ddlTerm = Word(alphanums + "_$") ddlTerm = Word(alphanums + "_$")
ddlName = Or([ddlTerm, ddlString]) ddlName = Or([ddlTerm, ddlString])
ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")"
ddlUnsigned = ddlWord("unsigned").setResultsName("isUnsigned")
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 = Or([ ddlAutoValue = Or([
@ -186,7 +187,7 @@ 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([ddlUnsigned, ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
ddlIfNotExists = Optional(Group(ddlWord("IF") + ddlWord("NOT") + ddlWord("EXISTS")).setResultsName("ifNotExists")) 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") createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
#ddlString.setDebug(True) #uncomment to debug pyparsing #ddlString.setDebug(True) #uncomment to debug pyparsing
@ -222,12 +223,17 @@ types = {
'datetime': 'time_point', 'datetime': 'time_point',
'timestamp': 'time_point', 'timestamp': 'time_point',
'enum': 'text', # MYSQL 'enum': 'text', # MYSQL
'set': 'text', # MYSQL 'set': 'text', # MYSQL,
'tinyint unsigned': 'tinyint_unsigned', #MYSQL
'smallint unsigned': 'smallint_unsigned', #MYSQL
'integer unsigned': 'integer_unsigned', #MYSQL
'int unsigned': 'integer_unsigned', #MYSQL
'bigint unsigned': 'bigint_unsigned', #MYSQL
} }
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([ddlUnsigned, ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") #createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
ddlComment = oneOf(["--", "#"]) + restOfLine #ddlComment = oneOf(["--", "#"]) + restOfLine
if failOnParse: if failOnParse:
ddl = OneOrMore(Suppress(SkipTo(createTable, False)) + createTable) ddl = OneOrMore(Suppress(SkipTo(createTable, False)) + createTable)
@ -272,6 +278,7 @@ for create in tableCreations:
print(' namespace ' + tableNamespace, file=header) print(' namespace ' + tableNamespace, file=header)
print(' {', file=header) print(' {', file=header)
for column in create.columns: for column in create.columns:
print(column);
if column.isConstraint: if column.isConstraint:
continue continue
sqlColumnName = column[0] sqlColumnName = column[0]
@ -279,6 +286,8 @@ for create in tableCreations:
tableTemplateParameters += ',\n ' + tableNamespace + '::' + columnClass tableTemplateParameters += ',\n ' + tableNamespace + '::' + columnClass
columnMember = toMemberName(sqlColumnName) columnMember = toMemberName(sqlColumnName)
sqlColumnType = column[1].lower() sqlColumnType = column[1].lower()
if column.isUnsigned:
sqlColumnType = sqlColumnType + ' unsigned';
if sqlColumnType == 'timestamp' and timestampWarning: if sqlColumnType == 'timestamp' and timestampWarning:
print("Warning: timestamp is mapped to sqlpp::time_point like datetime") print("Warning: timestamp is mapped to sqlpp::time_point like datetime")
print("Warning: You have to take care of timezones yourself") print("Warning: You have to take care of timezones yourself")