0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

Escape column names if they are reserved keywords

This commit is contained in:
Dirk Vanden Boer 2017-11-09 15:49:13 +01:00
parent fc1f6324f3
commit dd5970a193

View File

@ -48,6 +48,16 @@ def get_include_guard_name(namespace, inputfile):
val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile))
return val.upper()
def escape_if_reserved(name):
reserved_names = [
'GROUP',
'ORDER'
]
if name.upper() in reserved_names:
return '\\"{}\\"'.format(name)
return name
def repl_func(m):
if m.group(1) == '_':
@ -288,7 +298,7 @@ for create in tableCreations:
print(' {', file=header)
print(' struct _alias_t', file=header)
print(' {', file=header)
print(' static constexpr const char _literal[] = "' + sqlColumnName + '";', file=header)
print(' static constexpr const char _literal[] = "' + escape_if_reserved(sqlColumnName) + '";', file=header)
print(' using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;', file=header)
print(' template<typename T>', file=header)
print(' struct _member_t', file=header)