Skip to content

fix sequence points between getting text and its length #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ enable_testing()
add_library (sqlite_modern_cpp INTERFACE)
target_include_directories(sqlite_modern_cpp INTERFACE hdr/)

add_executable(tests ${TEST_SOURCES})
target_include_directories(tests INTERFACE ${SQLITE3_INCLUDE_DIRS})
add_executable(tests_runner ${TEST_SOURCES})
target_include_directories(tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS})
if(ENABLE_SQLCIPHER_TESTS)
target_link_libraries(tests Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
else()
target_link_libraries(tests Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
endif()

catch_discover_tests(tests)
target_compile_options(tests PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> )
catch_discover_tests(tests_runner)
target_compile_options(tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> )

# Place the file in the source directory, permitting us to place a single configuration file for YCM there.
# YCM is the code-completion engine for (neo)vim https://github.com/Valloric/YouCompleteMe
Expand Down
41 changes: 28 additions & 13 deletions hdr/sqlite_modern_cpp/type_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,25 @@ namespace sqlite {
}

// Convert char* to string_view to trigger op<<(..., const str_ref )
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char(&STR)[N]) {
return sqlite3_bind_text(stmt, inx, &STR[0], N-1, SQLITE_TRANSIENT);
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char(&STR)[N]) {
return sqlite3_bind_text(stmt, inx, &STR[0], N-1, SQLITE_TRANSIENT);
}

inline std::string get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<std::string>) {
return sqlite3_column_type(stmt, inx) == SQLITE_NULL ? std::string() :
std::string(reinterpret_cast<char const *>(sqlite3_column_text(stmt, inx)), sqlite3_column_bytes(stmt, inx));
if ( sqlite3_column_type(stmt, inx) == SQLITE_NULL ) {
return std::string();
}
char const * ptr = reinterpret_cast<char const *>(sqlite3_column_text(stmt, inx));
// call sqlite3_column_text explicitely before sqlite3_column_bytes: it may convert the value to text
return std::string(ptr, sqlite3_column_bytes(stmt, inx));
}
inline std::string get_val_from_db(sqlite3_value *value, result_type<std::string >) {
return sqlite3_value_type(value) == SQLITE_NULL ? std::string() :
std::string(reinterpret_cast<char const *>(sqlite3_value_text(value)), sqlite3_value_bytes(value));
inline std::string get_val_from_db(sqlite3_value *value, result_type<std::string>) {
if ( sqlite3_value_type(value) == SQLITE_NULL ) {
return std::string();
}
char const * ptr = reinterpret_cast<char const *>(sqlite3_value_text(value));
// call sqlite3_column_text explicitely before sqlite3_column_bytes: it may convert the value to text
return std::string(ptr, sqlite3_value_bytes(value));
}

inline void store_result_in_db(sqlite3_context* db, str_ref val) {
Expand All @@ -222,12 +230,19 @@ namespace sqlite {
}

inline std::u16string get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<std::u16string>) {
return sqlite3_column_type(stmt, inx) == SQLITE_NULL ? std::u16string() :
std::u16string(reinterpret_cast<char16_t const *>(sqlite3_column_text16(stmt, inx)), sqlite3_column_bytes16(stmt, inx));
if ( sqlite3_column_type(stmt, inx) == SQLITE_NULL ) {
return std::u16string();
}
char16_t const * ptr = reinterpret_cast<char16_t const *>(sqlite3_column_text16(stmt, inx));
// call sqlite3_column_text16 explicitely before sqlite3_column_bytes16: it may convert the value to text
return std::u16string(ptr, sqlite3_column_bytes16(stmt, inx));
}
inline std::u16string get_val_from_db(sqlite3_value *value, result_type<std::u16string>) {
return sqlite3_value_type(value) == SQLITE_NULL ? std::u16string() :
std::u16string(reinterpret_cast<char16_t const *>(sqlite3_value_text16(value)), sqlite3_value_bytes16(value));
if ( sqlite3_value_type(value) == SQLITE_NULL ) {
return std::u16string();
}
char16_t const * ptr = reinterpret_cast<char16_t const *>(sqlite3_value_text16(value));
return std::u16string(ptr, sqlite3_value_bytes16(value));
}

inline void store_result_in_db(sqlite3_context* db, u16str_ref val) {
Expand Down Expand Up @@ -273,16 +288,16 @@ namespace sqlite {
if(sqlite3_column_type(stmt, inx) == SQLITE_NULL) {
return {};
}
int bytes = sqlite3_column_bytes(stmt, inx);
T const* buf = reinterpret_cast<T const *>(sqlite3_column_blob(stmt, inx));
int bytes = sqlite3_column_bytes(stmt, inx);
return std::vector<T, A>(buf, buf + bytes/sizeof(T));
}
template<typename T, typename A> inline std::vector<T, A> get_val_from_db(sqlite3_value *value, result_type<std::vector<T, A>>) {
if(sqlite3_value_type(value) == SQLITE_NULL) {
return {};
}
int bytes = sqlite3_value_bytes(value);
T const* buf = reinterpret_cast<T const *>(sqlite3_value_blob(value));
int bytes = sqlite3_value_bytes(value);
return std::vector<T, A>(buf, buf + bytes/sizeof(T));
}

Expand Down