GCC Code Coverage Report


Directory: src/gate/
File: src/gate/data/cxx_adapter.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 92 0.0%
Functions: 0 18 0.0%
Branches: 0 80 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, 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 DataReader::DataReader(gate_data_reader_t* ptrReader) noexcept
37 : object_impl_t(ptrReader)
38 {
39 }
40
41 bool_t DataReader::isValid()
42 {
43 if (!this->impl_ptr)
44 {
45 return false;
46 }
47 return gate_data_reader_is_valid(this->impl_ptr);
48 }
49
50 bool_t DataReader::next()
51 {
52 if (!this->impl_ptr)
53 {
54 return false;
55 }
56 result_t res = gate_data_reader_next(this->impl_ptr);
57 if (GATE_SUCCEEDED(res))
58 {
59 return true;
60 }
61 else
62 {
63 if (res != GATE_RESULT_ENDOFSTREAM)
64 {
65 GATEXX_RAISE_EXCEPTION(res, NULL, 0);
66 }
67 return false;
68 }
69 }
70
71 void DataReader::close()
72 {
73 if (!this->impl_ptr)
74 {
75 return;
76 }
77 result_t res = gate_data_reader_close(this->impl_ptr);
78 GATEXX_CHECK_ERROR(res);
79 }
80
81 size_t DataReader::getFieldCount()
82 {
83 if (!this->impl_ptr)
84 {
85 return 0;
86 }
87 return gate_data_reader_get_field_count(this->impl_ptr);
88 }
89
90 gate_type_id_t DataReader::getFieldType(size_t index)
91 {
92 gate_type_id_t type = 0;
93 if (!this->impl_ptr)
94 {
95 GATEXX_RAISE_ERROR(results::NullPointer);
96 }
97 else
98 {
99 result_t res = gate_data_reader_get_field_type(this->impl_ptr, index, &type);
100 GATEXX_CHECK_EXCEPTION(res);
101 }
102 return type;
103 }
104
105 String DataReader::getFieldName(size_t index)
106 {
107 if (!this->impl_ptr)
108 {
109 GATEXX_RAISE_ERROR(results::NullPointer);
110 }
111 else
112 {
113 gate_string_t const* ptr_str = NULL;
114 result_t res = gate_data_reader_get_field_name(this->impl_ptr, index, &ptr_str);
115 GATEXX_CHECK_EXCEPTION(res);
116 if (ptr_str)
117 {
118 return String::duplicate(*ptr_str);
119 }
120 }
121 return String();
122 }
123
124 Value DataReader::getFieldValue(size_t index)
125 {
126 if (!this->impl_ptr)
127 {
128 GATEXX_RAISE_ERROR(results::NullPointer);
129 }
130 else
131 {
132 gate_value_t const* ptr_type = 0;
133 result_t res = gate_data_reader_get_field_value(this->impl_ptr, index, &ptr_type);
134 GATEXX_CHECK_EXCEPTION(res);
135 if (ptr_type)
136 {
137 return Value(*ptr_type);
138 }
139 }
140 return Value();
141 }
142
143
144
145 DataStatement::DataStatement(gate_data_statement_t* ptrStatement) noexcept
146 : object_impl_t(ptrStatement)
147 {
148 }
149
150 size_t DataStatement::getParamCount()
151 {
152 size_t count = 0;
153 result_t result = gate_data_statement_get_param_count(this->impl_ptr, &count);
154 GATEXX_CHECK_EXCEPTION(result);
155 return count;
156 }
157 void DataStatement::setParam(size_t index, Value const& value)
158 {
159 result_t result = gate_data_statement_set_param(this->impl_ptr, index, value.c_impl());
160 GATEXX_CHECK_EXCEPTION(result);
161 }
162 void DataStatement::setNamedParam(String const& name, Value const& value)
163 {
164 result_t result = gate_data_statement_set_named_param(this->impl_ptr, name.c_impl(), value.c_impl());
165 GATEXX_CHECK_EXCEPTION(result);
166 }
167
168 void DataStatement::reset()
169 {
170 result_t result = gate_data_statement_reset(this->impl_ptr);
171 GATEXX_CHECK_EXCEPTION(result);
172 }
173 int32_t DataStatement::execute()
174 {
175 int32_t affected_rows = 0;
176 result_t result = gate_data_statement_execute(this->impl_ptr, &affected_rows);
177 GATEXX_CHECK_EXCEPTION(result);
178 return affected_rows;
179 }
180 DataReader DataStatement::query()
181 {
182 gate_data_reader_t* ptr_reader = NULL;
183 result_t result = gate_data_statement_query(this->impl_ptr, &ptr_reader);
184 GATEXX_CHECK_EXCEPTION(result);
185 return DataReader(ptr_reader);
186 }
187
188
189
190 DataConnection::DataConnection(gate_data_connection_t* ptrConnection) noexcept
191 : object_impl_t(ptrConnection)
192 {
193 }
194
195 DataStatement DataConnection::createStatement(String const& sql)
196 {
197 if (!this->impl_ptr)
198 {
199 GATEXX_RAISE_ERROR(results::NullPointer);
200 }
201
202 gate_data_statement_t* ptr_stmt = NULL;
203 result_t res = gate_data_connection_create_statement(this->impl_ptr, sql.c_impl(), &ptr_stmt);
204 GATEXX_CHECK_EXCEPTION(res);
205 return DataStatement(ptr_stmt);
206 }
207
208
209
210 DataConnectionFactory::~DataConnectionFactory() noexcept
211 {
212 }
213
214 } // end of namespace data
215 } // end of namespace gate
216