Add the int type for the Row index parameter (#872)

This commit is contained in:
An Tao 2021-05-27 10:10:23 +08:00 committed by GitHub
parent 1e87c35b8f
commit afb7e853ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 9 deletions

View File

@ -65,7 +65,7 @@ class DROGON_EXPORT Result
Result &operator=(const Result &r) noexcept;
Result &operator=(Result &&) noexcept;
using DifferenceType = long;
using SizeType = unsigned long;
using SizeType = size_t;
using Reference = Row;
using ConstIterator = ConstResultIterator;
using Iterator = ConstIterator;

View File

@ -45,7 +45,7 @@ class ConstReverseRowIterator;
class DROGON_EXPORT Row
{
public:
using SizeType = unsigned long;
using SizeType = size_t;
using Reference = Field;
using ConstIterator = ConstRowIterator;
using Iterator = ConstIterator;
@ -54,6 +54,7 @@ class DROGON_EXPORT Row
using DifferenceType = long;
Reference operator[](SizeType index) const noexcept;
Reference operator[](int index) const noexcept;
Reference operator[](const char columnName[]) const;
Reference operator[](const std::string &columnName) const;

View File

@ -1,7 +1,7 @@
/**
*
* Row.cc
* An Tao
* @file Row.cc
* @author An Tao
*
* Copyright 2018, An Tao. All rights reserved.
* https://github.com/an-tao/drogon
@ -35,6 +35,14 @@ Row::Reference Row::operator[](SizeType index) const noexcept
return Field(*this, index);
}
Row::Reference Row::operator[](int index) const noexcept
{
assert(index >= 0);
auto i = static_cast<SizeType>(index);
assert(i < end_);
return Field(*this, i);
}
Row::Reference Row::operator[](const char columnName[]) const
{
auto N = result_.columnNumber(columnName);

View File

@ -109,11 +109,9 @@ int main()
for (auto row : r)
{
std::cout << "is_default: "
<< (row[(unsigned long)0].isNull() ? "is null, "
: "is not null, ")
<< "bool value:" << row[(unsigned long)0].as<bool>()
<< "(" << row[(unsigned long)0].as<std::string>()
<< ")" << std::endl;
<< (row[0].isNull() ? "is null, " : "is not null, ")
<< "bool value:" << row[0].as<bool>() << "("
<< row[0].as<std::string>() << ")" << std::endl;
}
} >> [](const DrogonDbException &e) {
std::cerr << e.base().what() << std::endl;