DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
SqlDataReader.cpp
Go to the documentation of this file.
1#include "pch.h"
3#include "System/Convert.h"
6
7namespace 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
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
25
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
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) {
51 }
52
53 double SqlDataReader::GetDouble(int iOrdinal) {
55 return std::stod(GetString(iOrdinal).GetRawString());
56 }
57
58 bool SqlDataReader::IsDBNull(int iOrdinal) {
61 return sVal.IsEmpty() || sVal == "NULL" || sVal == "null";
62 }
63
66 return m_pImpl->m_columns.GetCount();
67 }
68
71 if (iOrdinal < 0 || iOrdinal >= m_pImpl->m_columns.GetCount()) {
72 return "";
73 }
74 return m_pImpl->m_columns[iOrdinal];
75 }
76
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
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
98 return GetString(iOrdinal);
99 }
100
101 }
102 }
103 }
104}
Defines the exception thrown when an invalid argument is provided to a method.
Converts a base data type to another base data type, and encodes/decodes Base64 data.
The exception that is thrown when one of the arguments provided to a method is not valid.
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
static int ToInt32(bool value)
Definition Convert.cpp:154
DotNetDupe::System::String GetName(int iOrdinal) override
Gets the name of the specified column.
int GetFieldCount() const override
Gets the number of columns in the current row.
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.
int GetOrdinal(const DotNetDupe::System::String &sName) override
Gets the column ordinal, given the name of the column.
bool IsDBNull(int iOrdinal) override
Gets a value that indicates whether the column contains non-existent or missing values.
DotNetDupe::System::String GetString(int iOrdinal) override
Gets the value of the specified column as a string.
int GetInt32(int iOrdinal) override
Gets the value of the specified column as a 32-bit signed integer.
~SqlDataReader() override
Destructor releasing reader resources.
double GetDouble(int iOrdinal) override
Gets the value of the specified column as a double-precision floating point number.
bool Read() override
Advances the SqlDataReader to the next record.
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.
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74