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

Fix signatures II #143

Merged
merged 7 commits into from
Sep 20, 2024
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
91 changes: 56 additions & 35 deletions include/superior_mysqlpp/low_level/dbdriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ namespace SuperiorMySqlpp { namespace LowLevel
MYSQL mysql;
/** Logger instance pointer. */
Loggers::SharedPointer_t loggerPtr;

using size_t = unsigned long long;

private:
/**
* Internal thread-safe ID counter.
Expand Down Expand Up @@ -203,6 +200,26 @@ namespace SuperiorMySqlpp { namespace LowLevel

DBDriver& operator=(DBDriver&&) = delete;

/**
* Type for indexing rows.
* Underlying type inferred from usage in C MySQL client.
*/
using RowIndex = my_ulonglong;

/**
* Type for referring to number of rows.
*/
using RowCount = RowIndex;

/**
* Type for referring to number of fields of a row.
*/
using FieldCount = unsigned int;

/**
* Type for referring to number of bytes for a field.
*/
using FieldSize = unsigned long;

/**
* Returns current logger instance.
Expand Down Expand Up @@ -338,7 +355,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param fromlen Length of original string.
* @return HEX string.
*/
std::string makeHexString(const char *from, std::size_t fromlen)
std::string makeHexString(const char* from, std::size_t fromlen)
{
std::string result(fromlen * 2 + 1, '\0');

Expand All @@ -356,7 +373,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param from Original string.
* @return HEX string.
*/
std::string makeHexString(const char *from)
std::string makeHexString(const char* from)
{
return makeHexString(from, std::strlen(from));
}
Expand Down Expand Up @@ -399,7 +416,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Charset name as a C-string.
*/
auto getCharacterSetName() noexcept
const char* getCharacterSetName() noexcept
{
return mysql_character_set_name(getMysqlPtr());
}
Expand Down Expand Up @@ -547,15 +564,14 @@ namespace SuperiorMySqlpp { namespace LowLevel
freeResult();
}


/**
* Seeks to an arbitrary row in a query result set.
* @see https://dev.mysql.com/doc/refman/5.7/en/mysql-data-seek.html
* @remark Use this method only in case #storeResult (not #useResult) was called before.
*
* @param index Row number in a result set.
*/
void seekRow(size_t index) noexcept
void seekRow(SuperiorMySqlpp::LowLevel::DBDriver::RowIndex index) noexcept
{
mysql_data_seek(resultPtr, index);
}
Expand All @@ -567,7 +583,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param offset Row offset, not a row index. Typically returned value from #tellRowOffset is used.
* @return The previous value of the row cursor
*/
auto seekRowOffset(MYSQL_ROW_OFFSET offset) noexcept
MYSQL_ROW_OFFSET seekRowOffset(MYSQL_ROW_OFFSET offset) noexcept
{
return mysql_row_seek(resultPtr, offset);
}
Expand All @@ -580,7 +596,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return The current offset of the row cursor.
*/
auto tellRowOffset() noexcept
MYSQL_ROW_OFFSET tellRowOffset() noexcept
{
return mysql_row_tell(resultPtr);
}
Expand All @@ -592,7 +608,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return The MYSQL_FIELD structure for the current column. NULL if no columns are left.
*/
auto fetchField() noexcept
MYSQL_FIELD* fetchField() noexcept
{
return mysql_fetch_field(resultPtr);
}
Expand All @@ -604,7 +620,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param index Column index to fetch details of.
* @return The MYSQL_FIELD structure for the specified column.
*/
auto fetchFieldDirect(unsigned int index) noexcept
MYSQL_FIELD* fetchFieldDirect(unsigned int index) noexcept
{
return mysql_fetch_field_direct(resultPtr, index);
}
Expand All @@ -616,7 +632,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return An array of MYSQL_FIELD structures for all columns of a result set.
*/
auto fetchFields() noexcept
MYSQL_FIELD* fetchFields() noexcept
{
return mysql_fetch_fields(resultPtr);
}
Expand All @@ -627,8 +643,10 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return An array of unsigned long integers representing the size of each column (not including any terminating null bytes).
*/
auto fetchLengths() noexcept
FieldSize* fetchLengths() noexcept
{
static_assert(std::is_same<decltype(mysql_fetch_lengths(resultPtr)), FieldSize *>::value,
"Expectation about type FieldSize does not match actual value source.");
return mysql_fetch_lengths(resultPtr);
}

Expand All @@ -638,7 +656,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return MYSQL_ROW with next row results. NULL if there are no more rows or on error.
*/
auto fetchRow() noexcept
MYSQL_ROW fetchRow() noexcept
{
return mysql_fetch_row(resultPtr);
}
Expand All @@ -649,9 +667,9 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return MYSQL_ROW with next row results. NULL if there are no more rows.
*/
auto checkedFetchRow()
MYSQL_ROW checkedFetchRow()
{
auto *row = mysql_fetch_row(resultPtr);
auto* row = mysql_fetch_row(resultPtr);

if (row == nullptr && mysql_errno(resultPtr->handle) != 0)
{
Expand All @@ -669,7 +687,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param offset Field number index, use 0 for first column.
* @return Previous offset value.
*/
auto fieldSeek(MYSQL_FIELD_OFFSET offset) noexcept
MYSQL_FIELD_OFFSET fieldSeek(MYSQL_FIELD_OFFSET offset) noexcept
{
return mysql_field_seek(resultPtr, offset);
}
Expand All @@ -680,7 +698,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return The current offset of the field cursor.
*/
auto fieldTell() noexcept
MYSQL_FIELD_OFFSET fieldTell() noexcept
{
return mysql_field_tell(resultPtr);
}
Expand All @@ -704,7 +722,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Unsigned integer representing the number of columns in a result set.
*/
auto getFieldsCount() noexcept
FieldCount getFieldsCount() noexcept
{
return mysql_num_fields(resultPtr);
}
Expand All @@ -715,7 +733,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Number of rows in a result set.
*/
auto getRowsCount() noexcept
RowCount getRowsCount() noexcept
{
return mysql_num_rows(resultPtr);
}
Expand All @@ -740,7 +758,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Number of columns of the last performed query.
*/
auto getFieldsCount() noexcept
FieldCount getFieldsCount() noexcept
{
return mysql_field_count(getMysqlPtr());
}
Expand Down Expand Up @@ -785,7 +803,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Instance of MY_CHARSET_INFO structure.
*/
auto getCharacterSetInfo() noexcept
MY_CHARSET_INFO getCharacterSetInfo() noexcept
{
MY_CHARSET_INFO characterSet;
mysql_get_character_set_info(getMysqlPtr(), &characterSet);
Expand Down Expand Up @@ -897,7 +915,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Number of affected rows by last statement.
*/
auto affectedRows() noexcept
RowCount affectedRows() noexcept
{
return mysql_affected_rows(getMysqlPtr());
}
Expand Down Expand Up @@ -1296,8 +1314,11 @@ namespace SuperiorMySqlpp { namespace LowLevel
return mysql_stmt_free_result(statementPtr);
}

auto fieldCount() noexcept
FieldCount fieldCount() noexcept
{
static_assert(std::is_same<decltype(mysql_stmt_field_count(statementPtr)), FieldCount>::value,
"Expectation about type FieldCount does not match actual value source.");

return mysql_stmt_field_count(statementPtr);
}

Expand All @@ -1306,7 +1327,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
return mysql_stmt_insert_id(statementPtr);
}

auto resultMetadata()
Result resultMetadata()
{
auto resultPtr = mysql_stmt_result_metadata(statementPtr);
if (resultPtr == nullptr)
Expand Down Expand Up @@ -1445,7 +1466,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Number of affected rows by last statement.
*/
auto affectedRows() noexcept
RowCount affectedRows() noexcept
{
return mysql_stmt_affected_rows(statementPtr);
}
Expand All @@ -1470,9 +1491,9 @@ namespace SuperiorMySqlpp { namespace LowLevel
}
}

auto sendLongData(unsigned int paramNumber, const std::string& data)
void sendLongData(unsigned int paramNumber, const std::string& data)
{
return sendLongData(paramNumber, data.c_str(), data.length());
sendLongData(paramNumber, data.c_str(), data.length());
}

std::string sqlState()
Expand All @@ -1487,7 +1508,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @param index Row number in a result set.
*/
void seekRow(size_t index) noexcept
void seekRow(RowIndex index) noexcept
{
mysql_stmt_data_seek(statementPtr, index);
}
Expand All @@ -1499,7 +1520,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @param offset Row offset, not a row index. Typically returned value from #tellRowOffset is used.
* @return The previous value of row cursor.
*/
auto seekRowOffset(MYSQL_ROW_OFFSET offset) noexcept
MYSQL_ROW_OFFSET seekRowOffset(MYSQL_ROW_OFFSET offset) noexcept
{
return mysql_stmt_row_seek(statementPtr, offset);
}
Expand All @@ -1512,7 +1533,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return The current offset of the row cursor.
*/
auto tellRowOffset() noexcept
MYSQL_ROW_OFFSET tellRowOffset() noexcept
{
return mysql_stmt_row_tell(statementPtr);
}
Expand All @@ -1524,7 +1545,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
*
* @return Number of rows in the statement's result set.
*/
auto getRowsCount() noexcept
RowCount getRowsCount() noexcept
{
return mysql_stmt_num_rows(statementPtr);
}
Expand Down Expand Up @@ -1606,7 +1627,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @return Results management instance.
* @throws MysqlInternalError When any error occurred.
*/
auto storeResult()
Result storeResult()
{
auto result = mysql_store_result(getMysqlPtr());
if (result == nullptr)
Expand All @@ -1633,7 +1654,7 @@ namespace SuperiorMySqlpp { namespace LowLevel
* @return Results management instance.
* @throws MysqlInternalError When any error occurred.
*/
auto useResult()
Result useResult()
{
auto result = mysql_use_result(getMysqlPtr());
if (result == nullptr)
Expand Down
2 changes: 1 addition & 1 deletion include/superior_mysqlpp/prepared_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace SuperiorMySqlpp
*/
void update()
{
detail::initializeBindings<IsParamBinding, Types...>(bindings, data);
detail::initializeBindings<IsParamBinding>(bindings, data);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ namespace SuperiorMySqlpp
* Calls respectively initializeParamBinding or initializeResultBinding for each field.
* @tparam isParamBinding Is true if binding is a ParamBindings specialization.
* @param bindings Type #Bindings<...>.
* @param data Type std::tuple (or any heterogenous ordered container supporting std::get).
* @param data Type std::tuple (container supporting std::get).
*/
template<bool isParamBinding, typename... Types, typename Bindings, typename Data>
inline void initializeBindings(Bindings& bindings, Data& data)
template<bool isParamBinding, typename... Types, typename Bindings>
inline void initializeBindings(Bindings& bindings, std::tuple<Types...>& data)
{
InitializeBindingsImpl<isParamBinding, sizeof...(Types)>::call(bindings, data);
}
Expand Down
Loading