mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
Add the int type for the Row index parameter (#872)
This commit is contained in:
parent
1e87c35b8f
commit
afb7e853ec
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user