mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 12:40:40 -06:00
ddl2cpp command line argument for custom types (#491)
* ddl2cpp command line argument for custom types - Updated the ddl2cpp script to allow custom/extended types through external csv file - Had to re-order the script to allow the command line to be parsed before setting up the parser - Updated README * Test for the command line argument - Script test only for now * Test the custom type argument - Firs a negative test - Last a positive test and compile test against the generated output * Expand the test - Ensure built in types still work - Check capitilisation - Ensure more than one custom works - Check type with spaces --------- Co-authored-by: Carel Combrink <carel.combrink@vastech.co.za>
This commit is contained in:
@@ -84,5 +84,30 @@ if (${Python3_Interpreter_FOUND})
|
||||
"${sqlpp.scripts.generated.sample.include}.h")
|
||||
target_link_libraries(sqlpp.scripts.compiled.${sample_name} PRIVATE sqlpp11)
|
||||
endforeach()
|
||||
|
||||
set(custom_type_sql "ddl2cpp_sample_good_custom_type")
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_test(NAME sqlpp11.scripts.ddl2cpp.bad_custom_types
|
||||
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/../../scripts/ddl2cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/${custom_type_sql}.sql"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/fail"
|
||||
test)
|
||||
set_tests_properties(sqlpp11.scripts.ddl2cpp.bad_custom_types PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "Error: unsupported datatypes.")
|
||||
|
||||
set(sqlpp.scripts.generated.custom_type_sql.include "${CMAKE_CURRENT_BINARY_DIR}/${custom_type_sql}")
|
||||
add_custom_command(
|
||||
OUTPUT "${sqlpp.scripts.generated.custom_type_sql.include}.h"
|
||||
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/../../scripts/ddl2cpp"
|
||||
"--datatype-file=${CMAKE_CURRENT_LIST_DIR}/custom_types.csv"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/${custom_type_sql}.sql"
|
||||
"${sqlpp.scripts.generated.custom_type_sql.include}"
|
||||
test
|
||||
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/${custom_type_sql}.sql"
|
||||
VERBATIM)
|
||||
|
||||
add_executable(sqlpp.scripts.compiled.${custom_type_sql} ${custom_type_sql}.cpp
|
||||
"${sqlpp.scripts.generated.custom_type_sql.include}.h")
|
||||
target_link_libraries(sqlpp.scripts.compiled.${custom_type_sql} PRIVATE sqlpp11)
|
||||
endif()
|
||||
endif()
|
||||
9
tests/scripts/custom_types.csv
Normal file
9
tests/scripts/custom_types.csv
Normal file
@@ -0,0 +1,9 @@
|
||||
Boolean, CustomBooleanType
|
||||
Integer, CustomIntegerType, SPECIAL INT
|
||||
Serial, CustomSerialType
|
||||
FloatingPoint, CustomFloatingPointType
|
||||
Text, CustomTextType, another_text_type
|
||||
Blob, CustomBlobType
|
||||
Date, CustomDateType
|
||||
DateTime, CustomDateTimeType
|
||||
Time, CustomTimeType
|
||||
|
32
tests/scripts/ddl2cpp_sample_good_custom_type.cpp
Normal file
32
tests/scripts/ddl2cpp_sample_good_custom_type.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#include <sqlpp11/chrono.h>
|
||||
#include <ddl2cpp_sample_good_custom_type.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
test::TabFoo tab_foo;
|
||||
tab_foo.myBoolean = true;
|
||||
tab_foo.myInteger = 5;
|
||||
tab_foo.mySerial = 10;
|
||||
tab_foo.myFloatingPoint = 12.34;
|
||||
tab_foo.myText = "test";
|
||||
tab_foo.myBlob = "blob";
|
||||
tab_foo.myDate = sqlpp::chrono::day_point{};
|
||||
tab_foo.myDateTime = std::chrono::system_clock::now();
|
||||
tab_foo.myTime = std::chrono::seconds{10};
|
||||
// Special cases
|
||||
tab_foo.mySecondText = "another text";
|
||||
tab_foo.myTypeWithSpaces = 20;
|
||||
// Capitalisation
|
||||
tab_foo.capBoolean = false;
|
||||
// Build in types
|
||||
tab_foo.builtinBoolean = true;
|
||||
tab_foo.builtinInteger = 5;
|
||||
tab_foo.builtinSerial = 10;
|
||||
tab_foo.builtinFloatingPoint = 12.34;
|
||||
tab_foo.builtinText = "test";
|
||||
tab_foo.builtinBlob = "blob";
|
||||
tab_foo.builtinDate = sqlpp::chrono::day_point{};
|
||||
tab_foo.builtinDateTime = std::chrono::system_clock::now();
|
||||
tab_foo.builtinTime = std::chrono::seconds{10};
|
||||
}
|
||||
54
tests/scripts/ddl2cpp_sample_good_custom_type.sql
Normal file
54
tests/scripts/ddl2cpp_sample_good_custom_type.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2015, 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.
|
||||
*/
|
||||
|
||||
CREATE TABLE tab_foo
|
||||
(
|
||||
myBoolean CustomBooleanType,
|
||||
myInteger CustomIntegerType,
|
||||
mySerial CustomSerialType,
|
||||
myFloatingPoint CustomFloatingPointType,
|
||||
myText CustomTextType,
|
||||
myBlob CustomBlobType,
|
||||
myDate CustomDateType,
|
||||
myDateTime CustomDateTimeType,
|
||||
myTime CustomTimeType,
|
||||
-- Some more special cases
|
||||
mySecondText another_text_type,
|
||||
myTypeWithSpaces SPECIAL INT,
|
||||
-- Checking capitalisation of types
|
||||
capBoolean CUSTOMBOOLEANTYPE,
|
||||
-- Ensuring built in types still function
|
||||
builtinBoolean BOOLEAN,
|
||||
builtinInteger INTEGER,
|
||||
builtinSerial SERIAL,
|
||||
builtinFloatingPoint NUMERIC,
|
||||
builtinText TEXT,
|
||||
builtinBlob BINARY,
|
||||
builtinDate DATE,
|
||||
builtinDateTime TIMESTAMPTZ,
|
||||
builtinTime TIME WITH TIME ZONE
|
||||
|
||||
) WITH SYSTEM VERSIONING; -- enable System-Versioning for this table
|
||||
Reference in New Issue
Block a user