0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Merge branch 'release/0.38'

This commit is contained in:
rbock 2016-05-15 21:35:52 +02:00
commit 8b38df125b
13 changed files with 315 additions and 65 deletions

View File

@ -14,14 +14,13 @@ build_script:
- CD - CD
- cd .. - 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 sqlpp11
- CD - CD
- echo %configuration% - echo %configuration%
- mkdir build - mkdir build
- cd build - cd build
- cmake --version - cmake --version
- cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" - cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503" -DCMAKE_PREFIX_PATH="C:\projects\date"
- cmake --build . --config %configuration% - cmake --build . --config %configuration%
- ctest . --build-config %configuration% - ctest . --build-config %configuration%

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -48,7 +48,7 @@ before_script:
- mkdir build - mkdir build
- cd build - cd build
- if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" && "$TRAVIS_OS_NAME" = "linux" ]]; then export CXXFLAGS="--coverage"; fi - 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: script:
- cmake --build . --config $CONFIG - cmake --build . --config $CONFIG

View File

@ -1,4 +1,5 @@
# Copyright (c) 2013-2016, Roland Bock # Copyright (c) 2013-2016, Roland Bock
# Copyright (c) 2016 Christian Dávid
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, # 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() enable_testing()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
find_package(HinnantDate REQUIRED)
add_library(sqlpp11 INTERFACE) add_library(sqlpp11 INTERFACE)
set(DATE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../date" CACHE FILEPATH "Path to Howard Hinnant's date library") target_link_libraries(sqlpp11 INTERFACE HinnantDate::Date)
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_include_directories(sqlpp11 INTERFACE target_include_directories(sqlpp11 INTERFACE
$<BUILD_INTERFACE:${DATE_INCLUDE_DIR}>
$<BUILD_INTERFACE:${sqlpp11_SOURCE_DIR}/include> $<BUILD_INTERFACE:${sqlpp11_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
) )
if (NOT MSVC)
target_compile_features(sqlpp11 INTERFACE target_compile_features(sqlpp11 INTERFACE
cxx_alias_templates cxx_alias_templates
cxx_auto_type cxx_auto_type
@ -69,7 +61,6 @@ target_compile_features(sqlpp11 INTERFACE
cxx_template_template_parameters cxx_template_template_parameters
cxx_variadic_templates cxx_variadic_templates
) )
endif ()
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11"
DESTINATION include DESTINATION include
@ -106,13 +97,13 @@ install(EXPORT Sqlpp11Targets
install( install(
FILES FILES
cmake/Sqlpp11Config.cmake "cmake/Sqlpp11Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake"
"cmake/Modules/FindHinnantDate.cmake"
DESTINATION DESTINATION
${ConfigPackageLocation} ${ConfigPackageLocation}
) )
add_subdirectory(tests) add_subdirectory(tests)
add_subdirectory(test_types) add_subdirectory(test_types)
add_subdirectory(test_serializer) add_subdirectory(test_serializer)

View File

@ -0,0 +1,96 @@
#.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
# 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.
# 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)
# 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_ROOT_DIR}
)
mark_as_advanced(HinnantDate_INCLUDE_FILE)
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 "")
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
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_ROOT_DIR HinnantDate_INCLUDE_DIR
FAIL_MESSAGE ${HinnantDate_NOT_FOUND_MESSAGE}
)

View File

@ -23,4 +23,9 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # 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") include("${CMAKE_CURRENT_LIST_DIR}/Sqlpp11Targets.cmake")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2015, Roland Bock * Copyright (c) 2013-2016, Roland Bock
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * 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<Is...>&) const void _bind_impl(Target& target, const detail::index_sequence<Is...>&) const
{ {
using swallow = int[]; // see interpret_tuple.h using swallow = int[]; // see interpret_tuple.h
(void)swallow{( (void)swallow{0, (std::tuple_element<Is, _member_tuple_t>::type::operator()()._bind(target, Is), 0)...};
static_cast<typename std::tuple_element<Is, const _member_tuple_t>::type&>(*this)()._bind(target, Is), 0)...};
} }
}; };

View File

@ -257,7 +257,8 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
using swallow = int[]; using swallow = int[];
(void)swallow{(serialize(static_cast<const typename Policies::template _base_t<P>&>(t)()._data, context), 0)...}; (void)swallow{0,
(serialize(static_cast<const typename Policies::template _base_t<P>&>(t)()._data, context), 0)...};
return context; return context;
} }

View File

@ -29,42 +29,35 @@ from __future__ import print_function
import sys import sys
import re import re
import os 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, \ 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 WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, \
Or, Group, ParseException
def usage():
print('Usage: ddl2cpp [-no-timestamp-warning] <path to ddl> <path to target (without extension, e.g. /tmp/MyTable)> <namespace>')
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'
# HELPERS # HELPERS
def get_include_guard_name(namespace, inputfile): def get_include_guard_name(namespace, inputfile):
val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile)) val = re.sub("[^A-Za-z]+", "_", namespace + '_' + os.path.basename(inputfile))
return val.upper() return val.upper()
def repl_func(m): 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() return m.group(2).upper()
else: else:
return m.group(1) + m.group(2).upper() return m.group(1) + m.group(2).upper()
@ -72,14 +65,102 @@ def repl_func(m):
def toClassName(s): def toClassName(s):
return re.sub("(^|\s|[_0-9])(\S)", repl_func, s) return re.sub("(^|\s|[_0-9])(\S)", repl_func, s)
def toMemberName(s): def toMemberName(s):
return re.sub("(\s|_|[0-9])(\S)", repl_func, 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(optionalArgs = {}):
print('\
Usage: ddl2cpp <path to ddl> <path to target (without extension, e.g. /tmp/MyTable)> <namespace>\n\
ddl2cpp -help')
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
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 ARGUMENTS:\n' + arg_string +' \n \
<path to ddl> <path to target> <namespace>\n\
\n\
<path to ddl> path to your SQL database/table definitions (SHOW CREATE TABLE SomeTable) \n\
<path to target> path to a generated C++ header file. Without extension (no *.h). \n\
<namespace> namespace you want. Usually a project/database name\n')
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': "show warning about mysql timestamp data type", # timeStampWarning = True
# '-no-time-stamp-warning' # timeStampWarning = False
'-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_message()
# ARGUMENT PARSING
if len(sys.argv) < (4):
usage(optionalArgs)
sys.exit(ERROR_BAD_ARGS)
firstPositional = 1
timestampWarning = True
failOnParse = False
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-', '-')
if arg in list(optionalArgs.keys()):
setArgumentBool(arg, True)
firstPositional += 1
elif noArg in optionalArgs:
setArgumentBool(noArg, False)
firstPositional += 1
else:
pass
pathToDdl = sys.argv[firstPositional]
pathToHeader = sys.argv[firstPositional + 1] + '.h'
namespace = sys.argv[firstPositional + 2]
INCLUDE = 'sqlpp11'
NAMESPACE = 'sqlpp'
# PARSER # PARSER
def ddlWord(string): def ddlWord(string):
return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") 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("`")]) ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")])
negativeSign = Literal('-') negativeSign = Literal('-')
ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) ddlNum = Combine(Optional(negativeSign) + Word(nums + "."))
@ -87,8 +168,8 @@ ddlTerm = Word(alphas, alphanums + "_$")
ddlName = Or([ddlTerm, ddlString]) ddlName = Or([ddlTerm, ddlString])
ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")"
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 = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue"); ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue")
ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment")
ddlConstraint = Or([ ddlConstraint = Or([
ddlWord("CONSTRAINT"), ddlWord("CONSTRAINT"),
@ -98,7 +179,7 @@ ddlConstraint = Or([
ddlWord("INDEX"), ddlWord("INDEX"),
ddlWord("UNIQUE"), 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") createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
@ -132,6 +213,26 @@ types = {
'set': 'text', # MYSQL 'set': 'text', # 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") + 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(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 + '. Continuing [-no-warn-on-parse]')
# PROCESS DDL # PROCESS DDL
tableCreations = ddl.parseFile(pathToDdl) tableCreations = ddl.parseFile(pathToDdl)
@ -147,7 +248,7 @@ print('#include <' + INCLUDE + '/char_sequence.h>', file=header)
print('', file=header) print('', file=header)
print('namespace ' + namespace, file=header) print('namespace ' + namespace, file=header)
print('{', file=header) print('{', file=header)
DataTypeError = False; DataTypeError = False
for create in tableCreations: for create in tableCreations:
sqlTableName = create.tableName sqlTableName = create.tableName
tableClass = toClassName(sqlTableName) tableClass = toClassName(sqlTableName)
@ -184,22 +285,22 @@ for create in tableCreations:
print(' };', file=header) print(' };', file=header)
print(' };', file=header) print(' };', file=header)
try: try:
traitslist = [NAMESPACE + '::' + types[sqlColumnType]]; traitslist = [NAMESPACE + '::' + types[sqlColumnType]]
except KeyError as e: except KeyError as e:
print ('Error: datatype "' + sqlColumnType + '"" is not supported.') print ('Error: datatype "' + sqlColumnType + '"" is not supported.')
DataTypeError = True DataTypeError = True
requireInsert = True requireInsert = True
if column.hasAutoValue: if column.hasAutoValue:
traitslist.append(NAMESPACE + '::tag::must_not_insert'); traitslist.append(NAMESPACE + '::tag::must_not_insert')
traitslist.append(NAMESPACE + '::tag::must_not_update'); traitslist.append(NAMESPACE + '::tag::must_not_update')
requireInsert = False requireInsert = False
if not column.notNull: if not column.notNull:
traitslist.append(NAMESPACE + '::tag::can_be_null'); traitslist.append(NAMESPACE + '::tag::can_be_null')
requireInsert = False requireInsert = False
if column.hasDefaultValue: if column.hasDefaultValue:
requireInsert = False requireInsert = False
if requireInsert: 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(' using _traits = ' + NAMESPACE + '::make_traits<' + ', '.join(traitslist) + '>;', file=header)
print(' };', file=header) print(' };', file=header)
print(' }', file=header) print(' }', file=header)

View File

@ -26,6 +26,7 @@ set(test_serializer_names
CustomQuery CustomQuery
From From
In In
Insert
Where Where
) )

View File

@ -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 <sqlpp11/sqlpp11.h>
#include <iostream>
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;
}

View File

@ -130,6 +130,12 @@ int Prepared(int, char* [])
std::cerr << x.alpha << std::endl; 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 // 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 auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or