Skip to content

Commit

Permalink
Поправил сборку и тесты под Linux.
Browse files Browse the repository at this point in the history
Оптимизировал проверку колонок на преобразование даты.
  • Loading branch information
orefkov committed Oct 5, 2022
1 parent 14cee0e commit 3b472e3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ elseif(UNIX)
set (CMAKE_CXX_FLAGS "${V8SQLITE_CXX_CLANG_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${V8SQLITE_C_CLANG_FLAGS}")
set (CMAKE_CXX_FLAGS_RELEASE "${V8SQLITE_CXX_CLANG_RELEASE}")
set (CMAKE_CXX_FLAGS_DEBUG "${V8SQLITE_CXX_CLANG_DEBUG}")
set (CMAKE_CXX_FLAGS_DEBUG "${V8SQLITE_CXX_CLANG_DEBUG} -g")
set (CMAKE_C_FLAGS_RELEASE "${V8SQLITE_CXX_CLANG_RELEASE}")
set (CMAKE_C_FLAGS_DEBUG "${V8SQLITE_CXX_FLAGS_DEBUG}")

if (CMAKE_BUILD_TYPE STREQUAL Debug)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${V8SQLITE_CXX_CLANG_DEBUG}")
else ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${V8SQLITE_CXX_CLANG_RELEASE}")
endif ()

endif()

# Set static runtime library
Expand Down
10 changes: 9 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/projects/$ms{projectDirName}",
"copySourcesOptions": { "exclusionList": [ ".vs", ".git", "out", "_build", "1C" ] }
"copySourcesOptions": {
"exclusionList": [
".vs",
".git",
"out",
"_build",
"1C"
]
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
cmake_minimum_required (VERSION 3.15)
add_executable(testv8sqlite test_addin_base.cpp ../addin_base.cpp test_sqlite.cpp ../sqlite.cpp ../sqlite3_unicode.c)
target_include_directories(testv8sqlite PRIVATE "..")
add_compile_definitions(BUILD_TESTS)
add_compile_definitions(BUILD_TESTS SQLITE_CORE SQLITE_ENABLE_UNICODE)
add_dependencies(testv8sqlite core_as_str)
target_link_libraries(testv8sqlite sqlite3 core_as_str gtest_main)
add_test(NAME testv8sqlite COMMAND testv8sqlite)
5 changes: 5 additions & 0 deletions src/tests/test_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ TEST(Sqlite, CreateBase) {

TEST(Sqlite, ErrorCreateBase) {
SqliteBase base;
#ifdef _WIN32
EXPECT_FALSE(base.open(u"c:\\nul\\com"));
#else
EXPECT_FALSE(base.open(u"/sys"));
#endif
EXPECT_EQ(base.lastError(), u"unable to open database file");
EXPECT_FALSE(base.isOpen());
}
Expand Down Expand Up @@ -101,6 +105,7 @@ struct SimpleResultReceiver {
value& operator=(value other) {
this->~value();
new (this) value(std::move(other));
return *this;
}

stringa& blob() {
Expand Down
Binary file modified src/tests/v8sqlite.epf
Binary file not shown.
22 changes: 12 additions & 10 deletions src/v8sqlite_addin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,20 @@ bool V8SqliteAddin::BindParam(tVariant* params, unsigned count) {

struct ToTextReceiver {
chunked_string_concatenator<u16symbol>& vtText;
hashStrMapUIU<int> datesColumns;
std::unordered_set<int> dates;
hashStrMapUIU<int>& datesColumns;
std::vector<char> dates;
unsigned currentCol{0};
unsigned colCount{0};
int error{0};

void doSetColCount(unsigned cc) {
colCount = cc;
dates.resize(colCount, 0);
}

void checkColumnForDates(ssu colName) {
if (datesColumns.find(colName) != datesColumns.end()) {
dates.insert(currentCol);
dates[currentCol] = 1;
}
}

Expand All @@ -172,7 +177,7 @@ struct ValueTableReceiver : ToTextReceiver {
unsigned startOfRowCount = 0;

void setColumnCount(unsigned cc) {
colCount = cc;
doSetColCount(cc);
vtText << (eeu & u"{\"#\",acf6192e-81ca-46ef-93a6-5a6968b78663,{9,{" & cc & u",");
}

Expand Down Expand Up @@ -220,7 +225,7 @@ struct ValueTableReceiver : ToTextReceiver {
currentCol++;
}
void addText(ssu v) {
if (dates.size() && dates.contains(currentCol) && v.len == 19) {
if (dates[currentCol] && v.len == 19) {
vtText << (eeu & u"{\"D\"," & v(0, 4) & v(5, 2) & v(8, 2) & v(11, 2) & v(14, 2) & v(17, 2) & u"},");
} else {
vtText << (eeu & u"{\"S\",\"" & e_repl(v, u"\"", u"\"\"") & u"\"},");
Expand Down Expand Up @@ -258,7 +263,7 @@ struct JsonReceiver : ToTextReceiver {
void fixAnswer(WCHAR_T* answer) {}

void setColumnCount(unsigned cc) {
colCount = cc;
doSetColCount(cc);
vtText << uR"({"#type":"jv8:Array","#value":[{"#type":"jv8:Array","#value":[)";
}

Expand Down Expand Up @@ -293,7 +298,7 @@ struct JsonReceiver : ToTextReceiver {
addDelim();
}
void addText(ssu v) {
if (dates.size() && dates.contains(currentCol) && v.len == 19) {
if (dates[currentCol] && v.len == 19) {
vtText << (eeu & uR"({"#type":"jxs:dateTime","#value":")" & v(0, 10) & u'T' & v(11) & u"\"}");
} else {
vtText << (eeu & uR"({"#type":"jxs:string","#value":")" & expr_json_str(v) & u"\"}");
Expand Down Expand Up @@ -383,9 +388,6 @@ bool V8SqliteAddin::ExecQuery(tVariant& retVal, tVariant* params, unsigned count
}

bool V8SqliteAddin::RemoveQuery(tVariant* params, unsigned count) {
if (!db_.isOpen()) {
return error(u"База данных не открыта", u"Database not opened");
}
if (params[0].vt != VTYPE_PWSTR) {
return error(u"Первый параметр должен быть строкой", u"First param must be string");
}
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define F_VERSION 1,0,0,0
#define P_VERSION "1.0.0.0"
#define F_VERSION 1,0,0,1
#define P_VERSION "1.0.0.1"
#define COPY_RIGHT "© Àëåêñàíäð Îðåôêîâ, 2022"

0 comments on commit 3b472e3

Please sign in to comment.