Skip to content

Commit

Permalink
refactor: make signatures in dbdriver more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
OpatrilPeter committed May 29, 2024
1 parent cd064c4 commit 119d5ed
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions include/superior_mysqlpp/low_level/dbdriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,22 @@ namespace SuperiorMySqlpp { namespace LowLevel
* Type for indexing rows.
* Underlying type inferred from usage in C MySQL client.
*/
using RowIndex = unsigned long long;
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 int;

/**
* Returns current logger instance.
Expand Down Expand Up @@ -340,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 @@ -358,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 @@ -401,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 @@ -568,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 @@ -593,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 @@ -605,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 @@ -617,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 @@ -628,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 @@ -639,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 @@ -650,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 @@ -670,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 @@ -681,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 @@ -705,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 @@ -716,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 @@ -741,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 @@ -786,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 @@ -898,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 @@ -1297,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 @@ -1307,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 @@ -1446,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 Down Expand Up @@ -1500,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 @@ -1525,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 @@ -1607,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 @@ -1634,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

0 comments on commit 119d5ed

Please sign in to comment.