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