|
25 | 25 | #include "TestUtil.h" |
26 | 26 | #include "fb-cpp/Attachment.h" |
27 | 27 | #include "fb-cpp/Exception.h" |
| 28 | +#include "fb-cpp/RowSet.h" |
28 | 29 | #include "fb-cpp/Statement.h" |
29 | 30 | #include "fb-cpp/Transaction.h" |
30 | 31 | #include <exception> |
@@ -109,6 +110,140 @@ BOOST_AUTO_TEST_CASE(executePreparesAndExecutesStatement) |
109 | 110 | transaction.commit(); |
110 | 111 | } |
111 | 112 |
|
| 113 | +BOOST_AUTO_TEST_CASE(queryReturnsRowsIncludingFirstRow) |
| 114 | +{ |
| 115 | + const auto database = getTempFile("Attachment-queryReturnsRowsIncludingFirstRow.fdb"); |
| 116 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 117 | + FbDropDatabase attachmentDrop{attachment}; |
| 118 | + |
| 119 | + Transaction transaction{attachment}; |
| 120 | + BOOST_REQUIRE(attachment.execute(transaction, "create table t (id integer not null primary key)")); |
| 121 | + transaction.commitRetaining(); |
| 122 | + |
| 123 | + for (int i = 1; i <= 3; ++i) |
| 124 | + { |
| 125 | + Statement insert{attachment, transaction, "insert into t (id) values (?)"}; |
| 126 | + insert.setInt32(0, i); |
| 127 | + BOOST_REQUIRE(insert.execute(transaction)); |
| 128 | + } |
| 129 | + |
| 130 | + auto rowSet = attachment.queryRowSet(transaction, "select id from t order by id", 10u); |
| 131 | + |
| 132 | + BOOST_REQUIRE_EQUAL(rowSet.getCount(), 3u); |
| 133 | + BOOST_CHECK_EQUAL(rowSet.getRow(0).getInt32(0).value(), 1); |
| 134 | + BOOST_CHECK_EQUAL(rowSet.getRow(1).getInt32(0).value(), 2); |
| 135 | + BOOST_CHECK_EQUAL(rowSet.getRow(2).getInt32(0).value(), 3); |
| 136 | + |
| 137 | + transaction.commit(); |
| 138 | +} |
| 139 | + |
| 140 | +BOOST_AUTO_TEST_CASE(queryHonorsMaxRows) |
| 141 | +{ |
| 142 | + const auto database = getTempFile("Attachment-queryHonorsMaxRows.fdb"); |
| 143 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 144 | + FbDropDatabase attachmentDrop{attachment}; |
| 145 | + |
| 146 | + Transaction transaction{attachment}; |
| 147 | + BOOST_REQUIRE(attachment.execute(transaction, "create table t (id integer not null primary key)")); |
| 148 | + transaction.commitRetaining(); |
| 149 | + |
| 150 | + for (int i = 1; i <= 5; ++i) |
| 151 | + { |
| 152 | + Statement insert{attachment, transaction, "insert into t (id) values (?)"}; |
| 153 | + insert.setInt32(0, i); |
| 154 | + BOOST_REQUIRE(insert.execute(transaction)); |
| 155 | + } |
| 156 | + |
| 157 | + auto rowSet = attachment.queryRowSet(transaction, "select id from t order by id", 2u); |
| 158 | + |
| 159 | + BOOST_REQUIRE_EQUAL(rowSet.getCount(), 2u); |
| 160 | + BOOST_CHECK_EQUAL(rowSet.getRow(0).getInt32(0).value(), 1); |
| 161 | + BOOST_CHECK_EQUAL(rowSet.getRow(1).getInt32(0).value(), 2); |
| 162 | + |
| 163 | + transaction.commit(); |
| 164 | +} |
| 165 | + |
| 166 | +BOOST_AUTO_TEST_CASE(queryReturnsEmptyRowSetForNoRows) |
| 167 | +{ |
| 168 | + const auto database = getTempFile("Attachment-queryReturnsEmptyRowSetForNoRows.fdb"); |
| 169 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 170 | + FbDropDatabase attachmentDrop{attachment}; |
| 171 | + |
| 172 | + Transaction transaction{attachment}; |
| 173 | + BOOST_REQUIRE(attachment.execute(transaction, "create table t (id integer not null primary key)")); |
| 174 | + transaction.commitRetaining(); |
| 175 | + |
| 176 | + auto rowSet = attachment.queryRowSet(transaction, "select id from t", 10u); |
| 177 | + |
| 178 | + BOOST_CHECK_EQUAL(rowSet.getCount(), 0u); |
| 179 | + BOOST_CHECK(rowSet.getRawBuffer().empty()); |
| 180 | + |
| 181 | + transaction.commit(); |
| 182 | +} |
| 183 | + |
| 184 | +BOOST_AUTO_TEST_CASE(querySupportsStatementOptions) |
| 185 | +{ |
| 186 | + const auto database = getTempFile("Attachment-querySupportsStatementOptions.fdb"); |
| 187 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 188 | + FbDropDatabase attachmentDrop{attachment}; |
| 189 | + |
| 190 | + Transaction transaction{attachment}; |
| 191 | + auto rowSet = |
| 192 | + attachment.queryRowSet(transaction, "select 1 from rdb$database", 1u, StatementOptions().setDialect(3u)); |
| 193 | + |
| 194 | + BOOST_REQUIRE_EQUAL(rowSet.getCount(), 1u); |
| 195 | + BOOST_CHECK_EQUAL(rowSet.getRow(0).getInt32(0).value(), 1); |
| 196 | + |
| 197 | + transaction.commit(); |
| 198 | +} |
| 199 | + |
| 200 | +BOOST_AUTO_TEST_CASE(queryThrowsForNonQueryStatement) |
| 201 | +{ |
| 202 | + const auto database = getTempFile("Attachment-queryThrowsForNonQueryStatement.fdb"); |
| 203 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 204 | + FbDropDatabase attachmentDrop{attachment}; |
| 205 | + |
| 206 | + Transaction transaction{attachment}; |
| 207 | + BOOST_CHECK_THROW(attachment.queryRowSet(transaction, "create table t (id integer)", 10u), FbCppException); |
| 208 | + |
| 209 | + transaction.commit(); |
| 210 | +} |
| 211 | + |
| 212 | +BOOST_AUTO_TEST_CASE(queryRowSetSupportsProcedureWithOutputColumns) |
| 213 | +{ |
| 214 | + const auto database = getTempFile("Attachment-queryRowSetSupportsProcedureWithOutputColumns.fdb"); |
| 215 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 216 | + FbDropDatabase attachmentDrop{attachment}; |
| 217 | + |
| 218 | + Transaction transaction{attachment}; |
| 219 | + BOOST_REQUIRE(attachment.execute(transaction, |
| 220 | + "create procedure p returns (id integer, name varchar(20)) as begin id = 42; name = 'answer'; suspend; end")); |
| 221 | + transaction.commitRetaining(); |
| 222 | + |
| 223 | + auto rowSet = attachment.queryRowSet(transaction, "execute procedure p", 10u); |
| 224 | + |
| 225 | + BOOST_REQUIRE_EQUAL(rowSet.getCount(), 1u); |
| 226 | + BOOST_CHECK_EQUAL(rowSet.getRow(0).getInt32(0).value(), 42); |
| 227 | + BOOST_CHECK_EQUAL(rowSet.getRow(0).getString(1).value(), "answer"); |
| 228 | + |
| 229 | + transaction.commit(); |
| 230 | +} |
| 231 | + |
| 232 | +BOOST_AUTO_TEST_CASE(queryRowSetRejectsProcedureWithoutOutputColumns) |
| 233 | +{ |
| 234 | + const auto database = getTempFile("Attachment-queryRowSetRejectsProcedureWithoutOutputColumns.fdb"); |
| 235 | + Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; |
| 236 | + FbDropDatabase attachmentDrop{attachment}; |
| 237 | + |
| 238 | + Transaction transaction{attachment}; |
| 239 | + BOOST_REQUIRE(attachment.execute(transaction, "create procedure p as begin end")); |
| 240 | + transaction.commitRetaining(); |
| 241 | + |
| 242 | + BOOST_CHECK_THROW(attachment.queryRowSet(transaction, "execute procedure p", 10u), FbCppException); |
| 243 | + |
| 244 | + transaction.commit(); |
| 245 | +} |
| 246 | + |
112 | 247 | BOOST_AUTO_TEST_CASE(isNotValidAfterMove) |
113 | 248 | { |
114 | 249 | const auto database = getTempFile("Attachment-isNotValidAfterMove.fdb"); |
|
0 commit comments