GCC Code Coverage Report


Directory: src/gate/
File: src/gate/data/cxx_adapter.cpp
Date: 2026-08-06 22:46:24
Exec Total Coverage
Lines: 81 92 88.0%
Functions: 18 18 100.0%
Branches: 32 80 40.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/data/adapter.hpp"
29 #include "gate/exceptions.hpp"
30
31 namespace gate
32 {
33 namespace data
34 {
35
36 4 DataReader::DataReader(gate_data_reader_t* ptrReader) noexcept
37 4 : object_impl_t(ptrReader)
38 {
39 4 }
40
41 5 bool_t DataReader::isValid()
42 {
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!this->impl_ptr)
44 {
45 return false;
46 }
47 5 return gate_data_reader_is_valid(this->impl_ptr);
48 }
49
50 9 bool_t DataReader::next()
51 {
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!this->impl_ptr)
53 {
54 return false;
55 }
56 9 result_t res = gate_data_reader_next(this->impl_ptr);
57
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if (GATE_SUCCEEDED(res))
58 {
59 5 return true;
60 }
61 else
62 {
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (res != GATE_RESULT_ENDOFSTREAM)
64 {
65 GATEXX_RAISE_EXCEPTION(res, NULL, 0);
66 }
67 4 return false;
68 }
69 }
70
71 4 void DataReader::close()
72 {
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!this->impl_ptr)
74 {
75 return;
76 }
77 4 result_t res = gate_data_reader_close(this->impl_ptr);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATEXX_CHECK_ERROR(res);
79 }
80
81 5 size_t DataReader::getFieldCount()
82 {
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!this->impl_ptr)
84 {
85 return 0;
86 }
87 5 return gate_data_reader_get_field_count(this->impl_ptr);
88 }
89
90 33 gate_type_id_t DataReader::getFieldType(size_t index)
91 {
92 33 gate_type_id_t type = 0;
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (!this->impl_ptr)
94 {
95 GATEXX_RAISE_ERROR(results::NullPointer);
96 }
97 else
98 {
99
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
33 result_t res = gate_data_reader_get_field_type(this->impl_ptr, index, &type);
100
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
33 GATEXX_CHECK_EXCEPTION(res);
101 }
102 33 return type;
103 }
104
105 33 String DataReader::getFieldName(size_t index)
106 {
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (!this->impl_ptr)
108 {
109 GATEXX_RAISE_ERROR(results::NullPointer);
110 }
111 else
112 {
113 33 gate_string_t const* ptr_str = NULL;
114
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
33 result_t res = gate_data_reader_get_field_name(this->impl_ptr, index, &ptr_str);
115
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
33 GATEXX_CHECK_EXCEPTION(res);
116
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 if (ptr_str)
117 {
118 33 return String::duplicate(*ptr_str);
119 }
120 }
121 return String();
122 }
123
124 33 Value DataReader::getFieldValue(size_t index)
125 {
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (!this->impl_ptr)
127 {
128 GATEXX_RAISE_ERROR(results::NullPointer);
129 }
130 else
131 {
132 33 gate_value_t const* ptr_type = NULL;
133
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
33 result_t res = gate_data_reader_get_field_value(this->impl_ptr, index, &ptr_type);
134
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
33 GATEXX_CHECK_EXCEPTION(res);
135
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 if (ptr_type)
136 {
137
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
33 return Value(*ptr_type);
138 }
139 }
140 return Value();
141 }
142
143
144
145 23 DataStatement::DataStatement(gate_data_statement_t* ptrStatement) noexcept
146 23 : object_impl_t(ptrStatement)
147 {
148 23 }
149
150 7 size_t DataStatement::getParamCount()
151 {
152 7 size_t count = 0;
153
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 result_t result = gate_data_statement_get_param_count(this->impl_ptr, &count);
154
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
7 GATEXX_CHECK_EXCEPTION(result);
155 7 return count;
156 }
157 24 void DataStatement::setParam(size_t index, Value const& value)
158 {
159 24 result_t result = gate_data_statement_set_param(this->impl_ptr, index, value.c_impl());
160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 GATEXX_CHECK_EXCEPTION(result);
161 24 }
162 6 void DataStatement::setNamedParam(String const& name, Value const& value)
163 {
164 6 result_t result = gate_data_statement_set_named_param(this->impl_ptr, name.c_impl(), value.c_impl());
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 GATEXX_CHECK_EXCEPTION(result);
166 6 }
167
168 7 void DataStatement::reset()
169 {
170 7 result_t result = gate_data_statement_reset(this->impl_ptr);
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 GATEXX_CHECK_EXCEPTION(result);
172 7 }
173 19 int32_t DataStatement::execute()
174 {
175 19 int32_t affected_rows = 0;
176
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 result_t result = gate_data_statement_execute(this->impl_ptr, &affected_rows);
177
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
19 GATEXX_CHECK_EXCEPTION(result);
178 19 return affected_rows;
179 }
180 4 DataReader DataStatement::query()
181 {
182 4 gate_data_reader_t* ptr_reader = NULL;
183
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 result_t result = gate_data_statement_query(this->impl_ptr, &ptr_reader);
184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4 GATEXX_CHECK_EXCEPTION(result);
185 8 return DataReader(ptr_reader);
186 }
187
188
189
190 13 DataConnection::DataConnection(gate_data_connection_t* ptrConnection) noexcept
191 13 : object_impl_t(ptrConnection)
192 {
193 13 }
194
195 23 DataStatement DataConnection::createStatement(String const& sql)
196 {
197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (!this->impl_ptr)
198 {
199 GATEXX_RAISE_ERROR(results::NullPointer);
200 }
201
202 23 gate_data_statement_t* ptr_stmt = NULL;
203
1/2
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
23 result_t res = gate_data_connection_create_statement(this->impl_ptr, sql.c_impl(), &ptr_stmt);
204
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
23 GATEXX_CHECK_EXCEPTION(res);
205 46 return DataStatement(ptr_stmt);
206 }
207
208
209
210 4 DataConnectionFactory::~DataConnectionFactory() noexcept
211 {
212 4 }
213
214 } // end of namespace data
215 } // end of namespace gate
216