From dd5970a19380aa599389956c0ed449e730c0e5f9 Mon Sep 17 00:00:00 2001 From: Dirk Vanden Boer Date: Thu, 9 Nov 2017 15:49:13 +0100 Subject: [PATCH] Escape column names if they are reserved keywords --- scripts/ddl2cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 2deae826..adc05be1 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -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;', file=header) print(' template', file=header) print(' struct _member_t', file=header)