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:
parent
e921d81049
commit
fd939975ee
@ -169,6 +169,7 @@ ddlNum = Combine(Optional(negativeSign) + Word(nums + "."))
|
||||
ddlTerm = Word(alphanums + "_$")
|
||||
ddlName = Or([ddlTerm, ddlString])
|
||||
ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")"
|
||||
ddlUnsigned = ddlWord("unsigned").setResultsName("isUnsigned")
|
||||
ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull")
|
||||
ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue")
|
||||
ddlAutoValue = Or([
|
||||
@ -186,7 +187,7 @@ ddlConstraint = Or([
|
||||
ddlWord("INDEX"),
|
||||
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"))
|
||||
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
|
||||
#ddlString.setDebug(True) #uncomment to debug pyparsing
|
||||
@ -222,12 +223,17 @@ types = {
|
||||
'datetime': 'time_point',
|
||||
'timestamp': 'time_point',
|
||||
'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])))
|
||||
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
|
||||
ddlComment = oneOf(["--", "#"]) + restOfLine
|
||||
# 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")
|
||||
#ddlComment = oneOf(["--", "#"]) + restOfLine
|
||||
|
||||
if failOnParse:
|
||||
ddl = OneOrMore(Suppress(SkipTo(createTable, False)) + createTable)
|
||||
@ -272,6 +278,7 @@ for create in tableCreations:
|
||||
print(' namespace ' + tableNamespace, file=header)
|
||||
print(' {', file=header)
|
||||
for column in create.columns:
|
||||
print(column);
|
||||
if column.isConstraint:
|
||||
continue
|
||||
sqlColumnName = column[0]
|
||||
@ -279,6 +286,8 @@ for create in tableCreations:
|
||||
tableTemplateParameters += ',\n ' + tableNamespace + '::' + columnClass
|
||||
columnMember = toMemberName(sqlColumnName)
|
||||
sqlColumnType = column[1].lower()
|
||||
if column.isUnsigned:
|
||||
sqlColumnType = sqlColumnType + ' unsigned';
|
||||
if sqlColumnType == 'timestamp' and timestampWarning:
|
||||
print("Warning: timestamp is mapped to sqlpp::time_point like datetime")
|
||||
print("Warning: You have to take care of timezones yourself")
|
||||
|
Loading…
Reference in New Issue
Block a user