Skip to content

Commit

Permalink
fix: fixed dbsync segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
nbertoldo committed Aug 29, 2024
1 parent ebb64b4 commit 92bda1d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/common/dbsync/src/sqlite/isqlite_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <math.h>
#include "db_exception.h"

namespace SQLite
namespace SQLiteLegacy
{
const constexpr auto MAX_ROWS_ERROR_STRING {"Too Many Rows."};

Expand Down Expand Up @@ -90,4 +90,4 @@ namespace SQLite

};

}//namespace SQLite
}//namespace SQLiteLegacy
12 changes: 6 additions & 6 deletions src/common/dbsync/src/sqlite/sqlite_dbengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ ColumnType SQLiteDBEngine::columnTypeName(const std::string& type)
return retVal;
}

bool SQLiteDBEngine::bindJsonData(const std::shared_ptr<SQLite::IStatement> stmt,
bool SQLiteDBEngine::bindJsonData(const std::shared_ptr<SQLiteLegacy::IStatement> stmt,
const ColumnData& cd,
const nlohmann::json::value_type& valueType,
const unsigned int cid)
Expand Down Expand Up @@ -987,7 +987,7 @@ bool SQLiteDBEngine::getPrimaryKeysFromTable(const std::string& table,
return retVal;
}

void SQLiteDBEngine::getTableData(std::shared_ptr<SQLite::IStatement>const stmt,
void SQLiteDBEngine::getTableData(std::shared_ptr<SQLiteLegacy::IStatement>const stmt,
const int32_t index,
const ColumnType& type,
const std::string& fieldName,
Expand Down Expand Up @@ -1228,7 +1228,7 @@ void SQLiteDBEngine::deleteRowsbyPK(const std::string& table,
}
}

void SQLiteDBEngine::bindFieldData(const std::shared_ptr<SQLite::IStatement> stmt,
void SQLiteDBEngine::bindFieldData(const std::shared_ptr<SQLiteLegacy::IStatement> stmt,
const int32_t index,
const TableField& fieldData)
{
Expand Down Expand Up @@ -1983,14 +1983,14 @@ void SQLiteDBEngine::getFieldValueFromTuple(const Field& value,
}
}

std::shared_ptr<SQLite::IStatement>const SQLiteDBEngine::getStatement(const std::string& sql)
std::shared_ptr<SQLiteLegacy::IStatement>const SQLiteDBEngine::getStatement(const std::string& sql)
{
std::lock_guard<std::mutex> lock(m_stmtMutex);
const auto it
{
std::find_if(m_statementsCache.begin(),
m_statementsCache.end(),
[sql](const std::pair<std::string, std::shared_ptr<SQLite::IStatement>>& pair)
[sql](const std::pair<std::string, std::shared_ptr<SQLiteLegacy::IStatement>>& pair)
{
return 0 == pair.first.compare(sql);
})
Expand Down Expand Up @@ -2139,7 +2139,7 @@ void SQLiteDBEngine::updateTableRowCounter(const std::string& table, const long
{
if (it->second.currentRows + rowModifyCount > it->second.maxRows)
{
throw DbSync::max_rows_error { SQLite::MAX_ROWS_ERROR_STRING };
throw DbSync::max_rows_error { SQLiteLegacy::MAX_ROWS_ERROR_STRING };
}

it->second.currentRows += rowModifyCount;
Expand Down
14 changes: 7 additions & 7 deletions src/common/dbsync/src/sqlite/sqlite_dbengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class SQLiteDBEngine final : public DbSync::IDbEngine

ColumnType columnTypeName(const std::string& type);

bool bindJsonData(const std::shared_ptr<SQLite::IStatement> stmt,
bool bindJsonData(const std::shared_ptr<SQLiteLegacy::IStatement> stmt,
const ColumnData& cd,
const nlohmann::json::value_type& valueType,
const unsigned int cid);
Expand Down Expand Up @@ -222,13 +222,13 @@ class SQLiteDBEngine final : public DbSync::IDbEngine
void deleteRowsbyPK(const std::string& table,
const nlohmann::json& data);

void getTableData(std::shared_ptr<SQLite::IStatement>const stmt,
void getTableData(std::shared_ptr<SQLiteLegacy::IStatement>const stmt,
const int32_t index,
const ColumnType& type,
const std::string& fieldName,
Row& row);

void bindFieldData(const std::shared_ptr<SQLite::IStatement> stmt,
void bindFieldData(const std::shared_ptr<SQLiteLegacy::IStatement> stmt,
const int32_t index,
const TableField& fieldData);

Expand Down Expand Up @@ -295,7 +295,7 @@ class SQLiteDBEngine final : public DbSync::IDbEngine

SQLiteDBEngine& operator=(const SQLiteDBEngine&) = delete;

std::shared_ptr<SQLite::IStatement>const getStatement(const std::string& sql);
std::shared_ptr<SQLiteLegacy::IStatement>const getStatement(const std::string& sql);

std::string getSelectAllQuery(const std::string& table,
const TableColumns& tableFields) const;
Expand All @@ -316,11 +316,11 @@ class SQLiteDBEngine final : public DbSync::IDbEngine
const std::function<void()> callback = {});

Utils::MapWrapperSafe<std::string, TableColumns> m_tableFields;
std::deque<std::pair<std::string, std::shared_ptr<SQLite::IStatement>>> m_statementsCache;
std::deque<std::pair<std::string, std::shared_ptr<SQLiteLegacy::IStatement>>> m_statementsCache;
const std::shared_ptr<ISQLiteFactory> m_sqliteFactory;
std::shared_ptr<SQLite::IConnection> m_sqliteConnection;
std::shared_ptr<SQLiteLegacy::IConnection> m_sqliteConnection;
std::mutex m_stmtMutex;
std::unique_ptr<SQLite::ITransaction> m_transaction;
std::unique_ptr<SQLiteLegacy::ITransaction> m_transaction;
std::mutex m_maxRowsMutex;
std::map<std::string, MaxRows> m_maxRows;
};
Expand Down
4 changes: 2 additions & 2 deletions src/common/dbsync/src/sqlite/sqlite_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ constexpr auto DB_PERMISSIONS
0640
};

using namespace SQLite;
using namespace SQLiteLegacy;
using ExpandedSQLPtr = std::unique_ptr<char, CustomDeleter<decltype(&sqlite3_free), sqlite3_free>>;

static void checkSqliteResult(const int result,
Expand Down Expand Up @@ -271,7 +271,7 @@ std::string Statement::expand()

std::unique_ptr<IColumn> Statement::column(const int32_t index)
{
return std::make_unique<SQLite::Column>(m_stmt, index);
return std::make_unique<SQLiteLegacy::Column>(m_stmt, index);
}

int Statement::columnsCount() const
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/src/sqlite/sqlite_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <string>
#include <memory>
namespace SQLite
namespace SQLiteLegacy
{
class Connection : public IConnection
{
Expand Down
18 changes: 9 additions & 9 deletions src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ISQLiteFactory
// LCOV_EXCL_START
virtual ~ISQLiteFactory() = default;
// LCOV_EXCL_STOP
virtual std::shared_ptr<SQLite::IConnection> createConnection(const std::string& path) = 0;
virtual std::unique_ptr<SQLite::ITransaction> createTransaction(std::shared_ptr<SQLite::IConnection>& connection) = 0;
virtual std::unique_ptr<SQLite::IStatement> createStatement(std::shared_ptr<SQLite::IConnection>& connection,
virtual std::shared_ptr<SQLiteLegacy::IConnection> createConnection(const std::string& path) = 0;
virtual std::unique_ptr<SQLiteLegacy::ITransaction> createTransaction(std::shared_ptr<SQLiteLegacy::IConnection>& connection) = 0;
virtual std::unique_ptr<SQLiteLegacy::IStatement> createStatement(std::shared_ptr<SQLiteLegacy::IConnection>& connection,
const std::string& query) = 0;
};

Expand All @@ -36,19 +36,19 @@ class SQLiteFactory : public ISQLiteFactory
SQLiteFactory(const SQLiteFactory&) = delete;
SQLiteFactory& operator=(const SQLiteFactory&) = delete;

std::shared_ptr<SQLite::IConnection> createConnection(const std::string& path) override
std::shared_ptr<SQLiteLegacy::IConnection> createConnection(const std::string& path) override
{
return std::make_shared<SQLite::Connection>(path);
return std::make_shared<SQLiteLegacy::Connection>(path);
}
std::unique_ptr<SQLite::ITransaction> createTransaction(std::shared_ptr<SQLite::IConnection>& connection) override
std::unique_ptr<SQLiteLegacy::ITransaction> createTransaction(std::shared_ptr<SQLiteLegacy::IConnection>& connection) override
{
return std::make_unique<SQLite::Transaction>(connection);
return std::make_unique<SQLiteLegacy::Transaction>(connection);
}

std::unique_ptr<SQLite::IStatement> createStatement(std::shared_ptr<SQLite::IConnection>& connection,
std::unique_ptr<SQLiteLegacy::IStatement> createStatement(std::shared_ptr<SQLiteLegacy::IConnection>& connection,
const std::string& query) override
{
return std::make_unique<SQLite::Statement>(connection, query);
return std::make_unique<SQLiteLegacy::Statement>(connection, query);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/tests/sqlite/sqlite_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SQLiteTest::TearDown()
};
using ::testing::_;
using ::testing::Return;
using namespace SQLite;
using namespace SQLiteLegacy;
using namespace DbSync;

class ConnectionWrapper: public IConnection
Expand Down
8 changes: 4 additions & 4 deletions src/common/sqliteWrapper/include/sqliteWrapperTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ constexpr auto DB_PERMISSIONS
};


namespace SQLite
namespace SQLiteLegacy
{
const constexpr auto MAX_ROWS_ERROR_STRING {"Too Many Rows."};

Expand Down Expand Up @@ -188,9 +188,9 @@ namespace SQLite

};

}//namespace SQLite
}//namespace SQLiteLegacy

using namespace SQLite;
using namespace SQLiteLegacy;
using ExpandedSQLPtr = std::unique_ptr<char, CustomDeleter<decltype(&sqlite3_free), sqlite3_free>>;

static void checkSqliteResult(const int result,
Expand Down Expand Up @@ -228,7 +228,7 @@ static sqlite3_stmt* prepareSQLiteStatement(std::shared_ptr<IConnection>& connec
return pStatement;
}

namespace SQLite
namespace SQLiteLegacy
{
class Connection : public IConnection
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/include/modules.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

int modulesExec();
void modulesExec();
3 changes: 1 addition & 2 deletions src/modules/src/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace std;

int modulesExec() {
void modulesExec() {
ModuleManager moduleManager;
Configuration config;
bool running{true};
Expand All @@ -20,5 +20,4 @@ int modulesExec() {

moduleManager.stop();

return 0;
}
4 changes: 4 additions & 0 deletions src/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
{
"name": "lua",
"version": "5.3.5#6"
},
{
"name": "sqlite3",
"version": "3.45.0#0"
}
]
}

0 comments on commit 92bda1d

Please sign in to comment.