From 4e4cb9cc4c8d7f3df7d096729172e6f501bf2e55 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 22 Apr 2016 08:49:55 +0200 Subject: [PATCH 01/26] Minor cmake fix At least I hope it's a fix --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58ab3755..1a5924e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ target_include_directories(sqlpp11 INTERFACE $ ) -if (NOT MSVC) +if (NOT DEFINED MSVC) target_compile_features(sqlpp11 INTERFACE cxx_alias_templates cxx_auto_type From 690028fb84b509f663d5f4cadb6e522d12544bb5 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Apr 2016 10:30:06 +0200 Subject: [PATCH 02/26] Added test to prepare statement with zero parameters --- tests/Prepared.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Prepared.cpp b/tests/Prepared.cpp index e8796b02..637c030a 100644 --- a/tests/Prepared.cpp +++ b/tests/Prepared.cpp @@ -130,6 +130,12 @@ int Prepared(int, char* []) std::cerr << x.alpha << std::endl; } + // Can we prepare a query without parameters? + { + auto ps = db.prepare(select(all_of(t)).from(t).where((t.beta.like("%")))); + auto res = db(ps); + } + // Check that a prepared select is default-constructable { auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or From f41770dbe23e9427b0eaef34868ef0477927ae61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Sun, 1 May 2016 20:01:33 +0200 Subject: [PATCH 03/26] Added FindHinnatDate.cmake to prevent usage of preset paths Howard Hinnant's date and time library is found using a cmake Find-module. Commit 377fbc8958b26cb2c0151b3068bce07dff3811ec was reverted to ensure that the exported target has the correct properties. --- CMakeLists.txt | 23 +++----- cmake/Modules/FindHinnantDate.cmake | 83 +++++++++++++++++++++++++++++ cmake/Sqlpp11Config.cmake | 5 ++ 3 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 cmake/Modules/FindHinnantDate.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a5924e4..d7767a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright (c) 2013-2016, Roland Bock +# Copyright (c) 2016 Christian Dávid # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -27,27 +28,18 @@ project(sqlpp11 VERSION 0.1 LANGUAGES CXX) enable_testing() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +find_package(HinnantDate REQUIRED) + add_library(sqlpp11 INTERFACE) -set(DATE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../date" CACHE FILEPATH "Path to Howard Hinnant's date library") - -if(NOT EXISTS ${DATE_INCLUDE_DIR}/date.h) - message(SEND_ERROR "Can't find file date.h and cannot compile date_test/date_test.cpp") - message("Can't find date.h in ${DATE_INCLUDE_DIR} ") - message("Please either") - message(" - git clone https://github.com/howardhinnant/date ${DATE_INCLUDE_DIR}") - message(" - download and unzip a current version from https://github.com/howardhinnant/date to ${DATE_INCLUDE_DIR}") - message(" - set DATE_INCLUDE_DIR to point to the dir containing date.h from the date library") - message("") -endif() +target_link_libraries(sqlpp11 INTERFACE HinnantDate::Date) target_include_directories(sqlpp11 INTERFACE - $ $ $ ) -if (NOT DEFINED MSVC) target_compile_features(sqlpp11 INTERFACE cxx_alias_templates cxx_auto_type @@ -69,7 +61,6 @@ target_compile_features(sqlpp11 INTERFACE cxx_template_template_parameters cxx_variadic_templates ) -endif () install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" DESTINATION include @@ -106,13 +97,13 @@ install(EXPORT Sqlpp11Targets install( FILES - cmake/Sqlpp11Config.cmake + "cmake/Sqlpp11Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake" + "cmake/Modules/FindHinnantDate.cmake" DESTINATION ${ConfigPackageLocation} ) - add_subdirectory(tests) add_subdirectory(test_types) add_subdirectory(test_serializer) diff --git a/cmake/Modules/FindHinnantDate.cmake b/cmake/Modules/FindHinnantDate.cmake new file mode 100644 index 00000000..0d44df51 --- /dev/null +++ b/cmake/Modules/FindHinnantDate.cmake @@ -0,0 +1,83 @@ +#.rst: +# FindHinnantDate +# --------------- +# +# This module finds Howard Hinnant's date and time library for C++11 and beyond +# See https://github.com/HowardHinnant/date for details. +# +# This will define the following variables:: +# +# HinnantDate_FOUND - True if the system has the library +# HinnantDate_INCLUDE_DIR - The directory which includes the header +# +# and the following imported targets:: +# +# HinnantDate::Date - The target to use date.h +# +# The target will enable the required C++11 standard in your compiler. You can +# use any later standard but you have to enable them explicitly. + +# Copyright (c) 2016 Christian Dávid +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +cmake_minimum_required(VERSION 3.1) + +find_file(HinnantDate_INCLUDE_FILE + date.h + HINTS ${HinnantDate_INCLUDE_DIR} +) + +if (HinnantDate_INCLUDE_FILE) + # Validate that correct file is found + file(STRINGS ${HinnantDate_INCLUDE_FILE} check_result + LIMIT_COUNT 1 + REGEX "^ *// Copyright [(]c[)] 2015.* Howard Hinnant *$" + ) + + if("${check_result}" STREQUAL "") + message(STATUS "FindHinnantDate: Rejecting found '${HinnantDate_INCLUDE_FILE}', it seems to be a name twin.") + unset(HinnantDate_INCLUDE_FILE) + else() + # Check succeeded, create target + get_filename_component(HinnantDate_INCLUDE_DIR "${HinnantDate_INCLUDE_FILE}" DIRECTORY CACHE) + if(NOT TARGET HinnantDate::Date) + add_library(HinnantDate::Date INTERFACE IMPORTED) + set_target_properties(HinnantDate::Date PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HinnantDate_INCLUDE_DIR}" + INTERFACE_COMPILE_FEATURES "cxx_auto_type;cxx_static_assert;cxx_decltype;cxx_alias_templates;cxx_strong_enums" +# Due to cmake restrictions the standard cannot be set directly to interface imported targets. Instead required compile +# features are set (list maybe incomplete). Please note that this list shall be a minimal set of required features. +# CXX_STANDARD 11 +# CXX_STANDARD_REQUIRED true + ) + endif() + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HinnantDate + REQUIRED_VARS + HinnantDate_INCLUDE_DIR +) diff --git a/cmake/Sqlpp11Config.cmake b/cmake/Sqlpp11Config.cmake index 033d7f4b..015ab4b6 100644 --- a/cmake/Sqlpp11Config.cmake +++ b/cmake/Sqlpp11Config.cmake @@ -23,4 +23,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +include(CMakeFindDependencyMacro) +find_dependency(HinnantDate REQUIRED) + include("${CMAKE_CURRENT_LIST_DIR}/Sqlpp11Targets.cmake") From f32dd7a65c6e1da6a5e50784cb78e964724ebb56 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Tue, 3 May 2016 15:42:02 +0300 Subject: [PATCH 04/26] -m --- scripts/ddl2cpp | 79 ++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c4d41584..87fccc4f 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -34,10 +34,12 @@ import pprint 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 -def usage(): - print('Usage: ddl2cpp [-no-timestamp-warning] ') -if len(sys.argv) not in (4,5): +def usage(): + print('Usage: ddl2cpp [-no-timestamp-warning] \ + ') + +if len(sys.argv) not in (4, 5): usage() sys.exit(1) @@ -63,16 +65,19 @@ def get_include_guard_name(namespace, inputfile): val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile)) return val.upper() + def repl_func(m): - if (m.group(1) == '_'): + if m.group(1) == '_': return m.group(2).upper() else: return m.group(1) + m.group(2).upper() -def toClassName(s): + +def to_class_name(s): return re.sub("(^|\s|[_0-9])(\S)", repl_func, s) -def toMemberName(s): + +def to_member_name(s): return re.sub("(\s|_|[0-9])(\S)", repl_func, s) @@ -80,16 +85,19 @@ def toMemberName(s): def ddlWord(string): return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") -ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) +def ddlFunctionWord(string): + return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") + +ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') -ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) -ddlTerm = Word(alphas, alphanums + "_$") -ddlName = Or([ddlTerm, ddlString]) +ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) +ddlTerm = Word(alphas, alphanums + "_$") +ddlName = Or([ddlTerm, ddlString]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") -ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue"); -ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue"); -ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") +ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") +ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue") +ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlConstraint = Or([ ddlWord("CONSTRAINT"), ddlWord("PRIMARY"), @@ -98,7 +106,9 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +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") @@ -125,12 +135,12 @@ types = { 'boolean': 'boolean', 'double': 'floating_point', 'float': 'floating_point', - 'date' : 'day_point', - 'datetime' : 'time_point', - 'timestamp' : 'time_point', - 'enum' : 'text', # MYSQL - 'set' : 'text', # MYSQL - } + 'date': 'day_point', + 'datetime': 'time_point', + 'timestamp': 'time_point', + 'enum': 'text', # MYSQL + 'set': 'text', # MYSQL +} # PROCESS DDL @@ -147,11 +157,11 @@ print('#include <' + INCLUDE + '/char_sequence.h>', file=header) print('', file=header) print('namespace ' + namespace, file=header) print('{', file=header) -DataTypeError = False; +DataTypeError = False for create in tableCreations: sqlTableName = create.tableName - tableClass = toClassName(sqlTableName) - tableMember = toMemberName(sqlTableName) + tableClass = to_class_name(sqlTableName) + tableMember = to_member_name(sqlTableName) tableNamespace = tableClass + '_' tableTemplateParameters = tableClass print(' namespace ' + tableNamespace, file=header) @@ -160,9 +170,9 @@ for create in tableCreations: if column.isConstraint: continue sqlColumnName = column[0] - columnClass = toClassName(sqlColumnName) + columnClass = to_class_name(sqlColumnName) tableTemplateParameters += ',\n ' + tableNamespace + '::' + columnClass - columnMember = toMemberName(sqlColumnName) + columnMember = to_member_name(sqlColumnName) sqlColumnType = column[1].lower() if sqlColumnType == 'timestamp' and timestampWarning: print("Warning: timestamp is mapped to sqlpp::time_point like datetime") @@ -184,22 +194,22 @@ for create in tableCreations: print(' };', file=header) print(' };', file=header) try: - traitslist = [NAMESPACE + '::' + types[sqlColumnType]]; + traitslist = [NAMESPACE + '::' + types[sqlColumnType]] except KeyError as e: print ('Error: datatype "' + sqlColumnType + '"" is not supported.') DataTypeError = True requireInsert = True if column.hasAutoValue: - traitslist.append(NAMESPACE + '::tag::must_not_insert'); - traitslist.append(NAMESPACE + '::tag::must_not_update'); + traitslist.append(NAMESPACE + '::tag::must_not_insert') + traitslist.append(NAMESPACE + '::tag::must_not_update') requireInsert = False if not column.notNull: - traitslist.append(NAMESPACE + '::tag::can_be_null'); + traitslist.append(NAMESPACE + '::tag::can_be_null') requireInsert = False if column.hasDefaultValue: requireInsert = False if requireInsert: - traitslist.append(NAMESPACE + '::tag::require_insert'); + traitslist.append(NAMESPACE + '::tag::require_insert') print(' using _traits = ' + NAMESPACE + '::make_traits<' + ', '.join(traitslist) + '>;', file=header) print(' };', file=header) print(' }', file=header) @@ -223,10 +233,11 @@ for create in tableCreations: print('}', file=header) print('#endif', file=header) -if (DataTypeError): +if DataTypeError: print("Error: unsupported datatypes." ) print("Possible solutions:") - print("A) Implement this datatype (examples: sqlpp11/data_types)" ) - print("B) Extend/upgrade ddl2cpp (edit types map)" ) + print("A) Implement this datatype (examples: sqlpp11/data_types)") + print("B) Extend/upgrade ddl2cpp (edit types map)") print("C) Raise an issue on github" ) - sys.exit(10) #return non-zero error code, we might need it for automation + sys.exit(10) # return non-zero error code, we might need it for automation + From 94945cc9502599f7896a1701666c1d8601207a92 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Tue, 3 May 2016 15:42:02 +0300 Subject: [PATCH 05/26] ddl2cpp mysql now() support, minor PEP-8 edits --- scripts/ddl2cpp | 79 ++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c4d41584..87fccc4f 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -34,10 +34,12 @@ import pprint 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 -def usage(): - print('Usage: ddl2cpp [-no-timestamp-warning] ') -if len(sys.argv) not in (4,5): +def usage(): + print('Usage: ddl2cpp [-no-timestamp-warning] \ + ') + +if len(sys.argv) not in (4, 5): usage() sys.exit(1) @@ -63,16 +65,19 @@ def get_include_guard_name(namespace, inputfile): val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile)) return val.upper() + def repl_func(m): - if (m.group(1) == '_'): + if m.group(1) == '_': return m.group(2).upper() else: return m.group(1) + m.group(2).upper() -def toClassName(s): + +def to_class_name(s): return re.sub("(^|\s|[_0-9])(\S)", repl_func, s) -def toMemberName(s): + +def to_member_name(s): return re.sub("(\s|_|[0-9])(\S)", repl_func, s) @@ -80,16 +85,19 @@ def toMemberName(s): def ddlWord(string): return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") -ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) +def ddlFunctionWord(string): + return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") + +ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') -ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) -ddlTerm = Word(alphas, alphanums + "_$") -ddlName = Or([ddlTerm, ddlString]) +ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) +ddlTerm = Word(alphas, alphanums + "_$") +ddlName = Or([ddlTerm, ddlString]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") -ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue"); -ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue"); -ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") +ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") +ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue") +ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlConstraint = Or([ ddlWord("CONSTRAINT"), ddlWord("PRIMARY"), @@ -98,7 +106,9 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +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") @@ -125,12 +135,12 @@ types = { 'boolean': 'boolean', 'double': 'floating_point', 'float': 'floating_point', - 'date' : 'day_point', - 'datetime' : 'time_point', - 'timestamp' : 'time_point', - 'enum' : 'text', # MYSQL - 'set' : 'text', # MYSQL - } + 'date': 'day_point', + 'datetime': 'time_point', + 'timestamp': 'time_point', + 'enum': 'text', # MYSQL + 'set': 'text', # MYSQL +} # PROCESS DDL @@ -147,11 +157,11 @@ print('#include <' + INCLUDE + '/char_sequence.h>', file=header) print('', file=header) print('namespace ' + namespace, file=header) print('{', file=header) -DataTypeError = False; +DataTypeError = False for create in tableCreations: sqlTableName = create.tableName - tableClass = toClassName(sqlTableName) - tableMember = toMemberName(sqlTableName) + tableClass = to_class_name(sqlTableName) + tableMember = to_member_name(sqlTableName) tableNamespace = tableClass + '_' tableTemplateParameters = tableClass print(' namespace ' + tableNamespace, file=header) @@ -160,9 +170,9 @@ for create in tableCreations: if column.isConstraint: continue sqlColumnName = column[0] - columnClass = toClassName(sqlColumnName) + columnClass = to_class_name(sqlColumnName) tableTemplateParameters += ',\n ' + tableNamespace + '::' + columnClass - columnMember = toMemberName(sqlColumnName) + columnMember = to_member_name(sqlColumnName) sqlColumnType = column[1].lower() if sqlColumnType == 'timestamp' and timestampWarning: print("Warning: timestamp is mapped to sqlpp::time_point like datetime") @@ -184,22 +194,22 @@ for create in tableCreations: print(' };', file=header) print(' };', file=header) try: - traitslist = [NAMESPACE + '::' + types[sqlColumnType]]; + traitslist = [NAMESPACE + '::' + types[sqlColumnType]] except KeyError as e: print ('Error: datatype "' + sqlColumnType + '"" is not supported.') DataTypeError = True requireInsert = True if column.hasAutoValue: - traitslist.append(NAMESPACE + '::tag::must_not_insert'); - traitslist.append(NAMESPACE + '::tag::must_not_update'); + traitslist.append(NAMESPACE + '::tag::must_not_insert') + traitslist.append(NAMESPACE + '::tag::must_not_update') requireInsert = False if not column.notNull: - traitslist.append(NAMESPACE + '::tag::can_be_null'); + traitslist.append(NAMESPACE + '::tag::can_be_null') requireInsert = False if column.hasDefaultValue: requireInsert = False if requireInsert: - traitslist.append(NAMESPACE + '::tag::require_insert'); + traitslist.append(NAMESPACE + '::tag::require_insert') print(' using _traits = ' + NAMESPACE + '::make_traits<' + ', '.join(traitslist) + '>;', file=header) print(' };', file=header) print(' }', file=header) @@ -223,10 +233,11 @@ for create in tableCreations: print('}', file=header) print('#endif', file=header) -if (DataTypeError): +if DataTypeError: print("Error: unsupported datatypes." ) print("Possible solutions:") - print("A) Implement this datatype (examples: sqlpp11/data_types)" ) - print("B) Extend/upgrade ddl2cpp (edit types map)" ) + print("A) Implement this datatype (examples: sqlpp11/data_types)") + print("B) Extend/upgrade ddl2cpp (edit types map)") print("C) Raise an issue on github" ) - sys.exit(10) #return non-zero error code, we might need it for automation + sys.exit(10) # return non-zero error code, we might need it for automation + From f0d2bf6189bea5f96262a8ce9ba2b616e1cff363 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Tue, 3 May 2016 15:49:42 +0300 Subject: [PATCH 06/26] ddl2cpp mysql now(). Too many commits. --- scripts/ddl2cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c4d41584..c0f973dc 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -80,6 +80,9 @@ def toMemberName(s): def ddlWord(string): return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") +def ddlFunctionWord(string): + return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") + ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) @@ -98,7 +101,7 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +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") From 101a02e9e8df68044997416ca335821674ac2c1f Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Wed, 4 May 2016 23:13:17 +0300 Subject: [PATCH 07/26] adding comment --- scripts/ddl2cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c0f973dc..7810fa70 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -80,6 +80,8 @@ def toMemberName(s): 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(")") From 42dfa6cddc72fff2c6b48213f1f194ac7e0db55f Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Thu, 5 May 2016 01:58:53 +0300 Subject: [PATCH 08/26] argument parsing, fail on parsing --- .gitignore | 1 + scripts/ddl2cpp | 144 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..485dee64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index c4d41584..7b354d63 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -31,40 +31,28 @@ import re import os import pprint +# error codes, we should refactor this later +ERROR_DATA_TYPE = 10 +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 - -def usage(): - print('Usage: ddl2cpp [-no-timestamp-warning] ') - -if len(sys.argv) not in (4,5): - usage() - sys.exit(1) - -firstPositional = 1 -timestampWarning = True -if len(sys.argv) == 5: - if sys.argv[1] == '-no-timestamp-warning': - firstPositional += 1 - timestampWarning = False - else: - usage() - sys.exit(1) - -pathToDdl = sys.argv[firstPositional] -pathToHeader = sys.argv[firstPositional + 1] + '.h' -namespace = sys.argv[firstPositional + 2] - -INCLUDE = 'sqlpp11' -NAMESPACE = 'sqlpp' + WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group, ParseException # HELPERS + def get_include_guard_name(namespace, inputfile): val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile)) return val.upper() + def repl_func(m): - if (m.group(1) == '_'): + if m.group(1) == '_': + return m.group(2).upper() + else: + return m.group(1) + m.group(2).upper() + +def repl_func_for_args(m): + if m.group(1) == '-': return m.group(2).upper() else: return m.group(1) + m.group(2).upper() @@ -72,10 +60,61 @@ def repl_func(m): def toClassName(s): return re.sub("(^|\s|[_0-9])(\S)", repl_func, s) + def toMemberName(s): return re.sub("(\s|_|[0-9])(\S)", repl_func, s) +def setArgumentBool(s, bool_value): + first_lower = lambda s: s[:1].lower() + s[1:] if s else '' # http://stackoverflow.com/a/3847369/5006740 + var_name = first_lower(re.sub("(\s|-|[0-9])(\S)", repl_func_for_args, s)) + globals()[var_name] = bool_value + + +def usage(): + print('Usage: ddl2cpp [-no-timestamp-warning] ') + +# ARGUMENT PARSING +if len(sys.argv) < (4): + usage() + sys.exit(20) + +firstPositional = 1 +timestampWarning = True +failOnParse = True + +optionalArgs = { + # if -some-key is present, it will set variable someKey to True + # if -no-some-key is present, it will set variable someKey to False + 'timestamp-warning', # timeStampWarning = True + # '-no-time-stamp-warning' # timeStampWarning = False + 'fail-on-parse' # failOnParse = True + # 'no-fail-on-parse' # failOnParse = False + +} + +if len(sys.argv) >= 4: + + for arg in sys.argv: + noArg = arg.replace('-no-', '') + + if arg in optionalArgs: + setArgumentBool(arg, True) + firstPositional += 1 + elif noArg in optionalArgs: + setArgumentBool(noArg, False) + firstPositional += 1 + +#sys.exit(0) +pathToDdl = sys.argv[firstPositional] +pathToHeader = sys.argv[firstPositional + 1] + '.h' +namespace = sys.argv[firstPositional + 2] + +INCLUDE = 'sqlpp11' +NAMESPACE = 'sqlpp' + + + # PARSER def ddlWord(string): return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") @@ -87,8 +126,8 @@ ddlTerm = Word(alphas, alphanums + "_$") ddlName = Or([ddlTerm, ddlString]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") -ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue"); -ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue"); +ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") +ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue") ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlConstraint = Or([ ddlWord("CONSTRAINT"), @@ -98,14 +137,6 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, 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 = { @@ -125,16 +156,33 @@ types = { 'boolean': 'boolean', 'double': 'floating_point', 'float': 'floating_point', - 'date' : 'day_point', - 'datetime' : 'time_point', - 'timestamp' : 'time_point', - 'enum' : 'text', # MYSQL - 'set' : 'text', # MYSQL + 'date': 'day_point', + 'datetime': 'time_point', + 'timestamp': 'time_point', + 'enum': 'text', # MYSQL + 'set': 'text', # MYSQL } +ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") +ddlComment = oneOf(["--", "#"]) + restOfLine + +if failOnParse: + ddl = OneOrMore(Suppress(SkipTo(createTable, False)) + createTable) + ddl.ignore(ddlComment) + try: + tableCreations = ddl.parseFile(pathToDdl) + except ParseException as e: + print("parsing error, possible reason: can't parse default value for a field") + sys.exit() +else: + ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) + ddl.ignore(ddlComment) + tableCreations = ddl.parseFile(pathToDdl) # PROCESS DDL -tableCreations = ddl.parseFile(pathToDdl) + + header = open(pathToHeader, 'w') print('// generated by ' + ' '.join(sys.argv), file=header) @@ -147,7 +195,7 @@ print('#include <' + INCLUDE + '/char_sequence.h>', file=header) print('', file=header) print('namespace ' + namespace, file=header) print('{', file=header) -DataTypeError = False; +DataTypeError = False for create in tableCreations: sqlTableName = create.tableName tableClass = toClassName(sqlTableName) @@ -184,22 +232,22 @@ for create in tableCreations: print(' };', file=header) print(' };', file=header) try: - traitslist = [NAMESPACE + '::' + types[sqlColumnType]]; + traitslist = [NAMESPACE + '::' + types[sqlColumnType]] except KeyError as e: print ('Error: datatype "' + sqlColumnType + '"" is not supported.') DataTypeError = True requireInsert = True if column.hasAutoValue: - traitslist.append(NAMESPACE + '::tag::must_not_insert'); - traitslist.append(NAMESPACE + '::tag::must_not_update'); + traitslist.append(NAMESPACE + '::tag::must_not_insert') + traitslist.append(NAMESPACE + '::tag::must_not_update') requireInsert = False if not column.notNull: - traitslist.append(NAMESPACE + '::tag::can_be_null'); + traitslist.append(NAMESPACE + '::tag::can_be_null') requireInsert = False if column.hasDefaultValue: requireInsert = False if requireInsert: - traitslist.append(NAMESPACE + '::tag::require_insert'); + traitslist.append(NAMESPACE + '::tag::require_insert') print(' using _traits = ' + NAMESPACE + '::make_traits<' + ', '.join(traitslist) + '>;', file=header) print(' };', file=header) print(' }', file=header) From ffc2dd0f3c6a2add7670050fc37f8a948548783d Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Thu, 5 May 2016 02:40:44 +0300 Subject: [PATCH 09/26] doing --- scripts/ddl2cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 7b354d63..e9aa4ac1 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -81,15 +81,16 @@ if len(sys.argv) < (4): firstPositional = 1 timestampWarning = True -failOnParse = True - +failOnParse = False +warnOnParse = True +parseError = "parsing error, possible reason: can't parse default value for a field" optionalArgs = { # if -some-key is present, it will set variable someKey to True # if -no-some-key is present, it will set variable someKey to False 'timestamp-warning', # timeStampWarning = True # '-no-time-stamp-warning' # timeStampWarning = False 'fail-on-parse' # failOnParse = True - # 'no-fail-on-parse' # failOnParse = False + 'warn-on-parse' # warnOnParse = True } @@ -97,18 +98,27 @@ if len(sys.argv) >= 4: for arg in sys.argv: noArg = arg.replace('-no-', '') - + print (noArg) if arg in optionalArgs: + print ("AAAA") + print (noArg) setArgumentBool(arg, True) firstPositional += 1 elif noArg in optionalArgs: + print ("BBBB") setArgumentBool(noArg, False) firstPositional += 1 + else: + print ("abcd") + print(arg) + + -#sys.exit(0) pathToDdl = sys.argv[firstPositional] pathToHeader = sys.argv[firstPositional + 1] + '.h' namespace = sys.argv[firstPositional + 2] +print (pathToDdl) +sys.exit(0) INCLUDE = 'sqlpp11' NAMESPACE = 'sqlpp' @@ -173,17 +183,20 @@ if failOnParse: try: tableCreations = ddl.parseFile(pathToDdl) except ParseException as e: - print("parsing error, possible reason: can't parse default value for a field") + print(parseError) sys.exit() else: ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) ddl.ignore(ddlComment) tableCreations = ddl.parseFile(pathToDdl) + +if warnOnParse: + print(parseError) + + # PROCESS DDL - - header = open(pathToHeader, 'w') print('// generated by ' + ' '.join(sys.argv), file=header) print('#ifndef '+get_include_guard_name(namespace, pathToHeader), file=header) From 7097d4a32558d47bafab08dbd85887cbc7c61d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Thu, 5 May 2016 10:09:04 +0200 Subject: [PATCH 10/26] Approved error messages of FindHinnantDate.cmake Also added a documented variable to give hints. --- cmake/Modules/FindHinnantDate.cmake | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmake/Modules/FindHinnantDate.cmake b/cmake/Modules/FindHinnantDate.cmake index 0d44df51..7ae59c96 100644 --- a/cmake/Modules/FindHinnantDate.cmake +++ b/cmake/Modules/FindHinnantDate.cmake @@ -9,11 +9,14 @@ # # HinnantDate_FOUND - True if the system has the library # HinnantDate_INCLUDE_DIR - The directory which includes the header +# HinnantDate_ROOT_DIR - The base directory of the library # # and the following imported targets:: # # HinnantDate::Date - The target to use date.h # +# You can set HinnantDate_ROOT_DIR as hint to the location of the library. +# # The target will enable the required C++11 standard in your compiler. You can # use any later standard but you have to enable them explicitly. @@ -44,10 +47,16 @@ cmake_minimum_required(VERSION 3.1) +# ensure cache entry +set(HinnantDate_ROOT_DIR "${HinnantDate_ROOT_DIR}" CACHE PATH "Root directory of Howard Hinnant's date library") +set(HinnantDate_NOT_FOUND_MESSAGE "Could NOT find HinnantDate. +Maybe you need to adjust the search paths or HinnantDate_ROOT_DIR.") + find_file(HinnantDate_INCLUDE_FILE date.h - HINTS ${HinnantDate_INCLUDE_DIR} + HINTS ${HinnantDate_ROOT_DIR} ) +mark_as_advanced(HinnantDate_INCLUDE_FILE) if (HinnantDate_INCLUDE_FILE) # Validate that correct file is found @@ -57,11 +66,15 @@ if (HinnantDate_INCLUDE_FILE) ) if("${check_result}" STREQUAL "") - message(STATUS "FindHinnantDate: Rejecting found '${HinnantDate_INCLUDE_FILE}', it seems to be a name twin.") - unset(HinnantDate_INCLUDE_FILE) + string(APPEND HinnantDate_NOT_FOUND_MESSAGE "\nRejecting found '${HinnantDate_INCLUDE_FILE}', it seems to be a name twin.") + unset(HinnantDate_INCLUDE_FILE CACHE) else() # Check succeeded, create target get_filename_component(HinnantDate_INCLUDE_DIR "${HinnantDate_INCLUDE_FILE}" DIRECTORY CACHE) + mark_as_advanced(HinnantDate_INCLUDE_DIR) + set(HinnantDate_ROOT_DIR "${HinnantDate_INCLUDE_DIR}") + unset(HinnantDate_NOT_FOUND_MESSAGE) + if(NOT TARGET HinnantDate::Date) add_library(HinnantDate::Date INTERFACE IMPORTED) set_target_properties(HinnantDate::Date PROPERTIES @@ -78,6 +91,6 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(HinnantDate - REQUIRED_VARS - HinnantDate_INCLUDE_DIR + REQUIRED_VARS HinnantDate_ROOT_DIR HinnantDate_INCLUDE_DIR + FAIL_MESSAGE ${HinnantDate_NOT_FOUND_MESSAGE} ) From bcc3eea988bba695ea723b6ac32b56ae18729e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Thu, 5 May 2016 10:15:26 +0200 Subject: [PATCH 11/26] Updated travis build config It sets the path to the date library correctly now. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce830dcb..f2ccad57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,7 @@ before_script: - mkdir build - cd build - if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" && "$TRAVIS_OS_NAME" = "linux" ]]; then export CXXFLAGS="--coverage"; fi - - cmake .. -DCMAKE_BUILD_TYPE=$CONFIG -DDATE_INCLUDE_DIR=$PWD/../date + - cmake .. -DCMAKE_BUILD_TYPE=$CONFIG -DCMAKE_PREFIX_PATH=$PWD/../date script: - cmake --build . --config $CONFIG From 21ea63c050519cbc6be3796ddd8774308d1ad1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Thu, 5 May 2016 10:31:58 +0200 Subject: [PATCH 12/26] Adopted .appveyor.yml to find the date library --- .appveyor.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 6a32db7b..2574b0b0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,14 +14,13 @@ build_script: - CD - cd .. - CD - - git clone https://github.com/HowardHinnant/date + - git clone --branch v1.0.0 --depth 1 https://github.com/HowardHinnant/date - cd sqlpp11 - CD - echo %configuration% - mkdir build - cd build - cmake --version - - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" + - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH=../../date - cmake --build . --config %configuration% - ctest . --build-config %configuration% - From bd22cdbb6155ae57342683b6fea34d44955c1a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Thu, 5 May 2016 16:58:19 +0200 Subject: [PATCH 13/26] Corrected path to date in .appveyor.yml --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 2574b0b0..950a3f86 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,6 +21,6 @@ build_script: - mkdir build - cd build - cmake --version - - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH=../../date + - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH=../../../date - cmake --build . --config %configuration% - ctest . --build-config %configuration% From 5bd96147542807017b453098e54b3d9a3a1950c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Thu, 5 May 2016 20:31:28 +0200 Subject: [PATCH 14/26] Corrected path to date in .appveyor.yml (again) --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 950a3f86..10ab73ce 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,6 +21,6 @@ build_script: - mkdir build - cd build - cmake --version - - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH=../../../date + - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH="..\..\date" - cmake --build . --config %configuration% - ctest . --build-config %configuration% From e457757ec5409a0fc22f7fa88e57da7773545257 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Thu, 5 May 2016 23:08:27 +0300 Subject: [PATCH 15/26] heavy refactoring --- scripts/ddl2cpp | 59 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index e9aa4ac1..eb0e8d02 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -32,9 +32,11 @@ import os import pprint # error codes, we should refactor this later +ERROR_BAD_ARGS = 1 ERROR_DATA_TYPE = 10 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 @@ -71,54 +73,52 @@ def setArgumentBool(s, bool_value): globals()[var_name] = bool_value -def usage(): - print('Usage: ddl2cpp [-no-timestamp-warning] ') +def usage(optionalArgs = []): + argString = '' + for arg in optionalArgs: + argString = argString + '[-[no-]'+arg+'] ' + print('Usage: ddl2cpp '+ argString +' ') + +optionalArgs = [ + # if -some-key is present, it will set variable someKey to True + # if -no-some-key is present, it will set variable someKey to False + '-timestamp-warning', # timeStampWarning = True + # '-no-time-stamp-warning' # timeStampWarning = False + '-fail-on-parse', # failOnParse = True + '-warn-on-parse' # warnOnParse = True +] # ARGUMENT PARSING if len(sys.argv) < (4): - usage() - sys.exit(20) + usage(optionalArgs) + sys.exit(ERROR_BAD_ARGS) firstPositional = 1 timestampWarning = True failOnParse = False -warnOnParse = True -parseError = "parsing error, possible reason: can't parse default value for a field" -optionalArgs = { - # if -some-key is present, it will set variable someKey to True - # if -no-some-key is present, it will set variable someKey to False - 'timestamp-warning', # timeStampWarning = True - # '-no-time-stamp-warning' # timeStampWarning = False - 'fail-on-parse' # failOnParse = True - 'warn-on-parse' # warnOnParse = True +warnOnParse = False +parseError = "Parsing error, possible reason: can't parse default value for a field" -} if len(sys.argv) >= 4: - for arg in sys.argv: - noArg = arg.replace('-no-', '') - print (noArg) + #print(arg) + noArg = arg.replace('-no-', '-') + print(noArg) if arg in optionalArgs: - print ("AAAA") - print (noArg) setArgumentBool(arg, True) firstPositional += 1 elif noArg in optionalArgs: - print ("BBBB") setArgumentBool(noArg, False) firstPositional += 1 else: - print ("abcd") - print(arg) - - + pass pathToDdl = sys.argv[firstPositional] + pathToHeader = sys.argv[firstPositional + 1] + '.h' namespace = sys.argv[firstPositional + 2] -print (pathToDdl) -sys.exit(0) + INCLUDE = 'sqlpp11' NAMESPACE = 'sqlpp' @@ -183,16 +183,15 @@ if failOnParse: try: tableCreations = ddl.parseFile(pathToDdl) except ParseException as e: - print(parseError) - sys.exit() + print(parseError + '. Exiting [-no-fail-on-parse]') + sys.exit(ERROR_STRANGE_PARSING) else: ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) ddl.ignore(ddlComment) tableCreations = ddl.parseFile(pathToDdl) - if warnOnParse: - print(parseError) + print(parseError + '. Continuing [-no-warn-on-parse]') # PROCESS DDL From eed1b89f2ed7adfa187a34af23ff2fae9cbae967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=A1vid?= Date: Fri, 6 May 2016 19:52:00 +0200 Subject: [PATCH 16/26] Corrected path to date in .appveyor.yml (again) --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 10ab73ce..ba2387cf 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,6 +21,6 @@ build_script: - mkdir build - cd build - cmake --version - - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH="..\..\date" + - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH="C:\projects\date" - cmake --build . --config %configuration% - ctest . --build-config %configuration% From 7771ed8269c1f34f9db861566c31f515523fd89b Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 11 May 2016 19:10:23 +0200 Subject: [PATCH 17/26] Added serializer tests for insert --- include/sqlpp11/insert.h | 2 +- test_serializer/CMakeLists.txt | 1 + test_serializer/Insert.cpp | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test_serializer/Insert.cpp diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index be342093..5b635977 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -96,7 +96,7 @@ namespace sqlpp static Context& _(const T&, Context& context) { - context << "INSERT "; + context << "INSERT"; return context; } diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index f10ee5bc..3a83d6df 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -26,6 +26,7 @@ set(test_serializer_names CustomQuery From In + Insert Where ) diff --git a/test_serializer/Insert.cpp b/test_serializer/Insert.cpp new file mode 100644 index 00000000..e145cf7d --- /dev/null +++ b/test_serializer/Insert.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016-2016, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "compare.h" +#include "Sample.h" +#include + +#include + +namespace +{ + auto getTrue() -> std::string + { + MockDb::_serializer_context_t printer = {}; + return serialize(sqlpp::value(true), printer).str(); + } +} + +int Insert(int, char* []) +{ + const auto bar = test::TabBar{}; + + compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES"); + compare(__LINE__, insert_into(bar).set(bar.beta = "cheesecake", bar.gamma = true), + "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); + + return 0; +} From 3f33eb855475aaf080f05b12f9fb778608945a30 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 12 May 2016 14:35:14 +0200 Subject: [PATCH 18/26] Get rid of static_cast --- include/sqlpp11/parameter_list.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 443ad4ad..14ee3136 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -61,8 +61,7 @@ namespace sqlpp void _bind_impl(Target& target, const detail::index_sequence&) const { using swallow = int[]; // see interpret_tuple.h - (void)swallow{( - static_cast::type&>(*this)()._bind(target, Is), 0)...}; + (void)swallow{(std::tuple_element::type::operator()()._bind(target, Is), 0)...}; } }; From 3e6e16f1f02387b64c684b9c661299b0ecf226bd Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 12 May 2016 15:01:00 +0200 Subject: [PATCH 19/26] Added parameter to prevent empty swallow --- include/sqlpp11/parameter_list.h | 2 +- include/sqlpp11/statement.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 14ee3136..4052a61d 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -61,7 +61,7 @@ namespace sqlpp void _bind_impl(Target& target, const detail::index_sequence&) const { using swallow = int[]; // see interpret_tuple.h - (void)swallow{(std::tuple_element::type::operator()()._bind(target, Is), 0)...}; + (void)swallow{0, (std::tuple_element::type::operator()()._bind(target, Is), 0)...}; } }; diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index cc51ca6e..286e6cec 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -257,7 +257,8 @@ namespace sqlpp static Context& _(const T& t, Context& context) { using swallow = int[]; - (void)swallow{(serialize(static_cast&>(t)()._data, context), 0)...}; + (void)swallow{0, + (serialize(static_cast&>(t)()._data, context), 0)...}; return context; } From a5421e8c34a241a3d42682e6e51721bd0bf4257b Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Sat, 14 May 2016 14:30:08 +0300 Subject: [PATCH 20/26] adding help, remove debug output --- scripts/ddl2cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index eb0e8d02..3a9f0843 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -29,7 +29,7 @@ from __future__ import print_function import sys import re import os -import pprint + # error codes, we should refactor this later ERROR_BAD_ARGS = 1 @@ -73,21 +73,32 @@ def setArgumentBool(s, bool_value): globals()[var_name] = bool_value -def usage(optionalArgs = []): - argString = '' - for arg in optionalArgs: - argString = argString + '[-[no-]'+arg+'] ' - print('Usage: ddl2cpp '+ argString +' ') +def usage(optionalArgs = {}): + print('\ + Usage: ddl2cpp \n\ + ddl2cpp -help') -optionalArgs = [ +def help(): + argString = '\n' + for arg in list(optionalArgs.keys()): + if arg == '-help': + continue + argString = argString + ' [-[no-]'+arg+'] ' + optionalArgs[arg] + '\n' + print('Usage: ddl2cpp [-help] ' + argString + ' ') + sys.exit(0) + +optionalArgs = { # if -some-key is present, it will set variable someKey to True # if -no-some-key is present, it will set variable someKey to False - '-timestamp-warning', # timeStampWarning = True + '-timestamp-warning': "show warning about mysql timestamp data type", # timeStampWarning = True # '-no-time-stamp-warning' # timeStampWarning = False - '-fail-on-parse', # failOnParse = True - '-warn-on-parse' # warnOnParse = True -] + '-fail-on-parse': "abort instead of silent genereation of unusable headers", # failOnParse = True + '-warn-on-parse': "warn about unusable headers, but continue", # warnOnParse = True + '-help': "show this help" +} +if ('-help') in sys.argv: + help() # ARGUMENT PARSING if len(sys.argv) < (4): usage(optionalArgs) @@ -102,10 +113,8 @@ parseError = "Parsing error, possible reason: can't parse default value for a fi if len(sys.argv) >= 4: for arg in sys.argv: - #print(arg) noArg = arg.replace('-no-', '-') - print(noArg) - if arg in optionalArgs: + if arg in list(optionalArgs.keys()): setArgumentBool(arg, True) firstPositional += 1 elif noArg in optionalArgs: From 897d581eec27f2a7aa38794ab6d9712551ee5f1b Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Sat, 14 May 2016 14:33:28 +0300 Subject: [PATCH 21/26] fix -[no-]- display in arguments --- scripts/ddl2cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 3a9f0843..2deec90f 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -83,7 +83,7 @@ def help(): for arg in list(optionalArgs.keys()): if arg == '-help': continue - argString = argString + ' [-[no-]'+arg+'] ' + optionalArgs[arg] + '\n' + argString = argString + ' [-[no]'+arg+'] ' + optionalArgs[arg] + '\n' print('Usage: ddl2cpp [-help] ' + argString + ' ') sys.exit(0) From 11f40dc20c6bd053db82cea18340532876981c05 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Sat, 14 May 2016 15:57:26 +0300 Subject: [PATCH 22/26] small cleanup, pre-merging --- scripts/ddl2cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 2deec90f..c368338f 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -78,13 +78,14 @@ def usage(optionalArgs = {}): Usage: ddl2cpp \n\ ddl2cpp -help') -def help(): - argString = '\n' - for arg in list(optionalArgs.keys()): - if arg == '-help': + +def help_message(): + arg_string = '\n' + for argument in list(optionalArgs.keys()): + if argument == '-help': continue - argString = argString + ' [-[no]'+arg+'] ' + optionalArgs[arg] + '\n' - print('Usage: ddl2cpp [-help] ' + argString + ' ') + arg_string = arg_string + ' [-[no]'+argument+'] ' + optionalArgs[argument] + '\n' + print('Usage: ddl2cpp [-help] ' + arg_string + ' ') sys.exit(0) optionalArgs = { @@ -97,8 +98,8 @@ optionalArgs = { '-help': "show this help" } -if ('-help') in sys.argv: - help() +if '-help' in sys.argv: + help_message() # ARGUMENT PARSING if len(sys.argv) < (4): usage(optionalArgs) 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 23/26] 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) From de2409dd7eeece942c8ed84d4bed8ede7d35e1fd Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Sat, 14 May 2016 16:21:35 +0300 Subject: [PATCH 24/26] remove regression --- scripts/ddl2cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index ec26dd26..b77d895c 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -200,7 +200,7 @@ types = { 'set': 'text', # MYSQL } -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +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") ddlComment = oneOf(["--", "#"]) + restOfLine From e80f06e2a3ad9ffa6122e7e60bb5337b5399ebdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cdigitalist=2Eru=E2=80=9D?= <“strangeqargo@gmail.com”> Date: Sun, 15 May 2016 01:02:46 +0300 Subject: [PATCH 25/26] fix --- scripts/ddl2cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index b77d895c..cc2c7320 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -84,12 +84,25 @@ def usage(optionalArgs = {}): def help_message(): arg_string = '\n' + pad = 0 + padding = 0 + for argument in list(optionalArgs.keys()): + if len(argument) > pad: + pad = len(argument) for argument in list(optionalArgs.keys()): if argument == '-help': continue - arg_string = arg_string + ' [-[no]'+argument+'] ' + optionalArgs[argument] + '\n' - print('Usage: ddl2cpp [-help] ' + arg_string + - ' ') + if len(argument) < pad: + padding = " " * (pad - len(argument)) + else: + padding = '' + arg_string = arg_string + ' [-[no]'+argument+']: ' + padding + optionalArgs[argument] + '\n' + print('Usage: ddl2cpp [-help]\n\n OPTIONAL ARUMENTS:\n' + arg_string +' \n \ + \n\ +\n\ + path to your SQL database/table definitions (SHOW CREATE TABLE SomeTable) \n\ + path to a generated C++ header file. Without extension (no *.h). \n\ + namespace you want. Usually a project/database name\n') sys.exit(0) optionalArgs = { From ec6c36d541f3dda20df7cfd24e106f27875f0426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cdigitalist=2Eru=E2=80=9D?= <“strangeqargo@gmail.com”> Date: Sun, 15 May 2016 01:05:08 +0300 Subject: [PATCH 26/26] fix typo --- scripts/ddl2cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index cc2c7320..20855442 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -97,7 +97,7 @@ def help_message(): else: padding = '' arg_string = arg_string + ' [-[no]'+argument+']: ' + padding + optionalArgs[argument] + '\n' - print('Usage: ddl2cpp [-help]\n\n OPTIONAL ARUMENTS:\n' + arg_string +' \n \ + print('Usage: ddl2cpp [-help]\n\n OPTIONAL ARGUMENTS:\n' + arg_string +' \n \ \n\ \n\ path to your SQL database/table definitions (SHOW CREATE TABLE SomeTable) \n\