Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
8 changes: 4 additions & 4 deletions lib/src/HttpResponseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
private:
bool allowCompression_{true};

void setAllowCompression(bool allow) override;

bool allowCompression() const override;

void setBody(const char *body, size_t len) override
{
bodyPtr_ = std::make_shared<HttpMessageStringViewBody>(body, len);
Expand All @@ -478,6 +474,10 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
}
}

void setAllowCompression(bool allow) override;

bool allowCompression() const override;

void setContentTypeCodeAndCustomString(ContentType type,
const char *typeString,
size_t typeStringLength) override
Expand Down
29 changes: 29 additions & 0 deletions orm_lib/inc/drogon/orm/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,35 @@ class DROGON_EXPORT Field
return result_.getLength(row_, column_);
}

SqlFieldType sqlType() const noexcept
{
return result_.getSqlType(column_);
}

/// SQL type name (VARCHAR, INT, DECIMAL, etc.)
const std::string &typeName() const noexcept
{
return result_.getTypeName(column_);
}

/// Character length (VARCHAR)
int columnLength() const noexcept
{
return result_.getColumnLength(column_);
}

/// Numeric precision (DECIMAL / NUMERIC)
int precision() const noexcept
{
return result_.getPrecision(column_);
}

/// Numeric scale (DECIMAL / NUMERIC)
int scale() const noexcept
{
return result_.getScale(column_);
}

/// Convert to a type T value
template <typename T>
T as() const
Expand Down
104 changes: 104 additions & 0 deletions orm_lib/inc/drogon/orm/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,40 @@ class Row;
class ResultImpl;
using ResultImplPtr = std::shared_ptr<ResultImpl>;

enum class SqlFieldType : uint8_t
{
Unknown = 0,
Bool,
Int,
BigInt,
Float,
Double,
Decimal,
Varchar,
Text,
Date,
Time,
DateTime,
Blob,
Json,
Binary
};

enum class SqlStatus
{
Ok,
End
};

struct ColumnMeta
{
SqlFieldType sqlType{SqlFieldType::Unknown};
std::string typeName;
int length{0};
int precision{0};
int scale{0};
};

/// Result set containing data returned by a query or command.
/** This behaves as a container (as defined by the C++ standard library) and
* provides random access const iterators to iterate over its rows. A row
Expand Down Expand Up @@ -139,6 +167,82 @@ class DROGON_EXPORT Result
*/
unsigned long long insertId() const noexcept;

/**
* @brief Get the logical SQL type of the specified column.
*
* @param column Zero-based index of the column (must be less than
* columns()).
* @return The abstracted SQL field type for the given column, or
* SqlFieldType::Unknown if the type cannot be determined.
*
* @note Type metadata may only be fully populated for some database
* backends (for example, MySQL). For other backends, the result
* may be limited or fall back to SqlFieldType::Unknown.
*/
SqlFieldType getSqlType(SizeType column) const;

/**
* @brief Get the database-specific type name of the specified column.
*
* @param column Zero-based index of the column (must be less than
* columns()).
* @return A reference to a string containing the type name as reported
* by the underlying database driver (for example, "INT",
* "VARCHAR", "DECIMAL(10,2)", etc.).
*
* @note Type-name metadata may only be fully populated for some database
* backends (for example, MySQL). On other backends, the returned
* string may be empty or use a backend-specific representation.
*/
const std::string &getTypeName(SizeType column) const;

/**
* @brief Get the defined maximum length of the specified column.
*
* @param column Zero-based index of the column (must be less than
* columns()).
* @return The maximum length for the column in characters or bytes, as
* reported by the underlying database driver, or 0 if this
* information is not available.
*
* @note Length metadata may only be populated for some database backends
* (for example, MySQL) and for certain column types (such as
* character and binary types).
*/
int getColumnLength(SizeType column) const;

/**
* @brief Get the numeric precision for the specified column.
*
* @param column Zero-based index of the column (must be less than
* columns()).
* @return The precision (total number of significant digits) for the
* column, as reported by the underlying database driver, or 0 if
* not applicable or not available.
*
* @note Precision is generally only meaningful for numeric types such as
* DECIMAL or NUMERIC. On other types, the value may be 0 or
* unspecified, and metadata may only be provided by some backends
* (for example, MySQL).
*/
int getPrecision(SizeType column) const;

/**
* @brief Get the numeric scale for the specified column.
*
* @param column Zero-based index of the column (must be less than
* columns()).
* @return The scale (number of fractional digits) for the column, as
* reported by the underlying database driver, or 0 if not
* applicable or not available.
*
* @note Scale is generally only meaningful for numeric types such as
* DECIMAL or NUMERIC. On other types, the value may be 0 or
* unspecified, and metadata may only be provided by some backends
* (for example, MySQL).
*/
int getScale(SizeType column) const;

#ifdef _MSC_VER
Result() noexcept = default;
#endif
Expand Down
25 changes: 25 additions & 0 deletions orm_lib/src/Result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,31 @@ unsigned long long Result::insertId() const noexcept
return resultPtr_->insertId();
}

SqlFieldType Result::getSqlType(SizeType column) const
{
return resultPtr_->columnMeta(column).sqlType;
}

const std::string &Result::getTypeName(SizeType column) const
{
return resultPtr_->columnMeta(column).typeName;
}

int Result::getColumnLength(SizeType column) const
{
return resultPtr_->columnMeta(column).length;
}

int Result::getPrecision(SizeType column) const
{
return resultPtr_->columnMeta(column).precision;
}

int Result::getScale(SizeType column) const
{
return resultPtr_->columnMeta(column).scale;
}

int Result::oid(RowSizeType column) const noexcept
{
return resultPtr_->oid(column);
Expand Down
7 changes: 7 additions & 0 deletions orm_lib/src/ResultImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class ResultImpl : public trantor::NonCopyable
virtual bool isNull(SizeType row, RowSizeType column) const = 0;
virtual FieldSizeType getLength(SizeType row, RowSizeType column) const = 0;

virtual const ColumnMeta &columnMeta(SizeType column) const
{
(void)column;
static const ColumnMeta dummy{};
return dummy;
}

virtual unsigned long long insertId() const noexcept
{
return 0;
Expand Down
5 changes: 5 additions & 0 deletions orm_lib/src/mysql_impl/MysqlResultImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ unsigned long long MysqlResultImpl::insertId() const noexcept
{
return insertId_;
}

const ColumnMeta &MysqlResultImpl::columnMeta(SizeType column) const
{
return columnMeta_.at(column);
}
Loading
Loading