Skip to content
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

Statement value #24

Merged
merged 8 commits into from
Aug 18, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CTestTestfile.cmake
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
.fleet

# Gradle
.idea/**/gradle.xml
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ option(WINTER_WITH_MARIADB "Enable building MARIADB" OFF)
option(WINTER_WITH_MYSQL "Enable building MYSQL" OFF)
option(WINTER_WITH_REDIS "Enable building REDIS" OFF)


# Set a default build type if none was specified
set(default_build_type "Release")

Expand Down
2 changes: 1 addition & 1 deletion cmake/dep_gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
GIT_TAG v1.14.0
SOURCE_DIR ${THIRD_PARTY_DIR}/googletest
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/dep_openssl_system.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ if ( OPENSSL_FOUND )
endif()

#target_link_libraries(${YOUR_TARGET_HERE} ${OPENSSL_LIBRARIES})
set(WINTER_OPENSSL_LIB -lssl -lcrypto)
set(WINTER_OPENSSL_LIB ${OPENSSL_LIBRARIES})
1 change: 1 addition & 0 deletions wintercpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(_LIBCPP_INLINE_VISIBILITY "")
set(CMAKE_OPTIMIZE_DEPENDENCIES TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(APP_ENV "APP_ENV" local)
message("***************************** ENVIRONMENT IS ${APP_ENV} **************************************")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ namespace winter::data::sql_impl {
*/
const std::string &name() const;

/**
* @brief returns the full name of the column example tableName.columnName
* @return std::string
*/
std::string FullName() const;

/**
* @brief returns the datatype this column represents
* @return const FieldType
Expand Down

This file was deleted.

85 changes: 57 additions & 28 deletions wintercpp/include/wintercpp/data/sql/field/winter_data_sql_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,74 @@
#ifndef WINTER_DATA_SQL_FIELD
#define WINTER_DATA_SQL_FIELD

#include <wintercpp/data/sql/field/winter_data_sql_abstract_field.h>
#include <wintercpp/data/sql/field/winter_data_sql_data_type.h>
#include <wintercpp/data/sql/field/winter_data_sql_field_type.h>

namespace winter::data::sql_impl {

template<typename T>
class Field : public virtual AbstractField {
/**
* @brief Field class
* This class represents a field in a table.
* It contains the name of the field, the value and the type.
* It inherits from AbstractField.
* @tparam DataType
* @tparam FieldType
* @tparam name
*/
class Field {
public:
explicit Field(T value) :
value_(std::move(value)), type_(TypeField<T>::Get()) {}

Field(std::string name, T value) :
name_(std::move(name)), value_(std::move(value)),
type_(TypeField<T>::Get()) {}

Field(const Field &field) :
value_(field.value_), type_(field.type_), name_(field.name_) {}

explicit Field(const Field *field) :
value_(field->value_), type_(field->type_), name_(field->name_) {}

const T &value() const;

const FieldType &type() const override;

const std::string &name() const override;

void value(T value);

~Field() override = default;
explicit Field(const DataType& value) :
value_(value) {
type_ = GetFieldType(value);
}

Field(const std::string& name, const DataType& value) :
name_(name), value_(value) {
type_ = GetFieldType(value);
}

Field(const Field& field) :
name_(field.name_), value_(field.value_), type_(field.type_) {}

explicit Field(const Field* field) :
name_(field->name_), value_(field->value_), type_(field->type_) {}

/**
* @brief returns the value of the field.
*
* @return const DataType&
*/
const DataType& value() const;

/**
* @brief Returns the type of the field.
*
* @return const FieldType&
*/
const FieldType& type() const;

/**
* @brief Returns the name of the field.
*
* @return const std::string&
*/
const std::string& name() const;

/**
* @brief Sets the value of the field.
*
* @param value
*/
void value(DataType value);

//~Field() = default;

protected:
std::string name_;
T value_;
DataType value_;
FieldType type_;
};

} // namespace winter::data::sql_impl

#include "winter_data_sql_field.tpp"

#endif /* WINTER_DATA_SQL_FIELD */

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
#ifndef WINTER_DATA_SQL_FIELD_TYPE
#define WINTER_DATA_SQL_FIELD_TYPE

#include <iostream>
#include <optional>
#include <string>

#include "wintercpp/data/sql/field/winter_data_sql_data_type.h"
#include "wintercpp/exception/generic/winter_internal_exception.h"

namespace winter::data::sql_impl {

struct Date {
Expand Down Expand Up @@ -141,6 +146,79 @@ namespace winter::data::sql_impl {
static FieldType Get();
};

/**
* @brief Get the FieldType for a given type T.
*
* This template function returns the FieldType corresponding to the input type T. It uses
* compile-time type checking with std::is_same_v to determine the FieldType. If the input
* type T is not supported, it throws an exception of type exception::WinterInternalException.
*
* @tparam T The input type for which to get the FieldType.
* @return The FieldType corresponding to the input type T.
* @throws exception::WinterInternalException if the input type T is not supported.
*/
template<typename T>
FieldType GetFieldType() {
if constexpr (std::is_same_v<T, uint8_t>) {
return FieldType::kUchar;
} else if constexpr (std::is_same_v<T, uint16_t>) {
return FieldType::kUshort;
} else if constexpr (std::is_same_v<T, uint32_t>) {
return FieldType::KUint;
} else if constexpr (std::is_same_v<T, uint64_t>) {
return FieldType::kBigInt;
} else if constexpr (std::is_same_v<T, int8_t>) {
return FieldType::kSchar;
} else if constexpr (std::is_same_v<T, int16_t>) {
return FieldType::KShort;
} else if constexpr (std::is_same_v<T, int32_t>) {
return FieldType::kInt;
} else if constexpr (std::is_same_v<T, int64_t>) {
return FieldType::kLong;
} else if constexpr (std::is_same_v<T, char>) {
return FieldType::kChar;
} else if constexpr (std::is_same_v<T, short>) {
return FieldType::KShort;
} else if constexpr (std::is_same_v<T, long>) {
return FieldType::kLong;
} else if constexpr (std::is_same_v<T, long double>) {
return FieldType::KDecimal;
} else if constexpr (std::is_same_v<T, double>) {
return FieldType::kDouble;
} else if constexpr (std::is_same_v<T, float>) {
return FieldType::kFloat;
} else if constexpr (std::is_same_v<T, bool>) {
return FieldType::kBoolean;
} else if constexpr (std::is_same_v<T, std::string>) {
return FieldType::kString;
} else if constexpr (std::is_same_v<T, std::istream *>) {
return FieldType::kBlob;
} else if constexpr (std::is_same_v<T, nullptr_t>) {
return FieldType::kNull;
} else if constexpr (std::is_same_v<T, std::nullopt_t>) {
return FieldType::kNull;
} else {
throw exception::WinterInternalException("Type not supported");
}
}

/**
* @brief Get the FieldType for a given variant variable.
*
* This inline function uses std::visit to extract the type of the variant variable and then calls
* the GetFieldType<T>() template function to get the corresponding FieldType. It returns the FieldType.
*
* @param dataType The variant variable for which to get the FieldType.
* @return The FieldType corresponding to the type of the variant variable.
*/
inline FieldType GetFieldType(const DataType &dataType) {
return std::visit([](const auto &value) {
using T = std::decay_t<decltype(value)>;
return GetFieldType<T>();
},
dataType);
}

} // namespace winter::data::sql_impl

#endif /* WINTER_DATA_SQL_FIELD_TYPE */
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@
#define WINTER_DATA_SQL_FUNCTION_MIN

#include <wintercpp/data/sql/column/winter_data_sql_column.h>
#include <wintercpp/data/sql/field/winter_data_sql_field_type.h>
#include <wintercpp/data/sql/preparedstatement/winter_data_sql_prepared_statement.h>
#include <wintercpp/data/sql/preparedstatement/winter_data_sql_prepared_statement_field.h>
#include <wintercpp/data/sql/statement/clause/winter_data_sql_clause.h>
#include <wintercpp/data/sql/statement/clause/winter_data_sql_clause_operator.h>
#include <wintercpp/data/sql/statement/clause/winter_data_sql_clause_predicate.h>
#include <wintercpp/data/sql/statement/winter_data_sql_statement_values.h>

#include <queue>
#include <string>

#include "wintercpp/data/sql/field/winter_data_sql_field_type.h"
#include "wintercpp/data/sql/preparedstatement/winter_data_sql_prepared_statement.h"

namespace winter::data::sql_impl {

class Min : public virtual Clause {
public:
explicit Min(StatementValues column);
explicit Min(const StatementValue &statement_value);
virtual ~Min() = default;

PreparedStatement Prepare() override;
std::string Query() const override;
std::vector<PreparedStatementField> Fields() const override;

// PreparedStatement Prepare() override;

std::string name() override;
std::string name() const;

FieldType fieldType() override;
// FieldType fieldType() override;

private:
const StatementValues column_;
const std::shared_ptr<AbstractPreparedStatementField> field_;
const bool is_predicate_ = false;
const StatementValue statement_value_;
// const PreparedStatementField field_;
const std::string query_template_ = "MIN($min) AS min_$columnName";
const std::string query_param_ = "$min";
};

} // namespace winter::data::sql_impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void DataBaseMigration<TConnectionType, TTransactionType>::execute() {
std::to_string(migration.HASH_256())))
>> transaction;*/
auto columnFound = Column(*migration_table_, "found", FieldType::kBoolean);
auto columns = std::vector<sql_impl::StatementValues> {columnFound};
auto columns = std::vector<sql_impl::StatementValue> {columnFound};
auto response = Select(ss.str()) << columns >> transaction;
auto resultRow = response.RequireSingleOrNullopt();
// resultRow->AddRow("name");
Expand Down

This file was deleted.

Loading