DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
SqlDataReader.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Data/SqlClient/SqlDataReader.h
"
3
#include "
System/Convert.h
"
4
#include "
System/ArgumentException.h
"
5
#include "
System/Data/Internal/IDatabaseBackend.h
"
6
7
namespace
DotNetDupe
{
8
namespace
System
{
9
namespace
Data
{
10
namespace
SqlClient
{
11
12
struct
SqlDataReader::Impl :
public
Object
{
13
Collections::Generic::List<DotNetDupe::System::Data::Internal::Row> m_rows;
14
Collections::Generic::List<String> m_columns;
15
int
m_nCurrentIndex = -1;
16
};
17
18
SqlDataReader::SqlDataReader
(
Collections::Generic::List<DotNetDupe::System::Data::Internal::Row>
&& rows,
Collections::Generic::List<String>
&& columns)
19
: m_pImpl(
DotNetDupe
::
System
::
SmartPointer
<Impl>::NewShared()) {
20
m_pImpl->m_rows = std::move(rows);
21
m_pImpl->m_columns = std::move(columns);
22
}
23
24
SqlDataReader::~SqlDataReader
() =
default
;
25
26
bool
SqlDataReader::Read
() {
28
if
(m_pImpl->m_nCurrentIndex + 1 < m_pImpl->m_rows.GetCount()) {
29
m_pImpl->m_nCurrentIndex++;
30
return
true
;
31
}
32
return
false
;
33
}
34
35
DotNetDupe::System::String
SqlDataReader::GetString
(
int
iOrdinal) {
37
if
(m_pImpl->m_nCurrentIndex < 0 || m_pImpl->m_nCurrentIndex >= m_pImpl->m_rows.GetCount()) {
38
return
""
;
39
}
40
if
(iOrdinal < 0 || iOrdinal >= m_pImpl->m_columns.GetCount()) {
41
return
""
;
42
}
43
45
return
m_pImpl->m_rows[m_pImpl->m_nCurrentIndex].Values[iOrdinal];
46
}
47
48
int
SqlDataReader::GetInt32
(
int
iOrdinal) {
50
return
DotNetDupe::System::Convert::ToInt32
(
GetString
(iOrdinal));
51
}
52
53
double
SqlDataReader::GetDouble
(
int
iOrdinal) {
55
return
std::stod(
GetString
(iOrdinal).GetRawString());
56
}
57
58
bool
SqlDataReader::IsDBNull
(
int
iOrdinal) {
60
DotNetDupe::System::String
sVal =
GetString
(iOrdinal);
61
return
sVal.
IsEmpty
() || sVal ==
"NULL"
|| sVal ==
"null"
;
62
}
63
64
int
SqlDataReader::GetFieldCount
()
const
{
66
return
m_pImpl->m_columns.GetCount();
67
}
68
69
DotNetDupe::System::String
SqlDataReader::GetName
(
int
iOrdinal) {
71
if
(iOrdinal < 0 || iOrdinal >= m_pImpl->m_columns.GetCount()) {
72
return
""
;
73
}
74
return
m_pImpl->m_columns[iOrdinal];
75
}
76
77
int
SqlDataReader::GetOrdinal
(
const
DotNetDupe::System::String
& sName) {
79
for
(
int
i = 0; i < m_pImpl->m_columns.GetCount(); ++i) {
80
if
(m_pImpl->m_columns[i] == sName) {
81
return
i;
82
}
83
}
84
return
-1;
85
}
86
87
DotNetDupe::System::String
SqlDataReader::operator[]
(
const
DotNetDupe::System::String
& sName) {
89
int
ord =
GetOrdinal
(sName);
90
if
(ord == -1) {
91
throw
DotNetDupe::System::ArgumentException
(
DotNetDupe::System::String
(
"Column not found: "
) + sName);
92
}
93
return
GetString
(ord);
94
}
95
96
DotNetDupe::System::String
SqlDataReader::operator[]
(
int
iOrdinal) {
98
return
GetString
(iOrdinal);
99
}
100
101
}
102
}
103
}
104
}
ArgumentException.h
Defines the exception thrown when an invalid argument is provided to a method.
Convert.h
Converts a base data type to another base data type, and encodes/decodes Base64 data.
IDatabaseBackend.h
SqlDataReader.h
DotNetDupe::System::ArgumentException
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition
ArgumentException.h:16
DotNetDupe::System::Collections::Generic::List
Represents a strongly typed list of objects accessible by index.
Definition
List.h:29
DotNetDupe::System::Convert::ToInt32
static int ToInt32(bool value)
Definition
Convert.cpp:154
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetName
DotNetDupe::System::String GetName(int iOrdinal) override
Gets the name of the specified column.
Definition
SqlDataReader.cpp:69
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetFieldCount
int GetFieldCount() const override
Gets the number of columns in the current row.
Definition
SqlDataReader.cpp:64
DotNetDupe::System::Data::SqlClient::SqlDataReader::SqlDataReader
SqlDataReader(Collections::Generic::List< DotNetDupe::System::Data::Internal::Row > &&rows, Collections::Generic::List< DotNetDupe::System::String > &&columns)
Initializes a new instance of the SqlDataReader class with row and column collections.
Definition
SqlDataReader.cpp:18
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetOrdinal
int GetOrdinal(const DotNetDupe::System::String &sName) override
Gets the column ordinal, given the name of the column.
Definition
SqlDataReader.cpp:77
DotNetDupe::System::Data::SqlClient::SqlDataReader::IsDBNull
bool IsDBNull(int iOrdinal) override
Gets a value that indicates whether the column contains non-existent or missing values.
Definition
SqlDataReader.cpp:58
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetString
DotNetDupe::System::String GetString(int iOrdinal) override
Gets the value of the specified column as a string.
Definition
SqlDataReader.cpp:35
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetInt32
int GetInt32(int iOrdinal) override
Gets the value of the specified column as a 32-bit signed integer.
Definition
SqlDataReader.cpp:48
DotNetDupe::System::Data::SqlClient::SqlDataReader::~SqlDataReader
~SqlDataReader() override
Destructor releasing reader resources.
DotNetDupe::System::Data::SqlClient::SqlDataReader::GetDouble
double GetDouble(int iOrdinal) override
Gets the value of the specified column as a double-precision floating point number.
Definition
SqlDataReader.cpp:53
DotNetDupe::System::Data::SqlClient::SqlDataReader::Read
bool Read() override
Advances the SqlDataReader to the next record.
Definition
SqlDataReader.cpp:26
DotNetDupe::System::Data::SqlClient::SqlDataReader::operator[]
DotNetDupe::System::String operator[](const DotNetDupe::System::String &sName) override
Gets the value of the specified column in its native format given the column name.
Definition
SqlDataReader.cpp:87
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::System::String::IsEmpty
bool IsEmpty() const
Definition
String.cpp:398
DotNetDupe::System::Data::SqlClient
Definition
SqlCommand.h:8
DotNetDupe::System::Data
Definition
DbCommand.h:11
DotNetDupe::System::Text::Json::JsonValueKind::Object
@ Object
Definition
JsonElement.h:23
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
SqlDataReader.cpp
Generated by
1.18.0